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)
|
resp = makeRequest(t, "POST", "/api/libraries", libReq, ctx.AdminToken)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusCreated || resp.StatusCode == http.StatusOK {
|
require.Equal(t, http.StatusCreated, resp.StatusCode, "Failed to create library")
|
||||||
var lib map[string]interface{}
|
|
||||||
body, _ := io.ReadAll(resp.Body)
|
|
||||||
err := json.Unmarshal(body, &lib)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
ctx.LibraryID = lib["id"].(string)
|
var lib map[string]interface{}
|
||||||
t.Logf("Created new library: %v", lib["name"])
|
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")
|
require.NotEmpty(t, ctx.LibraryID, "Library ID is empty")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user