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

ROX-21867: e2e for traits #1618

Merged
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
8 changes: 4 additions & 4 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,21 @@
"filename": "pkg/client/fleetmanager/mocks/client_moq.go",
"hashed_secret": "44e17306b837162269a410204daaa5ecee4ec22c",
"is_verified": false,
"line_number": 584
"line_number": 646
},
{
"type": "Secret Keyword",
"filename": "pkg/client/fleetmanager/mocks/client_moq.go",
"hashed_secret": "0ff50155b4f57adeccae93f27dc23efe2a8b7824",
"is_verified": false,
"line_number": 585
"line_number": 647
},
{
"type": "Secret Keyword",
"filename": "pkg/client/fleetmanager/mocks/client_moq.go",
"hashed_secret": "5ce1b8d4fb9dae5c02b2017e39e7267a21cea37f",
"is_verified": false,
"line_number": 594
"line_number": 656
}
],
"pkg/client/iam/client_moq.go": [
Expand Down Expand Up @@ -586,5 +586,5 @@
}
]
},
"generated_at": "2024-02-05T19:02:34Z"
"generated_at": "2024-02-08T19:14:52Z"
}
103 changes: 103 additions & 0 deletions e2e/e2e_central_traits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package e2e

import (
"context"
"os"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/pkg/errors"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/admin/private"
"github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
fmImpl "github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager/impl"
)

var _ = Describe("central traits", Ordered, func() {
SkipIf(!runCentralTests, "Skipping Central tests")

var client *fleetmanager.Client
var adminAPI fleetmanager.AdminAPI
var notes []string
var ctx = context.Background()

BeforeEach(func() {
Expect(restoreDefaultGitopsConfig()).To(Succeed())

option := fmImpl.OptionFromEnv()
auth, err := fmImpl.NewStaticAuth(context.Background(), fmImpl.StaticOption{StaticToken: option.Static.StaticToken})
Expect(err).ToNot(HaveOccurred())
client, err = fmImpl.NewClient(fleetManagerEndpoint, auth)
Expect(err).ToNot(HaveOccurred())

adminStaticToken := os.Getenv("STATIC_TOKEN_ADMIN")
adminAuth, err := fmImpl.NewStaticAuth(context.Background(), fmImpl.StaticOption{StaticToken: adminStaticToken})
Expect(err).ToNot(HaveOccurred())
adminClient, err := fmImpl.NewClient(fleetManagerEndpoint, adminAuth)
Expect(err).ToNot(HaveOccurred())
adminAPI = adminClient.AdminAPI()

GinkgoWriter.Printf("Current time: %s\n", time.Now().String())
printNotes(notes)
})

It("should", func() {
central, _, err := adminAPI.CreateCentral(ctx, false, private.CentralRequestPayload{})
Expect(err).Should(Succeed())
id := central.Id
defer adminAPI.DeleteDbCentralById(ctx, id)

traits, _, err := adminAPI.GetCentralTraits(ctx, id)
Expect(err).ToNot(HaveOccurred(), "no error on no traits")
Expect(traits).To(BeEmpty(), "no traits yet")

_, err = adminAPI.PutCentralTrait(ctx, id, "test-trait")
Expect(err).ToNot(HaveOccurred(), "no error on adding test-trait")

traits, _, err = adminAPI.GetCentralTraits(ctx, id)
Expect(err).ToNot(HaveOccurred(), "no error on having traits")
Expect(traits).To(BeEquivalentTo([]string{"test-trait"}), "test-trait should be found")

_, err = adminAPI.PutCentralTrait(ctx, id, "test-trait-1")
Expect(err).ToNot(HaveOccurred(), "no error on adding test-trait-1")

_, err = adminAPI.PutCentralTrait(ctx, id, "test-trait-1")
Expect(err).ToNot(HaveOccurred(), "no error on adding test-trait-1 twice")

traits, _, err = adminAPI.GetCentralTraits(ctx, id)
Expect(err).ToNot(HaveOccurred(), "no error on having multiple traits")
Expect(traits).To(BeEquivalentTo([]string{"test-trait", "test-trait-1"}), "should have only two traits")

_, err = adminAPI.GetCentralTrait(ctx, id, "test-trait")
Expect(err).ToNot(HaveOccurred(), "no error on checking for existing trait")

_, err = adminAPI.GetCentralTrait(ctx, id, "test-trait-2")
Expect(err).To(HaveOccurred(), "error on checking for non-existing trait")

_, err = adminAPI.DeleteCentralTrait(ctx, id, "test-trait")
Expect(err).ToNot(HaveOccurred(), "no error on deleting test-trait")

_, err = adminAPI.DeleteCentralTrait(ctx, id, "test-trait")
Expect(err).ToNot(HaveOccurred(), "no error on deleting non-existing trait")

traits, _, err = adminAPI.GetCentralTraits(ctx, id)
Expect(err).ToNot(HaveOccurred(), "no error on retreiving traits")
Expect(traits).To(BeEquivalentTo([]string{"test-trait-1"}), "should have only one trait now")
})

It("should preserve preserved", func() {
central, _, err := adminAPI.CreateCentral(ctx, false, private.CentralRequestPayload{})
Expect(err).Should(Succeed())

_, err = adminAPI.PutCentralTrait(ctx, central.Id, constants.CentralTraitPreserved)
Expect(err).Should(Succeed())

_, err = client.PublicAPI().DeleteCentralById(ctx, central.Id, false)
Expect(err).To(BeEquivalentTo(errors.New("Bad request")))

_, err = adminAPI.DeleteDbCentralById(ctx, central.Id)
Expect(err).Should(Succeed(), "should ignore the preserved trait")
})
})
5 changes: 5 additions & 0 deletions pkg/client/fleetmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type AdminAPI interface {
DeleteDbCentralById(ctx context.Context, id string) (*http.Response, error)
CentralRotateSecrets(ctx context.Context, id string, centralRotateSecretsRequest admin.CentralRotateSecretsRequest) (*http.Response, error)
UpdateCentralNameById(ctx context.Context, id string, centralUpdateNameRequest admin.CentralUpdateNameRequest) (admin.Central, *http.Response, error)

GetCentralTraits(ctx context.Context, id string) ([]string, *http.Response, error)
GetCentralTrait(ctx context.Context, id string, trait string) (*http.Response, error)
PutCentralTrait(ctx context.Context, id string, trait string) (*http.Response, error)
DeleteCentralTrait(ctx context.Context, id string, trait string) (*http.Response, error)
}

// Client is a helper struct that wraps around the API clients generated from
Expand Down
Loading
Loading