-
Notifications
You must be signed in to change notification settings - Fork 3
/
applications_test.go
60 lines (50 loc) · 1.48 KB
/
applications_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
package solus
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestApplicationsService_List(t *testing.T) {
expected := ApplicationsResponse{
Data: []Application{
fakeApplication,
},
}
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/applications", r.URL.Path)
assert.Equal(t, http.MethodGet, r.Method)
writeJSON(t, w, http.StatusOK, expected)
})
defer s.Close()
actual, err := createTestClient(t, s.URL).Applications.List(context.Background())
require.NoError(t, err)
actual.service = nil
require.Equal(t, expected, actual)
}
func TestApplicationsService_Create(t *testing.T) {
data := ApplicationCreateRequest{
Name: "name",
URL: "url",
IconID: 1,
CloudInitVersion: "cloud init version",
UserDataTemplate: "user data template",
JSONSchema: "json schema",
IsVisible: true,
LoginLink: LoginLink{
Type: LoginLinkTypeURL,
Content: "login link content",
},
}
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/applications", r.URL.Path)
assert.Equal(t, http.MethodPost, r.Method)
assertRequestBody(t, r, data)
writeResponse(t, w, http.StatusCreated, fakeApplication)
})
defer s.Close()
actual, err := createTestClient(t, s.URL).Applications.Create(context.Background(), data)
require.NoError(t, err)
require.Equal(t, fakeApplication, actual)
}