File: tlds_test.go

package info (click to toggle)
golang-github-dnsimple-dnsimple-go 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,428 kB
  • sloc: makefile: 3
file content (107 lines) | stat: -rw-r--r-- 3,017 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package dnsimple

import (
	"context"
	"io"
	"net/http"
	"net/url"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestTldsService_ListTlds(t *testing.T) {
	setupMockServer()
	defer teardownMockServer()

	mux.HandleFunc("/v2/tlds", func(w http.ResponseWriter, r *http.Request) {
		httpResponse := httpResponseFixture(t, "/api/listTlds/success.http")

		testMethod(t, r, "GET")
		testHeaders(t, r)

		w.WriteHeader(httpResponse.StatusCode)
		_, _ = io.Copy(w, httpResponse.Body)
	})

	tldsResponse, err := client.Tlds.ListTlds(context.Background(), nil)

	assert.NoError(t, err)
	assert.Equal(t, &Pagination{CurrentPage: 1, PerPage: 2, TotalPages: 98, TotalEntries: 195}, tldsResponse.Pagination)
	tlds := tldsResponse.Data
	assert.Len(t, tlds, 2)
	assert.Equal(t, "ac", tlds[0].Tld)
	assert.Equal(t, 1, tlds[0].MinimumRegistration)
	assert.True(t, tlds[0].RegistrationEnabled)
	assert.True(t, tlds[0].RenewalEnabled)
	assert.False(t, tlds[0].TransferEnabled)
}

func TestTldsService_ListTlds_WithOptions(t *testing.T) {
	setupMockServer()
	defer teardownMockServer()

	mux.HandleFunc("/v2/tlds", func(w http.ResponseWriter, r *http.Request) {
		httpResponse := httpResponseFixture(t, "/api/listTlds/success.http")

		testQuery(t, r, url.Values{"page": []string{"2"}, "per_page": []string{"20"}})

		w.WriteHeader(httpResponse.StatusCode)
		_, _ = io.Copy(w, httpResponse.Body)
	})

	_, err := client.Tlds.ListTlds(context.Background(), &ListOptions{Page: Int(2), PerPage: Int(20)})

	assert.NoError(t, err)
}

func TestTldsService_GetTld(t *testing.T) {
	setupMockServer()
	defer teardownMockServer()

	mux.HandleFunc("/v2/tlds/com", func(w http.ResponseWriter, r *http.Request) {
		httpResponse := httpResponseFixture(t, "/api/getTld/success.http")

		testMethod(t, r, "GET")
		testHeaders(t, r)

		w.WriteHeader(httpResponse.StatusCode)
		_, _ = io.Copy(w, httpResponse.Body)
	})

	tldResponse, err := client.Tlds.GetTld(context.Background(), "com")

	assert.NoError(t, err)
	tld := tldResponse.Data
	assert.Equal(t, "com", tld.Tld)
	assert.Equal(t, 1, tld.TldType)
	assert.True(t, tld.WhoisPrivacy)
	assert.False(t, tld.AutoRenewOnly)
	assert.Equal(t, 1, tld.MinimumRegistration)
	assert.True(t, tld.RegistrationEnabled)
	assert.True(t, tld.RenewalEnabled)
	assert.True(t, tld.TransferEnabled)
	assert.Equal(t, "ds", tld.DnssecInterfaceType)
}

func TestTldsService_GetTldExtendedAttributes(t *testing.T) {
	setupMockServer()
	defer teardownMockServer()

	mux.HandleFunc("/v2/tlds/com/extended_attributes", func(w http.ResponseWriter, r *http.Request) {
		httpResponse := httpResponseFixture(t, "/api/getTldExtendedAttributes/success.http")

		testMethod(t, r, "GET")
		testHeaders(t, r)

		w.WriteHeader(httpResponse.StatusCode)
		_, _ = io.Copy(w, httpResponse.Body)
	})

	tldResponse, err := client.Tlds.GetTldExtendedAttributes(context.Background(), "com")

	assert.NoError(t, err)
	attributes := tldResponse.Data
	assert.Len(t, attributes, 4)
	assert.Equal(t, "uk_legal_type", attributes[0].Name)
}