-
Notifications
You must be signed in to change notification settings - Fork 2
/
zone_test.go
91 lines (70 loc) · 1.59 KB
/
zone_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
86
87
88
89
90
91
package hcdns_test
import (
"context"
"os"
"testing"
"time"
"go.acim.net/hcdns"
)
func TestRecords(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}
client := hcdns.NewClient(os.Getenv("TOKEN"))
zoneName := "hcdns-test.io"
ctx := context.Background()
zone, err := client.CreateZone(ctx, zoneName)
if err != nil {
t.Fatal(err)
}
records, err := zone.Records(ctx)
if err != nil {
t.Fatal(err)
}
if len(records) != 4 {
t.Errorf("got %d records; want 4 records", len(records))
}
if err := zone.Delete(ctx); err != nil {
t.Fatal(err)
}
}
func TestRecord(t *testing.T) { //nolint:cyclop
t.Parallel()
if testing.Short() {
t.Skip("skipping test in short mode")
}
c := hcdns.NewClient(os.Getenv("TOKEN"))
zoneName := "hcdns-test.co"
ctx := context.Background()
zone, err := c.CreateZoneWithDefaultTTL(ctx, zoneName, time.Hour)
if err != nil {
t.Fatal(err)
}
record, err := zone.CreateRecordWithTTL(ctx, hcdns.A, "foo", "127.0.0.1", time.Minute)
if err != nil {
t.Error(err)
}
if record.Type != hcdns.A {
t.Errorf("got type %s; want A", record.Type)
}
if record.Name != "foo" {
t.Errorf("got name %s; want foo", record.Name)
}
if record.Value != "127.0.0.1" {
t.Errorf("got value %s; want 127.0.0.1", record.Value)
}
if record.TTL != 60 {
t.Errorf("got ttl %d; want 60", record.TTL)
}
if record.ZoneID != zone.ID {
t.Errorf("got zone id %s; want %s", record.ZoneID, zone.ID)
}
_, err = zone.Record(ctx, record.ID)
if err != nil {
t.Error(err)
}
if err := zone.Delete(ctx); err != nil {
t.Fatal(err)
}
}