Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesClonk committed Feb 13, 2016
1 parent 07e0487 commit 38c4612
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions lib/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,25 @@ func Test_Client_NewClient(t *testing.T) {
}
}

// Test that API queries are throttled to 1/sec
// Test that API queries are throttled
func Test_Client_Throttling(t *testing.T) {
const ERROR = 250 * time.Millisecond
const EXPECTED_DURATION = 4 * time.Second
const ERROR = 100 * time.Millisecond
const EXPECTED_DURATION = 400 * time.Millisecond
server, _ := getTestServerAndClient(http.StatusOK, `{
"balance":-15.97,"pending_charges":"2.34",
"last_payment_date":"2015-01-29 05:06:27","last_payment_amount":"-5.00"}`)
defer server.Close()

options := Options{
Endpoint: server.URL,
RateLimitation: 1 * time.Second,
RateLimitation: 100 * time.Millisecond,
}
client := NewClient("test-key", &options)

time.Sleep(1 * time.Second)

// The first query should not be throttled
info, _ := client.GetAccountInfo()

// The next four queries should be throttled and take 4 seconds
// The next four queries should be throttled and take 400 milliseconds
before := time.Now()
info, _ = client.GetAccountInfo()
info, _ = client.GetAccountInfo()
Expand Down
2 changes: 1 addition & 1 deletion lib/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func Test_Servers_GetServer_OK(t *testing.T) {
"pending_charges":0.04,"status":"active","cost_per_month":"5.00","current_bandwidth_gb":7,"allowed_bandwidth_gb":"1000",
"netmask_v4":"255.255.255.0","gateway_v4":"123.456.789.1","power_status":"running","VPSPLANID":"29","v6_network":"::",
"v6_main_ip":"","v6_network_size":"0","label":"test alpha","internal_ip":"",
"v6_networks": [{"v6_network": "::", "v6_network_size": "0" }],
"v6_networks": [{"v6_network": "::", "v6_main_ip": "", "v6_network_size": "0" }],
"kvm_url":"https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=123","auto_backups":"no"}`)
defer server.Close()

Expand Down

0 comments on commit 38c4612

Please sign in to comment.