53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/rand"
|
|
"reflect"
|
|
)
|
|
|
|
const (
|
|
testBaseURL string = "http://localhost:8081"
|
|
testVhost string = "localhost"
|
|
testAPIKey string = "123Password"
|
|
)
|
|
|
|
func generateTestAPIURL() string {
|
|
return fmt.Sprintf("%s/api/v1", testBaseURL)
|
|
}
|
|
|
|
func generateTestAPIVhostURL() string {
|
|
return fmt.Sprintf("%s/servers/%s", generateTestAPIURL(), testVhost)
|
|
}
|
|
|
|
func generateTestRequestURI() string {
|
|
return fmt.Sprintf("api/v1/servers/%s", testVhost)
|
|
}
|
|
|
|
func initializePowerDNSTestClient() (*PowerDNS, error) {
|
|
pdns, err := NewClient(testBaseURL, testAPIKey, 3, 7200)
|
|
return pdns, err
|
|
}
|
|
|
|
func generateTestZone() string {
|
|
domain := fmt.Sprintf("test-%d.com", rand.Int())
|
|
return domain
|
|
}
|
|
|
|
func areEqualJSON(s1, s2 []byte) (bool, error) {
|
|
var o1 interface{}
|
|
var o2 interface{}
|
|
|
|
var err error
|
|
err = json.Unmarshal([]byte(s1), &o1)
|
|
if err != nil {
|
|
return false, fmt.Errorf("Error mashalling string 1 :: %s", err.Error())
|
|
}
|
|
err = json.Unmarshal(s2, &o2)
|
|
if err != nil {
|
|
return false, fmt.Errorf("Error mashalling string 2 :: %s", err.Error())
|
|
}
|
|
return reflect.DeepEqual(o1, o2), nil
|
|
}
|