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 tests #1661

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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-15T11:09:43Z"
}
102 changes: 102 additions & 0 deletions e2e/e2e_central_traits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package e2e

import (
"context"
"net/http"
"os"
"time"

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

"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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's align with `e2e_test.go

Suggested change
var _ = Describe("central traits", Ordered, func() {
var _ = Describe("Central traits", Ordered, func() {


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

BeforeEach(func() {
SkipIf(!runCentralTests, "Skipping Central tests")
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like notes are unused

})

It("should manage traits", func() {
central, _, err := adminAPI.CreateCentral(ctx, true, private.CentralRequestPayload{
CloudProvider: dpCloudProvider,
MultiAz: true,
Name: newCentralName(),
Region: dpRegion,
})
Expect(err).Should(Succeed())
id := central.Id

Eventually(assertCentralRequestProvisioning(ctx, client, id)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it matter to us in this test whether central will be provisioned or not?

WithTimeout(waitTimeout).
WithPolling(defaultPolling).
Should(Succeed())

defer adminAPI.DeleteDbCentralById(ctx, id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test whether it is possible to add trait to deleted central?


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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's rename to test-trait-0 for uniformity

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expect(traits).To(BeEquivalentTo([]string{"test-trait", "test-trait-1"}), "should have only two traits")
Expect(traits).To(BeEquivalentTo([]string{"test-trait", "test-trait-1"}), "should have exactly two traits")


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

resp, err := adminAPI.GetCentralTrait(ctx, id, "test-trait-2")
Expect(err).To(HaveOccurred(), "error on checking for non-existing trait")
if Expect(resp).NotTo(BeNil()) {
Expect(resp.StatusCode == http.StatusNotFound).To(BeTrue())
}

_, 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")
})
})
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