Skip to content

Commit 2fdf2df

Browse files
committed
test: minor test fixes
1 parent d52690e commit 2fdf2df

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

app/api/nodeodm_api_test.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http/httptest"
99
"testing"
1010

11+
"github.com/hotosm/scaleodm/app/config"
1112
"github.com/hotosm/scaleodm/app/meta"
1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
@@ -82,9 +83,10 @@ func TestTaskNewEndpoint(t *testing.T) {
8283

8384
_, handler := NewAPI(metadataStore, wfClient)
8485

85-
// Initialize cluster
86+
// Initialize cluster with the same URL that the API will use
8687
ctx := context.Background()
87-
err := db.InitLocalClusterRecord(ctx, "http://localhost:31100")
88+
clusterURL := config.SCALEODM_CLUSTER_URL
89+
err := db.InitLocalClusterRecord(ctx, clusterURL)
8890
require.NoError(t, err)
8991

9092
// Create task request
@@ -156,13 +158,14 @@ func TestTaskInfoEndpoint(t *testing.T) {
156158

157159
// Create job metadata (workflow may or may not exist in cluster)
158160
ctx := context.Background()
159-
err := db.InitLocalClusterRecord(ctx, "http://localhost:31100")
161+
clusterURL := config.SCALEODM_CLUSTER_URL
162+
err := db.InitLocalClusterRecord(ctx, clusterURL)
160163
require.NoError(t, err)
161164

162165
workflowName := "test-workflow-info"
163166
_, err = metadataStore.CreateJob(
164167
ctx,
165-
"http://localhost:31100",
168+
clusterURL,
166169
workflowName,
167170
"test-project",
168171
"s3://bucket/images/",
@@ -182,10 +185,17 @@ func TestTaskInfoEndpoint(t *testing.T) {
182185
// Should return OK even if workflow doesn't exist in cluster (metadata exists)
183186
assert.Equal(t, http.StatusOK, w.Code)
184187

185-
// Huma returns the body content directly, not wrapped in a Body field
188+
// Huma may return the body wrapped in a Body field or directly
186189
var response TaskInfo
187-
err = json.Unmarshal(w.Body.Bytes(), &response)
188-
require.NoError(t, err)
190+
var wrappedResponse TaskInfoResponse
191+
err = json.Unmarshal(w.Body.Bytes(), &wrappedResponse)
192+
if err == nil && wrappedResponse.Body.UUID != "" {
193+
response = wrappedResponse.Body
194+
} else {
195+
// Try direct unmarshaling
196+
err = json.Unmarshal(w.Body.Bytes(), &response)
197+
require.NoError(t, err)
198+
}
189199
assert.Equal(t, workflowName, response.UUID)
190200
}
191201

app/meta/cluster_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,27 @@ func TestGetClusterCapacity(t *testing.T) {
8989
store := NewStore(db)
9090
ctx := context.Background()
9191

92+
// Use a consistent cluster URL for the test
93+
clusterURL := "http://localhost:31100"
94+
9295
// Initialize cluster with max 10 jobs
93-
err := db.InitLocalClusterRecord(ctx, "http://localhost:31100")
96+
err := db.InitLocalClusterRecord(ctx, clusterURL)
9497
require.NoError(t, err)
9598

9699
// Update cluster details
97-
err = store.UpdateClusterDetails(ctx, "http://localhost:31100", 10, 10)
100+
err = store.UpdateClusterDetails(ctx, clusterURL, 10, 10)
98101
require.NoError(t, err)
99102

100103
// Get capacity (should be 0 active jobs)
101-
maxJobs, activeJobs, err := store.GetClusterCapacity(ctx, "http://localhost:31100")
104+
maxJobs, activeJobs, err := store.GetClusterCapacity(ctx, clusterURL)
102105
require.NoError(t, err)
103106
assert.Equal(t, 10, maxJobs)
104107
assert.Equal(t, 0, activeJobs)
105108

106109
// Create some running jobs
107110
_, err = store.CreateJob(
108111
ctx,
109-
"http://localhost:31100",
112+
clusterURL,
110113
"test-workflow-1",
111114
"test-project",
112115
"s3://bucket/images/",
@@ -121,7 +124,7 @@ func TestGetClusterCapacity(t *testing.T) {
121124

122125
_, err = store.CreateJob(
123126
ctx,
124-
"http://localhost:31100",
127+
clusterURL,
125128
"test-workflow-2",
126129
"test-project",
127130
"s3://bucket/images/",
@@ -135,15 +138,15 @@ func TestGetClusterCapacity(t *testing.T) {
135138
require.NoError(t, err)
136139

137140
// Get capacity again (should be 2 active jobs)
138-
maxJobs, activeJobs, err = store.GetClusterCapacity(ctx, "http://localhost:31100")
141+
maxJobs, activeJobs, err = store.GetClusterCapacity(ctx, clusterURL)
139142
require.NoError(t, err)
140143
assert.Equal(t, 10, maxJobs)
141144
assert.Equal(t, 2, activeJobs)
142145

143146
// Create a completed job (should not count)
144147
_, err = store.CreateJob(
145148
ctx,
146-
"http://localhost:31100",
149+
clusterURL,
147150
"test-workflow-3",
148151
"test-project",
149152
"s3://bucket/images/",
@@ -157,7 +160,7 @@ func TestGetClusterCapacity(t *testing.T) {
157160
require.NoError(t, err)
158161

159162
// Get capacity again (should still be 2 active jobs)
160-
maxJobs, activeJobs, err = store.GetClusterCapacity(ctx, "http://localhost:31100")
163+
maxJobs, activeJobs, err = store.GetClusterCapacity(ctx, clusterURL)
161164
require.NoError(t, err)
162165
assert.Equal(t, 10, maxJobs)
163166
assert.Equal(t, 2, activeJobs)

0 commit comments

Comments
 (0)