func TestTagSingle(t *testing.T) { res := tagTest(t, "aonly") assert.Equal(t, len(res), 1) assert.Equal(t, res[0].Id, "a") res = tagTest(t, "conly") assert.Equal(t, len(res), 1) assert.Equal(t, res[0].Id, "c") }
func TestMultipleIds(t *testing.T) { res := idTest(t, "a", "b") assert.Equal(t, len(res), 2) a := res[0] b := res[1] assert.Equal(t, a.Id, "a") assert.Equal(t, a.Name, "aname") assert.Equal(t, b.Id, "b") assert.Equal(t, b.Name, "bname") }
func TestCleanPathname(t *testing.T) { type pathtest struct { path []string expect string } tests := []pathtest{ // evil stuff {[]string{`../foo`}, "..,foo"}, {[]string{`/foo`}, ",foo"}, {[]string{`.././foo`}, "..,.,foo"}, {[]string{`-foo`}, "_foo"}, // ok {[]string{`b-foo`}, "b-foo"}, // ugly {[]string{`!`}, "."}, {[]string{`|`}, "."}, {[]string{`*`}, "."}, {[]string{`?`}, "."}, {[]string{`'`}, "."}, {[]string{`"`}, "."}, {[]string{`<`}, "."}, {[]string{`>`}, "."}, {[]string{`\foo`}, ".foo"}, } for _, test := range tests { res := CleanPathname(test.path...) assert.Equal(t, res, test.expect) } }
func TestSearchUrlOrder(t *testing.T) { setup := []searcherSetup{ {"ascheme", rhl{&host.Host{Id: "x", Name: "a"}}, nil}, {"bscheme", rhl{&host.Host{Id: "x", Name: "b"}}, nil}, } ms := buildMultiSearcher(setup...) ms.AddUrl("ascheme://p", "bscheme://p") res, err := ms.Id("_") if err != nil { t.Fatal(err) } assert.Equal(t, len(res), 1) assert.Equal(t, res[0].Name, "b", "the last added source should expand") }
func TestIdHost(t *testing.T) { res := idTest(t, "a") assert.Equal(t, len(res), 1) a := res[0] assert.Equal(t, a.Id, "a") assert.Equal(t, a.Name, "aname") assert.Equal(t, a.Tags, []string{"ab", "ac", "all", "aonly"}) assert.Equal(t, a.Port, "8080") assert.Equal(t, a.User, "auser") assert.Equal(t, a.Keyfiles, []string{"akeyx", "akeyy"}) assert.Equal(t, a.RemoteShell, "bash -a") assert.Equal(t, a.RemoteCd, "/a") assert.Equal(t, a.RemoteEnv, map[string]string{"aenvx": "x", "aenvy": "y"}) }
func TestTagMany(t *testing.T) { res := tagTest(t, "ac") assert.Equal(t, len(res), 2) for _, r := range res { switch r.Id { case "a", "c": //pass default: t.Fatal("tags should not return id", r.Id) } } }
func TestSearchConcatenationHosts(t *testing.T) { setup := []searcherSetup{ {"ascheme", rhl{&host.Host{Id: "x", Name: "xa"}, &host.Host{Id: "y", Name: "ya"}}, nil}, {"bscheme", rhl{&host.Host{Id: "y", Name: "yb"}}, nil}, {"cscheme", rhl{&host.Host{Id: "x", Name: "xc"}, &host.Host{Id: "y", Name: "yc"}}, nil}, } ms := buildMultiSearcher(setup...) ms.AddUrl("ascheme://p", "bscheme://p") res, err := ms.Tags("_") if err != nil { t.Fatal(err) } assert.Equal(t, len(res), 2) for _, r := range res { switch r.Id { case "x": assert.Equal(t, r.Name, "xa") case "y": assert.Equal(t, r.Name, "yb") default: t.Fatal("unkown host", r.Id) } } ms.AddUrl("cscheme://p") res, err = ms.Tags("_") if err != nil { t.Fatal(err) } assert.Equal(t, len(res), 2) for _, r := range res { switch r.Id { case "x": assert.Equal(t, r.Name, "xc") case "y": assert.Equal(t, r.Name, "yc") default: t.Fatal("unkown host", r.Id) } } }
func TestTagUnion(t *testing.T) { res := tagTest(t, "ab", "ac") assert.Equal(t, len(res), 1) assert.Equal(t, res[0].Id, "a") }
func TestMissingIds(t *testing.T) { res := idTest(t, "X") assert.Equal(t, len(res), 0) }