forked from exercism/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubmit_symlink_test.go
More file actions
68 lines (53 loc) · 1.61 KB
/
submit_symlink_test.go
File metadata and controls
68 lines (53 loc) · 1.61 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
61
62
63
64
65
66
67
68
// +build !windows
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 TestSubmitFilesInSymlinkedPath(t *testing.T) {
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("", "symlink-destination")
defer os.RemoveAll(tmpDir)
assert.NoError(t, err)
dstDir := filepath.Join(tmpDir, "workspace")
srcDir, err := ioutil.TempDir("", "symlink-source")
defer os.RemoveAll(srcDir)
assert.NoError(t, err)
err = os.Symlink(srcDir, dstDir)
assert.NoError(t, err)
dir := filepath.Join(dstDir, "bogus-track", "bogus-exercise")
os.MkdirAll(dir, os.FileMode(0755))
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
v := viper.New()
v.Set("token", "abc123")
v.Set("workspace", dstDir)
v.Set("apibaseurl", ts.URL)
cfg := config.Config{
Persister: config.InMemoryPersister{},
UserViperConfig: v,
}
file := filepath.Join(dir, "file.txt")
err = ioutil.WriteFile(filepath.Join(dir, "file.txt"), []byte("This is a file."), os.FileMode(0755))
assert.NoError(t, err)
err = runSubmit(cfg, pflag.NewFlagSet("symlinks", pflag.PanicOnError), []string{file})
assert.NoError(t, err)
assert.Equal(t, 1, len(submittedFiles))
assert.Equal(t, "This is a file.", submittedFiles["file.txt"])
}