|
1 | 1 | package client |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "encoding/json" |
6 | 5 | "fmt" |
7 | 6 | "net/http" |
@@ -331,20 +330,33 @@ func TestNGTSClient_PostDataReadingsWithOptions(t *testing.T) { |
331 | 330 | ClusterDescription: "Test cluster description", |
332 | 331 | } |
333 | 332 |
|
334 | | - err = client.PostDataReadingsWithOptions(context.Background(), readings, opts) |
| 333 | + err = client.PostDataReadingsWithOptions(t.Context(), readings, opts) |
335 | 334 | require.NoError(t, err) |
336 | 335 |
|
337 | 336 | // Verify the upload request |
338 | 337 | assert.NotNil(t, receivedRequest) |
339 | 338 | assert.Equal(t, "/"+ngtsUploadEndpoint, receivedRequest.URL.Path) |
340 | 339 | assert.Contains(t, receivedRequest.URL.RawQuery, "name=test-cluster") |
341 | 340 | assert.Equal(t, "Bearer test-access-token", receivedRequest.Header.Get("Authorization")) |
| 341 | + // certOwnership not set — must NOT appear in query |
| 342 | + assert.NotContains(t, receivedRequest.URL.RawQuery, "certOwnership") |
342 | 343 |
|
343 | 344 | // Verify the payload |
344 | 345 | var payload api.DataReadingsPost |
345 | 346 | err = json.Unmarshal(receivedBody, &payload) |
346 | 347 | require.NoError(t, err) |
347 | 348 | assert.Equal(t, 1, len(payload.DataReadings)) |
| 349 | + |
| 350 | + // Verify claimableCerts=true is included when set |
| 351 | + t.Run("claimableCerts: true sends certOwnership=unassigned to backend", func(t *testing.T) { |
| 352 | + optsUnassigned := Options{ |
| 353 | + ClusterName: "test-cluster", |
| 354 | + ClaimableCerts: true, |
| 355 | + } |
| 356 | + err = client.PostDataReadingsWithOptions(t.Context(), readings, optsUnassigned) |
| 357 | + require.NoError(t, err) |
| 358 | + assert.Contains(t, receivedRequest.URL.RawQuery, "certOwnership=unassigned") |
| 359 | + }) |
348 | 360 | } |
349 | 361 |
|
350 | 362 | func TestNGTSClient_AuthenticationFlow(t *testing.T) { |
@@ -384,7 +396,7 @@ func TestNGTSClient_AuthenticationFlow(t *testing.T) { |
384 | 396 | opts := Options{ClusterName: "test"} |
385 | 397 |
|
386 | 398 | for range 3 { |
387 | | - err = client.PostDataReadingsWithOptions(context.Background(), readings, opts) |
| 399 | + err = client.PostDataReadingsWithOptions(t.Context(), readings, opts) |
388 | 400 | require.NoError(t, err) |
389 | 401 | } |
390 | 402 |
|
@@ -448,7 +460,7 @@ func TestNGTSClient_ErrorHandling(t *testing.T) { |
448 | 460 | readings := []*api.DataReading{{DataGatherer: "test", Data: &api.DynamicData{}}} |
449 | 461 | opts := Options{ClusterName: "test"} |
450 | 462 |
|
451 | | - err = client.PostDataReadingsWithOptions(context.Background(), readings, opts) |
| 463 | + err = client.PostDataReadingsWithOptions(t.Context(), readings, opts) |
452 | 464 | require.Error(t, err) |
453 | 465 | assert.Contains(t, err.Error(), tt.expectedErrMsg) |
454 | 466 | }) |
|
0 commit comments