forked from exercism/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument_test.go
42 lines (34 loc) · 847 Bytes
/
document_test.go
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
package workspace
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNormalizedDocumentPath(t *testing.T) {
root, err := os.MkdirTemp("", "docpath")
assert.NoError(t, err)
defer os.RemoveAll(root)
err = os.MkdirAll(filepath.Join(root, "subdirectory"), os.FileMode(0755))
assert.NoError(t, err)
testCases := []struct {
filepath string
path string
}{
{
filepath: filepath.Join(root, "file.txt"),
path: "file.txt",
},
{
filepath: filepath.Join(root, "subdirectory", "file.txt"),
path: "subdirectory/file.txt",
},
}
for _, tc := range testCases {
err = os.WriteFile(tc.filepath, []byte("a file"), os.FileMode(0600))
assert.NoError(t, err)
doc, err := NewDocument(root, tc.filepath)
assert.NoError(t, err)
assert.Equal(t, doc.Path(), tc.path)
}
}