forked from tildetown/bbj2
		
	bad method test
This commit is contained in:
		
							parent
							
								
									89de893bf9
								
							
						
					
					
						commit
						db5f52f1fb
					
				| @ -106,6 +106,7 @@ func TestInstanceInfo(t *testing.T) { | ||||
| 
 | ||||
| 	ts := []struct { | ||||
| 		name     string | ||||
| 		req      func() *http.Request | ||||
| 		wantData instanceInfo | ||||
| 		wantErr  *HTTPError | ||||
| 	}{ | ||||
| @ -117,19 +118,43 @@ func TestInstanceInfo(t *testing.T) { | ||||
| 				Admins:       []string{"jillValentine", "rebeccaChambers"}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "bad method", | ||||
| 			req: func() *http.Request { | ||||
| 				r, _ := http.NewRequest("POST", "", strings.NewReader("")) | ||||
| 				return r | ||||
| 			}, | ||||
| 			wantErr: &HTTPError{ | ||||
| 				Msg:  "bad method", | ||||
| 				Code: 400, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	for _, tt := range ts { | ||||
| 		t.Run(tt.name, func(t *testing.T) { | ||||
| 			req, _ := http.NewRequest("GET", "", strings.NewReader("")) | ||||
| 			var req *http.Request | ||||
| 			if tt.req == nil { | ||||
| 				req, _ = http.NewRequest("GET", "", strings.NewReader("")) | ||||
| 			} else { | ||||
| 				req = tt.req() | ||||
| 			} | ||||
| 			api := &API{ | ||||
| 				Opts: *opts, | ||||
| 			} | ||||
| 			ctx := &ReqCtx{Req: req} | ||||
| 			resp, err := api.InstanceInfo(ctx) | ||||
| 			if tt.wantErr != nil && err != nil { | ||||
| 				t.Errorf("got unwanted error: %s", err.Error()) | ||||
| 				if !reflect.DeepEqual(tt.wantErr, err) { | ||||
| 					t.Errorf("got unwanted error: %s", err.Error()) | ||||
| 				} | ||||
| 				return | ||||
| 			} | ||||
| 
 | ||||
| 			if tt.wantErr != nil && err == nil { | ||||
| 				t.Errorf("expected error") | ||||
| 				return | ||||
| 			} | ||||
| 
 | ||||
| 			ii, ok := resp.Data.(instanceInfo) | ||||
| 			if !ok { | ||||
| 				t.Errorf("could not cast data in %s", tt.name) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user