forked from microscaling/imagelayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
88 lines (63 loc) · 1.82 KB
/
main_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
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
var (
srv *httptest.Server
)
func setupServer() {
srv = httptest.NewServer(NewServer().createRouter())
}
func teardownServer() {
srv.Close()
}
func TestStatusGetSuccess(t *testing.T) {
setupServer()
defer teardownServer()
path := srv.URL + "/registry/status"
req, _ := http.NewRequest("GET", path, nil)
req.Header.Add("Origin", srv.URL)
resp, err := http.DefaultClient.Do(req)
assert.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, srv.URL, resp.Header.Get("Access-Control-Allow-Origin"), "CORS Allow-Origin not set")
}
func TestAnalyzePostSuccess(t *testing.T) {
setupServer()
defer teardownServer()
path := srv.URL + "/registry/analyze"
req, _ := http.NewRequest("POST", path, strings.NewReader("{}"))
req.Header.Add("Origin", srv.URL)
resp, err := http.DefaultClient.Do(req)
assert.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, srv.URL, resp.Header.Get("Access-Control-Allow-Origin"), "CORS Allow-Origin not set")
}
func TestAnalyzeGetNotFound(t *testing.T) {
setupServer()
defer teardownServer()
path := srv.URL + "/registry/analyze"
req, _ := http.NewRequest("GET", path, nil)
resp, _ := http.DefaultClient.Do(req)
assert.Equal(t, 404, resp.StatusCode)
}
func TestStatusPostNotFound(t *testing.T) {
setupServer()
defer teardownServer()
path := srv.URL + "/registry/status"
req, _ := http.NewRequest("POST", path, strings.NewReader("{}"))
resp, _ := http.DefaultClient.Do(req)
assert.Equal(t, 404, resp.StatusCode)
}
func TestBadURL(t *testing.T) {
setupServer()
defer teardownServer()
path := srv.URL + "/registry/foo"
req, _ := http.NewRequest("GET", path, nil)
resp, _ := http.DefaultClient.Do(req)
assert.Equal(t, 404, resp.StatusCode)
}