-
Notifications
You must be signed in to change notification settings - Fork 5
/
config_test.go
69 lines (57 loc) · 1.5 KB
/
config_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 main
import (
"bytes"
"fmt"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
const defaultConfig = `
{
"credentials": {
"email": "[email protected]",
"token": "ABCDEFGHIJKLMNOP"
},
"domains": [
{
"name": "example.com",
"record-type": "A"
},
{
"name": "finishfirstsoftware.com",
"record-type": "A"
}
]
}
`
func TestLoadAllDomains(t *testing.T) {
var config Config
if err := decodeConfig(bytes.NewBufferString(defaultConfig), &config); err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
}
domains := config.LoadAllDomains()
assert.Equal(t, 2, len(domains))
for _, d := range domains {
fmt.Println(d.Name)
}
}
func TestCredentialsAreReadFromConfig(t *testing.T) {
var config Config
if err := decodeConfig(bytes.NewBufferString(defaultConfig), &config); err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
}
assert.Equal(t, config.Email(), "[email protected]")
assert.Equal(t, config.Token(), "ABCDEFGHIJKLMNOP")
}
func TestDomainsAreReadFromConfig(t *testing.T) {
var config Config
if err := decodeConfig(bytes.NewBufferString(defaultConfig), &config); err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
}
domain, _ := config.LoadDomain("example.com")
assert.Equal(t, domain.Name, "example.com")
assert.Equal(t, domain.RecordType, "A")
domain, _ = config.LoadDomain("finishfirstsoftware.com")
assert.Equal(t, domain.Name, "finishfirstsoftware.com")
assert.Equal(t, domain.RecordType, "A")
}