forked from exercism/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_relative_path_windows_test.go
More file actions
60 lines (47 loc) · 1.49 KB
/
submit_relative_path_windows_test.go
File metadata and controls
60 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cmd
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/exercism/cli/config"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func TestSubmitRelativePath(t *testing.T) {
//t.Skip("The Windows build is failing and needs to be debugged.\nSee https://ci.appveyor.com/project/kytrinyx/cli/build/110")
oldOut := Out
oldErr := Err
Out = ioutil.Discard
Err = ioutil.Discard
defer func() {
Out = oldOut
Err = oldErr
}()
// The fake endpoint will populate this when it receives the call from the command.
submittedFiles := map[string]string{}
ts := fakeSubmitServer(t, submittedFiles)
defer ts.Close()
tmpDir, err := ioutil.TempDir("", "relative-path")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
os.MkdirAll(dir, os.FileMode(0755))
writeFakeSolution(t, dir, "bogus-track", "bogus-exercise")
v := viper.New()
v.Set("token", "abc123")
v.Set("workspace", tmpDir)
v.Set("apibaseurl", ts.URL)
cfg := config.Configuration{
Persister: config.InMemoryPersister{},
UserViperConfig: v,
}
err = ioutil.WriteFile(filepath.Join(dir, "file.txt"), []byte("This is a file."), os.FileMode(0755))
err = os.Chdir(dir)
assert.NoError(t, err)
err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{"file.txt"})
assert.NoError(t, err)
assert.Equal(t, 1, len(submittedFiles))
assert.Equal(t, "This is a file.", submittedFiles["\\file.txt"])
}