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

added failure tests for list machinepools command and fixed dependency test issues #557

Merged
merged 1 commit into from
Sep 28, 2023
Merged
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
70 changes: 67 additions & 3 deletions tests/list_machinepools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ var _ = Describe("List machine pools", Ordered, func() {
"id":"my-cluster",
"subscription": {"id":"subsID"},
"state":"ready"
}]
}]
}`

BeforeAll(func() {
BeforeEach(func() {
// Create a context:
ctx = context.Background()

Expand Down Expand Up @@ -86,7 +86,7 @@ var _ = Describe("List machine pools", Ordered, func() {
config = result.ConfigString()
})

AfterAll(func() {
AfterEach(func() {
// Close the servers:
ssoServer.Close()
apiServer.Close()
Expand Down Expand Up @@ -186,4 +186,68 @@ var _ = Describe("List machine pools", Ordered, func() {
`^default\s+No\s+2\s+m5.xlarge\s+us-west-2a$`,
))
})

It("Fail on invalid cluster key", func() {
apiServer.AppendHandlers(
RespondWithJSON(http.StatusOK, subscriptionInfo),
)

// Run the command:
result := NewCommand().
ConfigString(config).
Args(
"list", "machinepools",
"--cluster", "invalid!cluster",
).Run(ctx)

Expect(result.ExitCode()).ToNot(BeZero())
Expect(result.ErrString()).To(ContainSubstring("Cluster name, identifier or external identifier"))
Expect(result.ErrString()).To(ContainSubstring("isn't valid"))
})

It("Fail on non-existing cluster", func() {
apiServer.AppendHandlers(
RespondWithJSON(http.StatusOK, subscriptionInfo),
RespondWith(http.StatusNotFound, `{}`),
)

// Run the command:
result := NewCommand().
ConfigString(config).
Args(
"list", "machinepools",
"--cluster", "my-cluster",
).Run(ctx)

Expect(result.ExitCode()).ToNot(BeZero())
Expect(result.ErrString()).To(ContainSubstring("Failed to get cluster"))
})

It("Fail when cluster is not in ready state", func() {
apiServer.AppendHandlers(
RespondWithJSON(http.StatusOK, subscriptionInfo),
RespondWithJSON(http.StatusOK, `{
"kind": "ClusterList",
"total": 1,
"items": [
{
"kind":"Cluster",
"id":"my-cluster",
"subscription": {"id":"subsID"},
"state":"waiting"
}]
}`),
)

// Run the command:
result := NewCommand().
ConfigString(config).
Args(
"list", "machinepools",
"--cluster", "my-cluster",
).Run(ctx)

Expect(result.ExitCode()).ToNot(BeZero())
Expect(result.ErrString()).To(ContainSubstring("is not yet ready"))
})
})
Loading