mirror of
				https://github.com/interviewstreet/go-jira.git
				synced 2025-10-30 23:47:46 +02:00 
			
		
		
		
	Add negative tests for RoleService
This commit is contained in:
		
				
					committed by
					
						 Wes McNamee
						Wes McNamee
					
				
			
			
				
	
			
			
			
						parent
						
							0f45703c19
						
					
				
				
					commit
					f4bc07d375
				
			
							
								
								
									
										8
									
								
								mocks/no_role.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								mocks/no_role.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| { | ||||
|     "errorMessages": [ | ||||
|       "Role with given id not found." | ||||
|     ], | ||||
|     "errors": { | ||||
|      | ||||
|     } | ||||
| } | ||||
							
								
								
									
										0
									
								
								mocks/no_roles.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								mocks/no_roles.json
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										52
									
								
								role_test.go
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								role_test.go
									
									
									
									
									
								
							| @@ -7,6 +7,31 @@ import ( | ||||
| 	"testing" | ||||
| ) | ||||
|  | ||||
| func TestRoleService_GetList_NoList(t *testing.T) { | ||||
| 	setup() | ||||
| 	defer teardown() | ||||
| 	testAPIEndpoint := "/rest/api/3/role" | ||||
|  | ||||
| 	raw, err := ioutil.ReadFile("./mocks/no_roles.json") | ||||
| 	if err != nil { | ||||
| 		t.Error(err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) { | ||||
| 		testMethod(t, r, "GET") | ||||
| 		testRequestURL(t, r, testAPIEndpoint) | ||||
| 		fmt.Fprintf(w, string(raw)) | ||||
| 	}) | ||||
|  | ||||
| 	roles, _, err := testClient.Role.GetList() | ||||
| 	if roles != nil { | ||||
| 		t.Errorf("Expected role list has %d entries but should be nil", len(*roles)) | ||||
| 	} | ||||
| 	if err == nil { | ||||
| 		t.Errorf("No error given") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestRoleService_GetList(t *testing.T) { | ||||
| 	setup() | ||||
| 	defer teardown() | ||||
| @@ -26,11 +51,37 @@ func TestRoleService_GetList(t *testing.T) { | ||||
| 	if roles == nil { | ||||
| 		t.Error("Expected role list. Role list is nil") | ||||
| 	} | ||||
| 	if len(*roles) != 2 { | ||||
| 		t.Errorf("Expected %d roles but got %d", 2, len(*roles)) | ||||
| 	} | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Error given: %v", err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestRoleService_Get_NoRole(t *testing.T) { | ||||
| 	setup() | ||||
| 	defer teardown() | ||||
| 	testAPIEdpoint := "/rest/api/3/role/99999" | ||||
| 	raw, err := ioutil.ReadFile("./mocks/no_role.json") | ||||
| 	if err != nil { | ||||
| 		t.Error(err.Error()) | ||||
| 	} | ||||
| 	testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) { | ||||
| 		testMethod(t, request, "GET") | ||||
| 		testRequestURL(t, request, testAPIEdpoint) | ||||
| 		fmt.Fprintf(writer, string(raw)) | ||||
| 	}) | ||||
|  | ||||
| 	role, _, err := testClient.Role.Get(99999) | ||||
| 	if role != nil { | ||||
| 		t.Errorf("Expected nil, got role %v", role) | ||||
| 	} | ||||
| 	if err == nil { | ||||
| 		t.Errorf("No error given") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestRoleService_Get(t *testing.T) { | ||||
| 	setup() | ||||
| 	defer teardown() | ||||
| @@ -52,5 +103,4 @@ func TestRoleService_Get(t *testing.T) { | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Error given: %s", err) | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user