40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestParse(t *testing.T) {
|
|
tests := []struct {
|
|
src string
|
|
dst string
|
|
srcPath string
|
|
dstPath string
|
|
service string
|
|
toContainer bool
|
|
err error
|
|
}{
|
|
{src: "foo", dst: "bar", err: errServiceMissing},
|
|
{src: "app:foo", dst: "app:bar", err: errServiceMissing},
|
|
{src: "app:foo", dst: "bar", srcPath: "foo", dstPath: "bar", service: "app", toContainer: false},
|
|
{src: "foo", dst: "app:bar", srcPath: "foo", dstPath: "bar", service: "app", toContainer: true},
|
|
}
|
|
|
|
for i, tc := range tests {
|
|
srcPath, dstPath, service, toContainer, err := parseSrcAndDst(tc.src, tc.dst)
|
|
if srcPath != tc.srcPath {
|
|
t.Errorf("[%d] srcPath: want (%s), got(%s)", i, tc.srcPath, srcPath)
|
|
}
|
|
if dstPath != tc.dstPath {
|
|
t.Errorf("[%d] dstPath: want (%s), got(%s)", i, tc.dstPath, dstPath)
|
|
}
|
|
if service != tc.service {
|
|
t.Errorf("[%d] service: want (%s), got(%s)", i, tc.service, service)
|
|
}
|
|
if toContainer != tc.toContainer {
|
|
t.Errorf("[%d] toConainer: want (%t), got(%t)", i, tc.toContainer, toContainer)
|
|
}
|
|
if err == nil && tc.err != nil && err.Error() != tc.err.Error() {
|
|
t.Errorf("[%d] err: want (%s), got(%s)", i, tc.err, err)
|
|
}
|
|
}
|
|
}
|