-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapps_test.go
156 lines (124 loc) · 4.49 KB
/
apps_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
package main
import (
"context"
"testing"
"github.com/Microkubes/microservice-apps-management/app"
"github.com/Microkubes/microservice-apps-management/app/test"
"github.com/Microkubes/microservice-apps-management/db"
"github.com/Microkubes/microservice-security/auth"
"github.com/keitaroinc/goa"
)
var (
service = goa.New("apps-test")
database = db.New()
ctrl = NewAppsController(service, database)
ID = "5975c461f9f8eb02aae053f3"
notFoundID = "rrr5c461f9f8eb02aae05zzz"
badReqID = "bad-request-error"
errInternalID = "internal-error"
name = "app-name"
desc = "Some description"
domain = "example.com"
)
var client = &app.AppPayload{
Name: name,
Description: &desc,
Domain: &domain,
}
var ctx = context.Background()
// Call generated test helper, this checks that the returned media type is of the
// correct type (i.e. uses view "default") and validates the media type.
// Also, it ckecks the returned status code
func TestGetAppsOK(t *testing.T) {
_, clientApp := test.GetAppsOK(t, ctx, service, ctrl, ID)
if clientApp == nil {
t.Fatal("Nil client app")
}
if clientApp.Name != name {
t.Errorf("Invalid app name, expected %s, got %s", name, clientApp.Name)
}
}
func TestGetAppsNotFound(t *testing.T) {
test.GetAppsNotFound(t, ctx, service, ctrl, notFoundID)
}
func TestGetAppsInternalServerError(t *testing.T) {
test.GetAppsInternalServerError(t, ctx, service, ctrl, errInternalID)
}
func TestGetAppsBadRequest(t *testing.T) {
test.GetAppsBadRequest(t, ctx, service, ctrl, badReqID)
}
func TestGetMyAppsAppsOK(t *testing.T) {
authObj := &auth.Auth{UserID: ID}
ctx = auth.SetAuth(ctx, authObj)
test.GetMyAppsAppsOK(t, ctx, service, ctrl)
}
func TestGetMyAppsAppsNotFound(t *testing.T) {
authObj := &auth.Auth{UserID: notFoundID}
ctx = auth.SetAuth(ctx, authObj)
test.GetMyAppsAppsNotFound(t, ctx, service, ctrl)
}
func TestGetMyAppsAppsInternalServerError(t *testing.T) {
authObj := &auth.Auth{UserID: errInternalID}
ctx = auth.SetAuth(ctx, authObj)
test.GetMyAppsAppsInternalServerError(t, ctx, service, ctrl)
}
func TestGetUserAppsAppsOK(t *testing.T) {
test.GetUserAppsAppsOK(t, ctx, service, ctrl, ID)
}
func TestGetUserAppsAppsNotFound(t *testing.T) {
test.GetUserAppsAppsNotFound(t, ctx, service, ctrl, notFoundID)
}
func TestGetUserAppsAppsInternalServerError(t *testing.T) {
test.GetUserAppsAppsInternalServerError(t, ctx, service, ctrl, errInternalID)
}
func TestRegisterAppAppsCreated(t *testing.T) {
authObj := &auth.Auth{UserID: ID}
ctx = auth.SetAuth(ctx, authObj)
test.RegisterAppAppsCreated(t, ctx, service, ctrl, client)
}
func TestRegisterAppAppsBadRequest(t *testing.T) {
authObj := &auth.Auth{UserID: badReqID}
ctx = auth.SetAuth(ctx, authObj)
test.RegisterAppAppsBadRequest(t, ctx, service, ctrl, client)
}
func TestRegisterAppAppsInternalServerError(t *testing.T) {
authObj := &auth.Auth{UserID: errInternalID}
ctx = auth.SetAuth(ctx, authObj)
test.RegisterAppAppsInternalServerError(t, ctx, service, ctrl, client)
}
func TestUpdateAppAppsOK(t *testing.T) {
test.UpdateAppAppsOK(t, ctx, service, ctrl, ID, client)
}
func TestUpdateAppAppsNotFound(t *testing.T) {
test.UpdateAppAppsNotFound(t, ctx, service, ctrl, notFoundID, client)
}
func TestUpdateAppAppsInternalServerError(t *testing.T) {
test.UpdateAppAppsInternalServerError(t, ctx, service, ctrl, errInternalID, client)
}
func TestUpdateAppAppsBadRequest(t *testing.T) {
test.UpdateAppAppsBadRequest(t, ctx, service, ctrl, badReqID, client)
}
func TestRegenerateClientSecretAppsOK(t *testing.T) {
test.RegenerateClientSecretAppsOK(t, ctx, service, ctrl, ID)
}
func TestRegenerateClientSecretAppsNotFound(t *testing.T) {
test.RegenerateClientSecretAppsNotFound(t, ctx, service, ctrl, notFoundID)
}
func TestRegenerateClientSecretAppsInternalServerError(t *testing.T) {
test.RegenerateClientSecretAppsInternalServerError(t, ctx, service, ctrl, errInternalID)
}
func TestRegenerateClientSecretAppsBadRequest(t *testing.T) {
test.RegenerateClientSecretAppsBadRequest(t, ctx, service, ctrl, badReqID)
}
func TestDeleteAppAppsOK(t *testing.T) {
test.DeleteAppAppsOK(t, ctx, service, ctrl, ID)
}
func TestDeleteAppAppsNotFound(t *testing.T) {
test.DeleteAppAppsNotFound(t, ctx, service, ctrl, notFoundID)
}
func TestDeleteAppAppsInternalServerError(t *testing.T) {
test.DeleteAppAppsInternalServerError(t, ctx, service, ctrl, errInternalID)
}
func TestDeleteAppAppsBadRequest(t *testing.T) {
test.DeleteAppAppsBadRequest(t, ctx, service, ctrl, badReqID)
}