-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsubscription_test.go
64 lines (60 loc) · 1.6 KB
/
subscription_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: Winni Neessen <wn@neessen.dev> et al
//
// SPDX-License-Identifier: MIT
package hibp
import (
"net/http"
"os"
"testing"
)
// TestSubscriptionAPI_Status tests the Status() method of the subscription API
func TestSubscriptionAPI_Status(t *testing.T) {
t.Run("Unauthenticated", func(t *testing.T) {
hc := New(WithRateLimitSleep())
subscriptionStatus, httpResponse, err := hc.SubscriptionAPI.Status()
if err == nil {
t.Errorf("err is nil but expected a failure")
}
if httpResponse == nil {
t.Errorf("httpResponse is nil")
} else {
if httpResponse.StatusCode != http.StatusUnauthorized {
t.Errorf("unexpected status code: %d", httpResponse.StatusCode)
}
}
if subscriptionStatus != nil {
t.Errorf("subscriptionStatus is not nil")
}
})
t.Run("Authenticated", func(t *testing.T) {
apiKey := os.Getenv("HIBP_API_KEY")
if apiKey == "" {
t.SkipNow()
}
hc := New(WithAPIKey(apiKey), WithRateLimitSleep())
subscriptionStatus, httpResponse, err := hc.SubscriptionAPI.Status()
if err != nil {
t.Error(err)
}
if httpResponse == nil {
t.Errorf("httpResponse is nil")
} else {
if httpResponse.StatusCode != http.StatusOK {
t.Errorf("unexpected status code: %d", httpResponse.StatusCode)
}
}
if subscriptionStatus == nil {
t.Errorf("subscriptionStatus is nil")
} else {
if subscriptionStatus.Description == "" {
t.Errorf("Description is empty")
}
if subscriptionStatus.SubscriptionName == "" {
t.Errorf("SubscriptionName is empty")
}
if subscriptionStatus.Rpm <= 0 {
t.Errorf("Rpm is impossible")
}
}
})
}