-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_test.go
81 lines (74 loc) · 2.37 KB
/
main_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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"testing"
"github.com/fsouza/go-dockerclient"
"github.com/stretchr/testify/assert"
)
func TestParseCommand(t *testing.T) {
assert := assert.New(t)
cases := []struct {
Input string
Command string
Args string
Error error
}{
{":help me", "help", "", nil},
{":help", "help", "", nil},
{":h", "help", "", nil},
{":quit", "quit", "", nil},
{":q", "quit", "", nil},
{":commit this", "commit", "", nil},
{":commit", "commit", "", nil},
{":c", "commit", "", nil},
{":print this", "print", "", nil},
{":print", "print", "", nil},
{":p", "print", "", nil},
{":eval apt-get update", "eval", "apt-get update", nil},
{":e apt-get update", "eval", "apt-get update", nil},
{":eval", "eval", "", ErrMissingRequiredArg},
{":e", "eval", "", ErrMissingRequiredArg},
{"apt-get update", "eval", "apt-get update", nil},
{":run apt-get update", "run", "apt-get update", nil},
{":r apt-get update", "run", "apt-get update", nil},
{":run", "run", "", ErrMissingRequiredArg},
{":r", "run", "", ErrMissingRequiredArg},
{":from ubuntu:latest", "from", "ubuntu:latest", nil},
{":f ubuntu:latest", "from", "ubuntu:latest", nil},
{":from", "from", "", ErrMissingRequiredArg},
{":f", "from", "", ErrMissingRequiredArg},
{":write Dockerfile", "write", "Dockerfile", nil},
{":w Dockerfile", "write", "Dockerfile", nil},
{":write", "write", "", ErrMissingRequiredArg},
{":w", "write", "", ErrMissingRequiredArg},
{":notreal", ":notreal", "", ErrInvalidCommand},
{"", "", "", nil},
}
for _, line := range cases {
cmd, args, err := parseCommand(line.Input)
assert.Equal(line.Command, cmd, "Command should be equal for %s", line.Input)
assert.Equal(line.Args, args, "Args should be equal for %s", line.Input)
if line.Error == nil {
assert.NoError(err)
} else {
assert.EqualError(err, line.Error.Error())
}
}
}
func TestPruneChanges(t *testing.T) {
assert := assert.New(t)
changes := []docker.Change{
{Path: "/tmp", Kind: 0},
{Path: "/tmp/foo", Kind: 1},
{Path: "/tmp/foo/banana", Kind: 1},
{Path: "/tmp/bar", Kind: 2},
{Path: "/tmp/bar/banana", Kind: 2},
}
result := pruneChanges(changes)
expected := []docker.Change{
{Path: "/tmp/foo", Kind: 1},
{Path: "/tmp/foo/banana", Kind: 1},
{Path: "/tmp/bar", Kind: 2},
{Path: "/tmp/bar/banana", Kind: 2},
}
assert.Equal(result, expected, "they should be equal")
}