示例#1
0
文件: json_test.go 项目: afajl/ctrl
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")
}
示例#2
0
文件: json_test.go 项目: afajl/ctrl
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")
}
示例#3
0
文件: path_test.go 项目: afajl/ctrl
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)
	}
}
示例#4
0
文件: search_test.go 项目: afajl/ctrl
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")
}
示例#5
0
文件: json_test.go 项目: afajl/ctrl
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"})
}
示例#6
0
文件: json_test.go 项目: afajl/ctrl
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)
		}
	}
}
示例#7
0
文件: search_test.go 项目: afajl/ctrl
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)
		}
	}
}
示例#8
0
文件: json_test.go 项目: afajl/ctrl
func TestTagUnion(t *testing.T) {
	res := tagTest(t, "ab", "ac")
	assert.Equal(t, len(res), 1)
	assert.Equal(t, res[0].Id, "a")
}
示例#9
0
文件: json_test.go 项目: afajl/ctrl
func TestMissingIds(t *testing.T) {
	res := idTest(t, "X")
	assert.Equal(t, len(res), 0)
}