2014-09-16 08:48:56 +02:00
|
|
|
package module
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDetect(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Input string
|
|
|
|
Pwd string
|
|
|
|
Output string
|
|
|
|
Err bool
|
|
|
|
}{
|
|
|
|
{"./foo", "/foo", "file:///foo/foo", false},
|
|
|
|
{"git::./foo", "/foo", "git::file:///foo/foo", false},
|
2014-09-27 18:29:12 +02:00
|
|
|
{
|
|
|
|
"git::github.com/hashicorp/foo",
|
|
|
|
"",
|
|
|
|
"git::https://github.com/hashicorp/foo.git",
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"./foo//bar",
|
|
|
|
"/foo",
|
|
|
|
"file:///foo/foo//bar",
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"git::github.com/hashicorp/foo//bar",
|
|
|
|
"",
|
|
|
|
"git::https://github.com/hashicorp/foo.git//bar",
|
|
|
|
false,
|
|
|
|
},
|
2015-02-01 20:17:56 +01:00
|
|
|
{
|
|
|
|
"git::https://github.com/hashicorp/consul.git",
|
|
|
|
"",
|
|
|
|
"git::https://github.com/hashicorp/consul.git",
|
|
|
|
false,
|
|
|
|
},
|
2014-09-16 08:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
output, err := Detect(tc.Input, tc.Pwd)
|
2015-10-08 14:48:04 +02:00
|
|
|
if err != nil != tc.Err {
|
2014-09-16 08:48:56 +02:00
|
|
|
t.Fatalf("%d: bad err: %s", i, err)
|
|
|
|
}
|
|
|
|
if output != tc.Output {
|
2015-04-13 15:12:43 +02:00
|
|
|
t.Fatalf("%d: bad output: %s\nexpected: %s", i, output, tc.Output)
|
2014-09-16 08:48:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|