-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_test.go
More file actions
68 lines (54 loc) · 1.55 KB
/
encode_test.go
File metadata and controls
68 lines (54 loc) · 1.55 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
package main
import (
// "flag"
// "github.com/codegangsta/cli"
"os"
"testing"
)
type testpair struct {
input string
errorExpected bool
}
var testPaths = []testpair{
{"/my/test/path", false},
{"/", false},
{"does-not-exist", true},
}
var testDestinationPaths = []testpair{
{"/my-test-go-directory", false},
}
func TestVerifyPath(t *testing.T) {
for _, pair := range testPaths {
// set := flag.NewFlagSet("test", 0)
// set.String("path", pair.input, "--path ~/home")
// context := cli.NewContext(nil, set, set)
// Initialize path with value of path flag
path := pair.input
// Verify that the path is valid
path, err := verifyPath(path)
// If this pair is invalid, expect an error to have been returned from verifyPath
if pair.errorExpected {
if err == nil {
t.Error("Expected an error for path " + pair.input + " but received nil.")
}
} else {
if err != nil {
t.Error("Did not expect an error but received one for path " + path)
}
}
}
}
func TestCreateDirectory(t *testing.T) {
for _, pair := range testDestinationPaths {
// Create the directory but do not force an overwrite
_, err := createDirectory(pair.input, false)
if os.IsNotExist(err) {
t.Error("Expected " + pair.input + " to be created but was not.")
}
// Create the directory and force an overwrite if one already exists
_, err = createDirectory(pair.input, true)
if os.IsNotExist(err) {
t.Error("Expected " + pair.input + " to be created but was not.")
}
}
}