Skip to content

Commit c7f4fbf

Browse files
committed
test: add httptest-based API client tests + fix revoked session detection
- Add 20 tests in pkg/api/client_test.go covering: - GetQuote: promo applied, no promo, invalid promo rejected (400), promo field present in request body - ListPlans: filters disabled + out-of-stock, empty results - ListRegions: filters out-of-stock - ListTemplates: returns all - CreateDeployOrder: promo sent in body, promo omitted when empty (omitempty) - Auth: 401 expired vs 401 revoked distinction - GetDefaultPaymentMethod: returns default, returns nil when none set - GetInstance: wrapped {instance:{}} format and direct {} format - GetDefaultAPIURL: https accepted, http/invalid/missing-host rejected - Fix production bug: 401 revoked detection never worked because the inline struct used Code string but ErrorResponse encodes Code as int, causing json.Unmarshal to fail silently and always fall through to ErrTokenExpired. Fix: drop the Code field from the inline struct (only Detail is needed). - Add auth.ResetDefaultStore() for test isolation
1 parent b480920 commit c7f4fbf

3 files changed

Lines changed: 553 additions & 1 deletion

File tree

pkg/api/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func (c *Client) doRequest(method, path string, body interface{}) (*http.Respons
104104
resp.Body.Close()
105105
var errResp struct {
106106
Detail string `json:"detail"`
107-
Code string `json:"code"`
108107
}
109108
if json.Unmarshal(body, &errResp) == nil {
110109
if strings.Contains(errResp.Detail, "revoked") {

0 commit comments

Comments
 (0)