Ejemplo n.º 1
0
func TestMaxUserReached(t *testing.T) {
	server := setup()
	defer server.Close()
	defer close()

	conf.SetMaxClients(3)

	cr1 := ClientRequest{0, 0, 10, 0, nil}
	cr2 := ClientRequest{0, 0, 10, 0, nil}
	cr3 := ClientRequest{0, 0, 10, 0, nil}

	sr1 := normalPost(cr1, t, server.URL)
	normalPost(cr2, t, server.URL)
	normalPost(cr3, t, server.URL)

	//Max limit reached
	cr4 := ClientRequest{0, 0, 10, 0, nil}
	sr4 := normalPost(cr4, t, server.URL)

	if sr4.Code != 0 {
		t.Error("Incorrect code 1:", sr4.Code)
	}

	cr1.Id = sr1.Id
	cr1.Key = sr1.Key
	cr1.Code = 100

	//Delete cr1
	normalPost(cr1, t, server.URL)

	//request again
	sr4 = normalPost(cr4, t, server.URL)

	if sr4.Code == 0 {
		t.Error("Incorrect code 2:", sr4.Code)
	}

}
Ejemplo n.º 2
0
func TestMaxNumberClients(t *testing.T) {
	conf.SetMaxClients(3)

	c := New()
	c.Init()
	defer c.Close()

	header := make(map[string][]string)

	id1, key1, err1 := c.NewClient(header)
	if err1 != nil {
		t.Error("Client1:", err1)
	}

	_, _, err2 := c.NewClient(header)
	if err2 != nil {
		t.Error("Client2:", err2)
	}

	_, _, err3 := c.NewClient(header)
	if err3 != nil {
		t.Error("Client3:", err3)
	}

	//Max reached
	_, _, err4 := c.NewClient(header)
	if err4 == nil {
		t.Error("No error in Client4")
	}

	c.DeleteClient(id1, key1, header)

	_, _, err5 := c.NewClient(header)
	if err5 != nil {
		t.Error("Client5:", err5)
	}

}