-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathloopia_test.go
59 lines (49 loc) · 1.45 KB
/
loopia_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
package loopia
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"strings"
"fmt"
"github.com/stretchr/testify/assert"
)
var (
// mux is the HTTP request multiplexer used with the test server.
mux *http.ServeMux
// client is the API client being tested
client *API
// server is a test HTTP server used to provide mock API responses
server *httptest.Server
)
func setup() {
// test server
mux = http.NewServeMux()
server = httptest.NewServer(mux)
client, _ = New("loopia@loopiaapi", "verysecret")
client.RPCEndpoint = server.URL
}
func teardown() {
server.Close()
}
func TestClient_Credentials(t *testing.T) {
setup()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "POST", r.Method, "Expected method 'POST', got %s", r.Method)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Error("Unexpected error when reading response Body")
}
xmlParamPattern := "<param><value>%s</value></param>"
search := []string {
fmt.Sprintf(xmlParamPattern, "<string>loopia@loopiaapi</string>"),
fmt.Sprintf(xmlParamPattern, "<string>verysecret</string>"),
fmt.Sprintf(xmlParamPattern, "<string></string>"),
fmt.Sprintf(xmlParamPattern, "<string>example.com</string>"),
fmt.Sprintf(xmlParamPattern, "<string>www</string>"),
}
assert.Contains(t, string(body[:]), strings.Join(search, ""), "Expected username inside XML body")
})
client.GetZoneRecord("example.com", "www", 12345)
teardown()
}