-
Notifications
You must be signed in to change notification settings - Fork 3
/
api_validate_test.go
43 lines (33 loc) · 1.02 KB
/
api_validate_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
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
type ValidateTestStorage struct {
NullStorage
Accept bool
}
func (storage *ValidateTestStorage) AccountHasKey(name, key string) (bool, error) {
return storage.Accept, nil
}
func TestValidateHandlerSuccess(t *testing.T) {
r := HTTPRequest(t, "GET", "https://localhost/v1/validate?accountName=someone&apiKey=ff01ab", "")
w := httptest.NewRecorder()
s := &ValidateTestStorage{Accept: true}
c := &Context{Storage: s}
ValidateHandler(c, w, r)
if w.Code != http.StatusNoContent {
t.Errorf("Expected response code %d, but was %d", http.StatusNoContent, w.Code)
}
}
func TestValidateHandlerReject(t *testing.T) {
r := HTTPRequest(t, "GET", "https://localhost/v1/validate?accountName=someone&apiKey=ff01ab", "")
w := httptest.NewRecorder()
s := &ValidateTestStorage{Accept: false}
c := &Context{Storage: s}
ValidateHandler(c, w, r)
if w.Code != http.StatusNotFound {
t.Errorf("Expected response code %d, but was %d", http.StatusNotFound, w.Code)
}
}