test: improve integration test error reporting for library creation
- Add explicit status code check (require.Equal 201) - Remove conditional success/failure branching - Provide clear error message with actual vs expected status Now if CreateLibrary returns 500, test will clearly show: "Failed to create library: expected 201, got 500" Instead of vague "Library ID is empty" message that hid the 500 error.
This commit is contained in:
@@ -285,16 +285,14 @@ func setupTestSuite(t *testing.T) *TestContext {
|
||||
resp = makeRequest(t, "POST", "/api/libraries", libReq, ctx.AdminToken)
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusCreated || resp.StatusCode == http.StatusOK {
|
||||
var lib map[string]interface{}
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
err := json.Unmarshal(body, &lib)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode, "Failed to create library")
|
||||
|
||||
ctx.LibraryID = lib["id"].(string)
|
||||
t.Logf("Created new library: %v", lib["name"])
|
||||
}
|
||||
var lib map[string]interface{}
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
err := json.Unmarshal(body, &lib)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx.LibraryID = lib["id"].(string)
|
||||
require.NotEmpty(t, ctx.LibraryID, "Library ID is empty")
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user