Skip to content

Commit

Permalink
added failure tests for list machinepools command
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirumlaDevi committed Sep 27, 2023
1 parent 1884874 commit 5b60bbf
Showing 1 changed file with 67 additions and 3 deletions.
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"))
})
})

0 comments on commit 5b60bbf

Please sign in to comment.