@@ -3,18 +3,20 @@ package porkbun
3
3
import (
4
4
"bacon/pkg/client"
5
5
"bacon/pkg/porkbun"
6
+ "encoding/json"
6
7
"fmt"
7
8
"testing"
9
+
10
+ "gopkg.in/yaml.v3"
8
11
)
9
12
10
- func TestConvertToPorkbunRecord (t * testing.T ) {
13
+ func TestConvertToPorkbun (t * testing.T ) {
11
14
record := client.Record {
12
15
Type : "A" ,
13
16
Host : "www.example.com" ,
14
17
Content : "123.456.789.112" ,
15
18
TTL : 600 ,
16
19
}
17
-
18
20
porkRecord := porkbun .ConvertToPorkbunRecord (record )
19
21
20
22
if porkRecord .Type != record .Type {
@@ -29,7 +31,6 @@ func TestConvertToPorkbunRecord(t *testing.T) {
29
31
t .Log ("expected" , record .Content , "found" , porkRecord .Content )
30
32
t .Fail ()
31
33
}
32
-
33
34
if porkRecord .TTL != fmt .Sprint (record .TTL ) {
34
35
t .Log ("expected" , fmt .Sprint (record .TTL ), "found" , porkRecord .TTL )
35
36
}
@@ -38,34 +39,32 @@ func TestConvertToPorkbunRecord(t *testing.T) {
38
39
}
39
40
}
40
41
41
- func TestConvertToClientRecord (t * testing.T ) {
42
+ func TestConvertToClientSimple (t * testing.T ) {
42
43
porkRecord := porkbun.PorkbunRecord {
43
44
Id : "abcxyz" ,
44
45
Name : "www.example.com" ,
45
46
Type : "A" ,
46
47
Content : "123.456.789.112" ,
47
48
TTL : "600" ,
48
49
}
49
-
50
50
record , err := porkbun .ConvertToClientRecord (porkRecord )
51
51
if err != nil {
52
52
t .Log (err )
53
53
t .FailNow ()
54
54
}
55
55
56
- if record .Host != porkRecord .Name {
57
- t .Log ("expected" , porkRecord .Name , "found" , record .Host )
58
- t .Fail ()
59
- }
60
56
if record .Type != porkRecord .Type {
61
57
t .Log ("expected" , porkRecord .Type , "found" , record .Type )
62
58
t .Fail ()
63
59
}
60
+ if record .Host != porkRecord .Name {
61
+ t .Log ("expected" , porkRecord .Name , "found" , record .Host )
62
+ t .Fail ()
63
+ }
64
64
if record .Content != porkRecord .Content {
65
65
t .Log ("expected" , porkRecord .Content , "found" , record .Content )
66
66
t .Fail ()
67
67
}
68
-
69
68
if record .TTL != 600 {
70
69
t .Log ("expected" , porkRecord .TTL , "found" , 600 )
71
70
t .Fail ()
@@ -113,3 +112,59 @@ func TestHashFuzzy(t *testing.T) {
113
112
t .Fail ()
114
113
}
115
114
}
115
+
116
+ func TestComparePorkbunResponse (t * testing.T ) {
117
+ const config = `type: CNAME
118
+ host: www.jungaretti.com
119
+ content: green-forest-08be42d1e.azurestaticapps.net
120
+ ttl: 600`
121
+ const response = `{"id": "188254337","name": "www.jungaretti.com","type": "CNAME","content": "green-forest-08be42d1e.azurestaticapps.net","ttl": "600","prio": "0"}`
122
+
123
+ record := client.Record {}
124
+ err := yaml .Unmarshal ([]byte (config ), & record )
125
+ if err != nil {
126
+ t .Log (err )
127
+ t .FailNow ()
128
+ }
129
+ porkRecord := porkbun.PorkbunRecord {}
130
+ err = json .Unmarshal ([]byte (response ), & porkRecord )
131
+ if err != nil {
132
+ t .Log (err )
133
+ t .FailNow ()
134
+ }
135
+
136
+ convertedRecord := porkbun .ConvertToPorkbunRecord (record )
137
+ if porkRecord .HashFuzzy () != convertedRecord .HashFuzzy () {
138
+ t .Log (porkRecord .HashFuzzy ())
139
+ t .Log (convertedRecord .HashFuzzy ())
140
+ t .Fail ()
141
+ }
142
+ }
143
+
144
+ func TestComparePorkbunResponseNullPriority (t * testing.T ) {
145
+ const config = `type: CNAME
146
+ host: www.jungaretti.com
147
+ content: green-forest-08be42d1e.azurestaticapps.net
148
+ ttl: 600`
149
+ const response = `{"id": "188254337","name": "www.jungaretti.com","type": "CNAME","content": "green-forest-08be42d1e.azurestaticapps.net","ttl": "600","prio": null}`
150
+
151
+ record := client.Record {}
152
+ err := yaml .Unmarshal ([]byte (config ), & record )
153
+ if err != nil {
154
+ t .Log (err )
155
+ t .FailNow ()
156
+ }
157
+ porkRecord := porkbun.PorkbunRecord {}
158
+ err = json .Unmarshal ([]byte (response ), & porkRecord )
159
+ if err != nil {
160
+ t .Log (err )
161
+ t .FailNow ()
162
+ }
163
+
164
+ convertedRecord := porkbun .ConvertToPorkbunRecord (record )
165
+ if porkRecord .HashFuzzy () != convertedRecord .HashFuzzy () {
166
+ t .Log ("one" , porkRecord .HashFuzzy ())
167
+ t .Log ("two" , convertedRecord .HashFuzzy ())
168
+ t .Error ()
169
+ }
170
+ }
0 commit comments