-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_test.go
85 lines (64 loc) · 1.45 KB
/
client_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package hcdns_test
import (
"context"
"os"
"testing"
"time"
"go.acim.net/hcdns"
)
func TestZones(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}
c := hcdns.NewClient(os.Getenv("TOKEN"))
zs, err := c.Zones(context.Background())
if err != nil {
t.Fatal(err)
}
if len(zs) == 0 {
t.Error("got 0 zones; want more than zero")
}
}
func TestZone(t *testing.T) { //nolint:cyclop
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}
client := hcdns.NewClient(os.Getenv("TOKEN"))
zoneName := "hcdns-test.com"
ctx := context.Background()
zone, err := client.CreateZone(ctx, zoneName)
if err != nil {
t.Fatal(err)
}
if zone.Name != zoneName {
t.Errorf("got name %s; want %s", zone.Name, zoneName)
}
if zone.TTL != 86400 {
t.Errorf("got ttl %d; want %d", zone.TTL, 86400)
}
zone, err = client.Zone(ctx, zone.ID)
if err != nil {
t.Errorf("zone: %v", err)
}
if zone.Name != zoneName {
t.Errorf("got name %s; want %s", zone.Name, zoneName)
}
zone, err = client.ZoneByName(ctx, zone.Name)
if err != nil {
t.Errorf("zone by name: %v", err)
}
if zone.Name != zoneName {
t.Errorf("got name %s; want %s", zone.Name, zoneName)
}
if err := zone.UpdateDefaultTTL(ctx, time.Hour); err != nil {
t.Errorf("update zone: %v", err)
}
if zone.TTL != 3600 {
t.Errorf("got ttl %d; want %d", zone.TTL, 3600)
}
if err := zone.Delete(ctx); err != nil {
t.Fatal(err)
}
}