Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ForceReconcile, add unit and e2e tests #1338

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,22 @@ var _ = Describe("Central", func() {
Expect(secretsStored).Should(ContainElements(expectedSecrets))
})

It("should set ForceReconcile through admin API", func() {
if createdCentral == nil {
Fail("central not created")
}

_, _, err := adminAPI.UpdateCentralById(
context.Background(),
createdCentral.Id,
private.CentralUpdateRequest{ForceReconcile: "true"})

Expect(err).To(BeNil())

privateCentral, _, err := client.PrivateAPI().GetCentral(context.Background(), createdCentral.Id)
Expect(err).To(BeNil())
Expect(privateCentral.ForceReconcile).To(Equal("true"))
})
// TODO(ROX-11368): Add test to eventually reach ready state
// TODO(ROX-11368): create test to check that Central and Scanner are healthy
// TODO(ROX-11368): Create test to check Central is correctly exposed
Expand Down
11 changes: 3 additions & 8 deletions internal/dinosaur/pkg/handlers/admin_dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,7 @@ func updateCentralRequest(request *dbapi.CentralRequest, strategicPatch []byte)
if err != nil {
return fmt.Errorf("unmarshalling strategic merge patch: %w", err)
}
// only keep central and scanner keys
for k := range patchMap {
if k != "central" && k != "scanner" {
delete(patchMap, k)
}
}

patchBytes, err := json.Marshal(patchMap)
if err != nil {
return fmt.Errorf("marshalling strategic merge patch: %w", err)
Expand All @@ -308,12 +303,12 @@ func updateCentralRequest(request *dbapi.CentralRequest, strategicPatch []byte)
scannerBytes = string(request.Scanner)
}

var originalBytes = fmt.Sprintf("{\"central\":%s,\"scanner\":%s,\"forceReconcile\":\"%s\"}", centralBytes, scannerBytes, request.ForceReconcile)
var originalBytes = fmt.Sprintf("{\"central\":%s,\"scanner\":%s,\"force_reconcile\":\"%s\"}", centralBytes, scannerBytes, request.ForceReconcile)

type Original struct {
Central *dbapi.CentralSpec `json:"central,omitempty"`
Scanner *dbapi.ScannerSpec `json:"scanner,omitempty"`
ForceReconcile string `json:"forceReconcile,omitempty"`
ForceReconcile string `json:"force_reconcile,omitempty"`
}

// apply the patch
Expand Down
20 changes: 11 additions & 9 deletions internal/dinosaur/pkg/handlers/admin_dinosaur_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ func Test_updateCentralRequest(t *testing.T) {
patch: `{"scanner":{"analyzer":{"resources":{"limits":null}}}}`,
wantScanner: `{"analyzer":{"resources":{"requests":{"cpu":"1","memory":"1"}},"scaling":{}},"db":{"resources":{}}}`,
}, {
name: "replacing forceReconcile",
state: `{"forceReconcile":"foo"}`,
patch: `{"forceReconcile":"bar"}`,
name: "replacing force_reconcile",
state: `{"force_reconcile":"foo"}`,
patch: `{"force_reconcile":"bar"}`,
wantForceReconcile: "bar",
}, {
name: "unsetting forceReconcile",
state: `{"forceReconcile":"foo"}`,
patch: `{"forceReconcile":null}`,
name: "unsetting force_reconcile",
state: `{"force_reconcile":"foo"}`,
patch: `{"force_reconcile":null}`,
wantForceReconcile: "",
}, {
name: "setting forceReconcile to empty string",
state: `{"forceReconcile":"foo"}`,
patch: `{"forceReconcile":""}`,
name: "setting force_reconcile to empty string",
state: `{"force_reconcile":"foo"}`,
patch: `{"force_reconcile":""}`,
wantForceReconcile: "",
}, {
name: "should fail if the patch is invalid json",
Expand Down Expand Up @@ -217,6 +217,8 @@ func Test_updateCentralRequest(t *testing.T) {
if len(tt.wantCentral) > 0 {
assert.Equal(t, string(tt.wantCentral), string(request.Central))
}

assert.Equal(t, tt.wantForceReconcile, request.ForceReconcile)
}
})
}
Expand Down
Loading