|
@@ -47,6 +47,7 @@ func TestHandler_GetProvisioner(t *testing.T) {
|
|
|
ctx: ctx,
|
|
ctx: ctx,
|
|
|
req: req,
|
|
req: req,
|
|
|
auth: auth,
|
|
auth: auth,
|
|
|
|
|
+ adminDB: &admin.MockDB{},
|
|
|
statusCode: 500,
|
|
statusCode: 500,
|
|
|
err: &admin.Error{
|
|
err: &admin.Error{
|
|
|
Type: admin.ErrorServerInternalType.String(),
|
|
Type: admin.ErrorServerInternalType.String(),
|
|
@@ -71,6 +72,7 @@ func TestHandler_GetProvisioner(t *testing.T) {
|
|
|
ctx: ctx,
|
|
ctx: ctx,
|
|
|
req: req,
|
|
req: req,
|
|
|
auth: auth,
|
|
auth: auth,
|
|
|
|
|
+ adminDB: &admin.MockDB{},
|
|
|
statusCode: 500,
|
|
statusCode: 500,
|
|
|
err: &admin.Error{
|
|
err: &admin.Error{
|
|
|
Type: admin.ErrorServerInternalType.String(),
|
|
Type: admin.ErrorServerInternalType.String(),
|
|
@@ -153,13 +155,11 @@ func TestHandler_GetProvisioner(t *testing.T) {
|
|
|
for name, prep := range tests {
|
|
for name, prep := range tests {
|
|
|
tc := prep(t)
|
|
tc := prep(t)
|
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Run(name, func(t *testing.T) {
|
|
|
- h := &Handler{
|
|
|
|
|
- auth: tc.auth,
|
|
|
|
|
- adminDB: tc.adminDB,
|
|
|
|
|
- }
|
|
|
|
|
- req := tc.req.WithContext(tc.ctx)
|
|
|
|
|
|
|
+ mockMustAuthority(t, tc.auth)
|
|
|
|
|
+ ctx := admin.NewContext(tc.ctx, tc.adminDB)
|
|
|
|
|
+ req := tc.req.WithContext(ctx)
|
|
|
w := httptest.NewRecorder()
|
|
w := httptest.NewRecorder()
|
|
|
- h.GetProvisioner(w, req)
|
|
|
|
|
|
|
+ GetProvisioner(w, req)
|
|
|
res := w.Result()
|
|
res := w.Result()
|
|
|
|
|
|
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
@@ -277,12 +277,10 @@ func TestHandler_GetProvisioners(t *testing.T) {
|
|
|
for name, prep := range tests {
|
|
for name, prep := range tests {
|
|
|
tc := prep(t)
|
|
tc := prep(t)
|
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Run(name, func(t *testing.T) {
|
|
|
- h := &Handler{
|
|
|
|
|
- auth: tc.auth,
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ mockMustAuthority(t, tc.auth)
|
|
|
req := tc.req.WithContext(tc.ctx)
|
|
req := tc.req.WithContext(tc.ctx)
|
|
|
w := httptest.NewRecorder()
|
|
w := httptest.NewRecorder()
|
|
|
- h.GetProvisioners(w, req)
|
|
|
|
|
|
|
+ GetProvisioners(w, req)
|
|
|
res := w.Result()
|
|
res := w.Result()
|
|
|
|
|
|
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
@@ -402,13 +400,11 @@ func TestHandler_CreateProvisioner(t *testing.T) {
|
|
|
for name, prep := range tests {
|
|
for name, prep := range tests {
|
|
|
tc := prep(t)
|
|
tc := prep(t)
|
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Run(name, func(t *testing.T) {
|
|
|
- h := &Handler{
|
|
|
|
|
- auth: tc.auth,
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ mockMustAuthority(t, tc.auth)
|
|
|
req := httptest.NewRequest("POST", "/foo", io.NopCloser(bytes.NewBuffer(tc.body)))
|
|
req := httptest.NewRequest("POST", "/foo", io.NopCloser(bytes.NewBuffer(tc.body)))
|
|
|
req = req.WithContext(tc.ctx)
|
|
req = req.WithContext(tc.ctx)
|
|
|
w := httptest.NewRecorder()
|
|
w := httptest.NewRecorder()
|
|
|
- h.CreateProvisioner(w, req)
|
|
|
|
|
|
|
+ CreateProvisioner(w, req)
|
|
|
res := w.Result()
|
|
res := w.Result()
|
|
|
|
|
|
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
@@ -562,12 +558,10 @@ func TestHandler_DeleteProvisioner(t *testing.T) {
|
|
|
for name, prep := range tests {
|
|
for name, prep := range tests {
|
|
|
tc := prep(t)
|
|
tc := prep(t)
|
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Run(name, func(t *testing.T) {
|
|
|
- h := &Handler{
|
|
|
|
|
- auth: tc.auth,
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ mockMustAuthority(t, tc.auth)
|
|
|
req := tc.req.WithContext(tc.ctx)
|
|
req := tc.req.WithContext(tc.ctx)
|
|
|
w := httptest.NewRecorder()
|
|
w := httptest.NewRecorder()
|
|
|
- h.DeleteProvisioner(w, req)
|
|
|
|
|
|
|
+ DeleteProvisioner(w, req)
|
|
|
res := w.Result()
|
|
res := w.Result()
|
|
|
|
|
|
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
@@ -616,6 +610,7 @@ func TestHandler_UpdateProvisioner(t *testing.T) {
|
|
|
return test{
|
|
return test{
|
|
|
ctx: context.Background(),
|
|
ctx: context.Background(),
|
|
|
body: body,
|
|
body: body,
|
|
|
|
|
+ adminDB: &admin.MockDB{},
|
|
|
statusCode: 500,
|
|
statusCode: 500,
|
|
|
err: &admin.Error{ // TODO(hs): this probably needs a better error
|
|
err: &admin.Error{ // TODO(hs): this probably needs a better error
|
|
|
Type: "",
|
|
Type: "",
|
|
@@ -645,6 +640,7 @@ func TestHandler_UpdateProvisioner(t *testing.T) {
|
|
|
return test{
|
|
return test{
|
|
|
ctx: ctx,
|
|
ctx: ctx,
|
|
|
body: body,
|
|
body: body,
|
|
|
|
|
+ adminDB: &admin.MockDB{},
|
|
|
auth: auth,
|
|
auth: auth,
|
|
|
statusCode: 500,
|
|
statusCode: 500,
|
|
|
err: &admin.Error{
|
|
err: &admin.Error{
|
|
@@ -1052,14 +1048,12 @@ func TestHandler_UpdateProvisioner(t *testing.T) {
|
|
|
for name, prep := range tests {
|
|
for name, prep := range tests {
|
|
|
tc := prep(t)
|
|
tc := prep(t)
|
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Run(name, func(t *testing.T) {
|
|
|
- h := &Handler{
|
|
|
|
|
- auth: tc.auth,
|
|
|
|
|
- adminDB: tc.adminDB,
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ mockMustAuthority(t, tc.auth)
|
|
|
|
|
+ ctx := admin.NewContext(tc.ctx, tc.adminDB)
|
|
|
req := httptest.NewRequest("POST", "/foo", io.NopCloser(bytes.NewBuffer(tc.body)))
|
|
req := httptest.NewRequest("POST", "/foo", io.NopCloser(bytes.NewBuffer(tc.body)))
|
|
|
- req = req.WithContext(tc.ctx)
|
|
|
|
|
|
|
+ req = req.WithContext(ctx)
|
|
|
w := httptest.NewRecorder()
|
|
w := httptest.NewRecorder()
|
|
|
- h.UpdateProvisioner(w, req)
|
|
|
|
|
|
|
+ UpdateProvisioner(w, req)
|
|
|
res := w.Result()
|
|
res := w.Result()
|
|
|
|
|
|
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|
|
assert.Equals(t, tc.statusCode, res.StatusCode)
|