Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions internal/scheduling/reservations/commitments/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package commitments

import (
"context"
"encoding/json"
"fmt"
"net/http"
gosync "sync"
"time"
Expand Down Expand Up @@ -173,26 +171,21 @@ func (c *commitmentsClient) listCommitments(ctx context.Context, project Project
"/domains/" + project.DomainID +
"/projects/" + project.ID +
"/commitments"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
if err != nil {
return nil, err
}
req.Header.Set("X-Auth-Token", c.limes.Token())
resp, err := c.limes.HTTPClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

// Use gophercloud's Get method which handles re-authentication automatically
var list struct {
Commitments []Commitment `json:"commitments"`
}
err = json.NewDecoder(resp.Body).Decode(&list)
resp, err := c.limes.Get(ctx, url, &list, &gophercloud.RequestOpts{
OkCodes: []int{http.StatusOK},
})
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return nil, err
}

// Add the project information to each commitment.
var commitments []Commitment
for _, c := range list.Commitments {
Expand Down
6 changes: 3 additions & 3 deletions internal/scheduling/reservations/commitments/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ func TestCommitmentsClient_listCommitments_HTTPError(t *testing.T) {
t.Errorf("expected nil commitments, got %+v", commitments)
}

expectedError := "unexpected status code: 404"
if err.Error() != expectedError {
t.Errorf("expected error %q, got %q", expectedError, err.Error())
// Gophercloud returns a more detailed error message
if !strings.Contains(err.Error(), "404") {
t.Errorf("expected error to contain '404', got %q", err.Error())
}
}

Expand Down
Loading