-
Notifications
You must be signed in to change notification settings - Fork 2
/
record_test.go
69 lines (53 loc) · 1.27 KB
/
record_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
package hcdns_test
import (
"context"
"os"
"testing"
"time"
"go.acim.net/hcdns"
)
func TestUpdateAndDelete(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.rs"
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 err := record.UpdateValue(ctx, "192.168.0.1"); err != nil {
t.Error(err)
}
if record.Value != "192.168.0.1" {
t.Errorf("got value %s; want 192.168.0.1", record.Value)
}
if err := record.UpdateValueAndTTL(ctx, "192.168.1.1", time.Hour); err != nil {
t.Error(err)
}
if record.Value != "192.168.1.1" {
t.Errorf("got value %s; want 192.168.1.1", record.Value)
}
if record.TTL != 3600 {
t.Errorf("got ttl %d; want 3600", record.TTL)
}
if err := record.Delete(ctx); err != nil {
t.Error(err)
}
records, err := zone.Records(ctx)
if err != nil {
t.Error(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)
}
}