Skip to content

Commit

Permalink
Refactor test checks.
Browse files Browse the repository at this point in the history
Clearly check either the error case or the successful result case.
  • Loading branch information
gigerdo committed Sep 10, 2024
1 parent 5f5f60d commit 4ceec3a
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 50 deletions.
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ func TestGetOrganization(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := Get(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if !assert.Equal(t, test.want, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/invitation_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ func TestCreateInvitation(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := CreateInvitation(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if !assert.Equal(t, test.want, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/invitation_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ func TestDeleteInvitation(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := DeleteInvitation(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if err == nil && !assert.NotNil(t, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.NotNil(t, got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/invitation_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ func TestListInvitations(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := ListInvitations(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if !assert.Equal(t, test.want, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ func TestListOrganization(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := List(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if !assert.Equal(t, test.want, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/member_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ func TestDeleteMember(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := DeleteMember(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if err == nil && !assert.NotNil(t, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.NotNil(t, got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/member_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ func TestListMembers(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := ListMembers(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if !assert.Equal(t, test.want, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/member_role_assignments_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func TestAddRoleAssignments(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := AddRoleAssignments(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if got != nil && !assert.Equal(t, test.want, *got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, *got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/member_role_assignments_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func TestRemoveRoleAssignments(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := RemoveRoleAssignments(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if got != nil && !assert.Equal(t, test.want, *got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, *got)
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/organizationapi/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ func TestUpdateOrganization(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := Update(test.params)
if err != nil && !assert.EqualError(t, err, test.err) {
t.Error(err)
}
if !assert.Equal(t, test.want, got) {
t.Error(err)
if test.err != "" {
assert.EqualError(t, err, test.err)
assert.Nil(t, got)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, got)
}
})
}
Expand Down

0 comments on commit 4ceec3a

Please sign in to comment.