示例#1
0
func TestDo(t *testing.T) {
	c := goprana.NewClient(goprana.DefaultPort)

	for path, want := range reqChecks {
		req, err := http.NewRequest("GET", "", nil)
		if err != nil {
			t.Fatal(err)
		}
		resp, err := c.Do(vip, path, req)
		if err != nil {
			t.Fatal(err)
		}

		dec := json.NewDecoder(resp.Body)
		var r quoteResp
		if err := dec.Decode(&r); err != nil {
			t.Fatal(err)
		}
		resp.Body.Close()

		if r.Quote != want.Quote {
			t.Errorf("got quote %v, want %v", r.Quote, want.Quote)
		}
		if r.Counter <= 0 {
			t.Errorf("got quote counter %v, want >0", r.Counter)
		}
	}
}
示例#2
0
func TestHosts(t *testing.T) {
	c := goprana.NewClient(goprana.DefaultPort)

	hosts, err := c.Hosts(appName, vip)
	if err != nil {
		t.Fatal(err)
	}

	if len(hosts) == 0 {
		t.Error("got 0 hosts")
	}
}
示例#3
0
func TestPost(t *testing.T) {
	c := goprana.NewClient(goprana.DefaultPort)

	for path := range reqChecks {
		resp, err := c.Post(vip, path, "", nil)
		if err != nil {
			t.Fatal(err)
		}
		resp.Body.Close()

		if resp.StatusCode != http.StatusNotImplemented {
			t.Errorf("got status %v, want 501 Not Implemented", resp.StatusCode)
		}
	}
}
示例#4
0
func ExampleClient_Get() {
	c := goprana.NewClient(goprana.DefaultPort)

	resp, err := c.Get("gotquotes-go", "/api/quote/random")
	if err != nil {
		log.Fatalln(err)
	}
	defer resp.Body.Close()

	output, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("%s", output)
}
示例#5
0
func TestDynamicProperties(t *testing.T) {
	c := goprana.NewClient(goprana.DefaultPort)

	ids := []string{}
	for k := range propChecks {
		ids = append(ids, k)
	}

	props, err := c.DynamicProperties(ids...)
	if err != nil {
		t.Fatal(err)
	}

	for id, want := range propChecks {
		val, ok := props[id]
		if !ok {
			t.Errorf("property %v not found", id)
			continue
		}
		if val != want {
			t.Errorf("got property %v=%v, want %v", id, val, want)
		}
	}
}