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:
2026-01-29 21:16:35 -05:00
parent ff44115be2
commit ea7abd7476
+6 -8
View File
@@ -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")
})