コード例 #1
0
func TestReset(t *testing.T) {
	etcdtest.DeleteAllFrom(defaultEtcdPrefix)

	in := &medium{typ: inline, eskip: `route2: Method("PUT") -> <shunt>; route3: Method("HEAD") -> <shunt>`}
	out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix}
	writeClient, _ := createWriteClient(out)
	readOutClient, _ := createReadClient(out)
	readClient, _ := createReadClient(in)

	err := etcdtest.PutDataTo(defaultEtcdPrefix, "route1", `Method("GET") -> <shunt>`)
	if err != nil {
		t.Error(err)
	}

	err = etcdtest.PutDataTo(defaultEtcdPrefix, "route2", `Method("POST") -> <shunt>`)
	if err != nil {
		t.Error(err)
	}

	err = resetCmd(readClient, readOutClient, writeClient)
	if err != nil {
		t.Error(err)
	}

	routes, err := loadRoutesChecked(readOutClient)
	if err != nil {
		t.Error(err)
	}

	if len(routes) != 2 {
		t.Error("failed to reset routes")
	}

	for _, id := range []string{"route2", "route3"} {
		found := false
		for _, r := range routes {
			if r.Id != id {
				continue
			}

			found = true
			switch id {
			case "route2":
				if r.Method != "PUT" {
					t.Error("failed to reset routes")
				}
			case "route3":
				if r.Method != "HEAD" {
					t.Error("failed to reset routes")
				}
			}
		}

		if !found {
			t.Error("failed to reset routes")
		}
	}
}
コード例 #2
0
ファイル: write_test.go プロジェクト: zalando/skipper
func TestResetLoadExistingFails(t *testing.T) {
	etcdtest.DeleteAllFrom(defaultEtcdPrefix)

	in := &medium{typ: inline, eskip: `route2: Method("POST") -> <shunt>`}
	out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix}
	err := etcdtest.PutDataTo(defaultEtcdPrefix, "route1", "invalid doc")
	if err != nil {
		t.Error(err)
	}

	err = resetCmd(cmdArgs{in: in, out: out})
	if err != nil {
		t.Error(err)
	}

	_, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route1")
	if err == nil {
		t.Error(err)
	}

	_, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route2")
	if err != nil {
		t.Error(err)
	}
}
コード例 #3
0
func TestResetLoadExistingFails(t *testing.T) {
	etcdtest.DeleteAllFrom(defaultEtcdPrefix)

	in := &medium{typ: inline, eskip: `route2: Method("POST") -> <shunt>`}
	out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix}
	writeClient, _ := createWriteClient(out)
	readOutClient, _ := createReadClient(out)
	readClient, _ := createReadClient(in)

	err := etcdtest.PutDataTo(defaultEtcdPrefix, "route1", "invalid doc")
	if err != nil {
		t.Error(err)
	}

	err = resetCmd(readClient, readOutClient, writeClient)
	if err != nil {
		t.Error(err)
	}

	_, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route1")
	if err == nil {
		t.Error(err)
	}

	_, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route2")
	if err != nil {
		t.Error(err)
	}
}