forked from anuaimi/rage4
/
api_test.go
168 lines (135 loc) · 4.55 KB
/
api_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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package rage4
import (
"fmt"
"os"
"testing"
"net/http"
"github.com/spf13/viper"
)
var client Client
func TestMain(m *testing.M) {
// setup mock rage4 api server()
go serverWebPages()
// get settings for rage4
viper.SetConfigName("testing") // can be testing.json, testing.yaml
viper.AddConfigPath("./example")
viper.ReadInConfig()
accountKey := viper.GetString("AccountKey")
email := viper.GetString("Email")
url := viper.GetString("URL")
fmt.Printf("testing rage4 api at %s using account %s\n", url, accountKey)
// create client to test API calls
client = Client{
AccountKey: accountKey,
Email: email,
URL: url,
Http: http.DefaultClient,
}
if (client == Client{}) {
os.Exit(-1)
}
retCode := m.Run()
fmt.Printf("result = %d", retCode)
// teardown()
os.Exit(retCode)
}
func serverWebPages() {
// create web server - port 9000
http.HandleFunc("/testAuth", testAuthHandler)
baseURL := "rapi"
http.HandleFunc( baseURL + "/getdomains", getDomainsHandler)
http.HandleFunc( baseURL + "/getdomain", getDomainHandler)
http.HandleFunc( baseURL + "/getdomainbyname", getDomainsHandler)
http.HandleFunc( baseURL + "/createregulardomain", createRegularDomainHandler)
http.HandleFunc( baseURL + "/createregulardomainext", createRegularDomainExtHandler)
http.HandleFunc( baseURL + "/createreversedomain4", createReverseDomain4Handler)
http.HandleFunc( baseURL + "/createreversedomain6", createReverseDomain6Handler)
http.HandleFunc( baseURL + "/updatedomain", updateDomainHandler)
http.HandleFunc( baseURL + "/deletedomain", deleteDomainHandler)
http.HandleFunc( baseURL + "/showcurrentusage", showCurrentUsageHandler)
http.HandleFunc( baseURL + "/showcurrentglobalusage", showCurrentGlobalUsageHandler)
http.HandleFunc( baseURL + "/listrecordtypes", listRecordTypesHandler)
http.HandleFunc( baseURL + "/listgeoregions", listGeoRegionsHandler)
http.HandleFunc( baseURL + "/getrecords", getRecordsHandler)
http.HandleFunc( baseURL + "/createrecord", createRecordHandler)
http.HandleFunc( baseURL + "/updaterecord", updateRecordHandler)
http.HandleFunc( baseURL + "/deleterecord", deleteRecordHandler)
http.ListenAndServe(":9000", nil)
}
func testAuthHandler(w http.ResponseWriter, r *http.Request) {
// test run completed
os.Exit(0)
}
func getDomainsHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func getDomainHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func createRegularDomainHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func createRegularDomainExtHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func createReverseDomain4Handler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func createReverseDomain6Handler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func updateDomainHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func deleteDomainHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func showCurrentUsageHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func showCurrentGlobalUsageHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func listRecordTypesHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func listGeoRegionsHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func getRecordsHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func createRecordHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func updateRecordHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
func deleteRecordHandler(w http.ResponseWriter, r *http.Request) {
// no input required
// return array of domain info
}
/////////////
func TestAuthentication(t *testing.T) {
//make sure username & password passed in and
}
func TestGetDomains(t *testing.T) {
fmt.Print("testing getdomains")
// domains, err := client.GetDomains()
client.GetDomains()
}