-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
48 lines (40 loc) · 986 Bytes
/
main_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
package main
import (
"log"
"os"
"path"
"testing"
)
func createFakeConfigPath() {
// Change configPath
err := os.Setenv("TMPDIR", "/tmp")
if err != nil {
log.Fatal(" ", err)
}
tmpPath := os.Getenv("TMPDIR")
// Set a configuration path environment in /tmp/.dnscli
configPath = path.Join(tmpPath, ".dnscli")
configFile = path.Join(configPath, "config.json")
createConfigPath()
}
func TestCreateConfigPath(t *testing.T) {
createFakeConfigPath()
// Clean up
defer func() {
os.RemoveAll(configPath)
}()
if _, err := os.Stat(configFile); os.IsNotExist(err) {
t.Error("configuration path not found")
}
}
func TestSetHeaders(t *testing.T) {
config.ApiURL = "https://api.custom.com"
config.Domain = "example.com"
config.Token = "Token123"
config.Mail = "[email protected]"
r := setHeaders("GET", "customurl", nil)
dnsToken := config.Mail + ":" + config.Token
if r.Header.Get("X-DNSimple-Token") != dnsToken {
t.Error("DNS Headers not properly set")
}
}