-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider_test.go
129 lines (125 loc) · 2.93 KB
/
provider_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package glesys
import (
"context"
"os"
"testing"
"time"
"github.com/libdns/libdns"
)
func TestProvider_GetRecords(t *testing.T) {
skipUnauth(t)
type fields struct {
Project string
ApiKey string
}
type args struct {
ctx context.Context
zone string
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{"first",
fields{os.Getenv("GLESYS_PROJECT"), os.Getenv("GLESYS_KEY")},
args{context.TODO(), os.Getenv("GLESYS_ZONE")},
false,
},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &Provider{
Project: tt.fields.Project,
ApiKey: tt.fields.ApiKey,
}
got, err := p.GetRecords(tt.args.ctx, tt.args.zone)
if (err != nil) != tt.wantErr {
t.Errorf("Provider.GetRecords() error = %v, wantErr %v", err, tt.wantErr)
return
}
if len(got) < 1 {
t.Errorf("Expected > 0 records. Got %v", len(got))
}
for i, r := range got {
if r.Name == "" {
t.Errorf("Expected record %d name. Got '%v'", i, r.Name)
}
if r.TTL < 1*time.Second {
t.Errorf("Record %d (%v) hand < 1 second TTL. Got %v", i, r, r.TTL)
}
switch r.Type {
case "MX":
if r.Priority < 1 {
t.Errorf("Expected record %d of type %s to have a priority. Got %v", i, r.Type, r.Priority)
}
}
}
// t.Errorf("Got %+v", got)
})
}
}
func TestProvider_AppendRecords(t *testing.T) {
skipUnauth(t)
type fields struct {
Project string
ApiKey string
}
type args struct {
ctx context.Context
zone string
records []libdns.Record
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{"first",
fields{os.Getenv("GLESYS_PROJECT"), os.Getenv("GLESYS_KEY")},
args{
context.TODO(),
os.Getenv("GLESYS_ZONE"),
[]libdns.Record{
{Type: "TXT", TTL: time.Minute * 5, Name: "_libdns-test", Value: time.Now().Local().String()},
},
},
false,
},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &Provider{
Project: tt.fields.Project,
ApiKey: tt.fields.ApiKey,
}
got, err := p.AppendRecords(tt.args.ctx, tt.args.zone, tt.args.records)
if (err != nil) != tt.wantErr {
t.Errorf("Provider.AppendRecords() error = %v, wantErr %v", err, tt.wantErr)
return
}
if len(got) != len(tt.args.records) {
t.Errorf("Record count requested is not same as returned. Got %v, want %v", len(got), len(tt.args.records))
}
for i, gr := range got {
if gr.ID == "" {
t.Errorf("Expected a record ID but got nothing: %+v", gr)
}
wr := tt.args.records[i]
if gr.Name != wr.Name {
t.Errorf("Mismatching name. Got %v, Want %v", gr.Name, wr.Name)
}
if gr.TTL != wr.TTL {
t.Errorf("Mismatching TTL. Got %v, Want %v", gr.TTL, wr.TTL)
}
if gr.Value != wr.Value {
t.Errorf("Mismatching Value. Got %v, Want %v", gr.Value, wr.Value)
}
}
})
}
}