Skip to content

Commit

Permalink
azure/group: when deleting group, consider 404 success
Browse files Browse the repository at this point in the history
Co-authored-by: Christer Edvartsen <[email protected]>
  • Loading branch information
thokra-nav and christeredvartsen committed Jul 2, 2024
1 parent 964c02e commit 3642761
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/azureclient/azureclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ func (s *client) DeleteGroup(ctx context.Context, grpID uuid.UUID) error {
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusNotFound {
return nil
}

if resp.StatusCode != http.StatusNoContent {
body, _ := io.ReadAll(resp.Body)
return fmt.Errorf("remove azure group with ID: %q: %q: %q", grpID, resp.Status, string(body))
Expand Down
14 changes: 14 additions & 0 deletions internal/azureclient/azureclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,18 @@ func Test_DeleteGroup(t *testing.T) {
t.Errorf("Expected error to contain %q, got %q", contains, err)
}
})

t.Run("404 is considered OK", func(t *testing.T) {
httpClient := test.NewTestHttpClient(
func(req *http.Request) *http.Response {
return test.Response("404 Not Found", "{}")
},
)

client := azureclient.New(httpClient)
err := client.DeleteGroup(ctx, grpID)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
})
}
2 changes: 1 addition & 1 deletion internal/reconcilers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (m *Manager) ListenForEvents(ctx context.Context) {
if err == nil || errors.Is(err, context.Canceled) {
// Receive will return nil error when canceled
return
} else if err != nil {
} else {
m.log.WithError(err).Error("error while receiving pubsub message")
}

Expand Down

0 comments on commit 3642761

Please sign in to comment.