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 047569f
Showing 1 changed file with 66 additions and 3 deletions.
69 changes: 66 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,67 @@ 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("isn't valid: it must contain only letters, digits, dashes and underscores"))

Check failure on line 204 in tests/list_machinepools_test.go

View workflow job for this annotation

GitHub Actions / Lint

line is 126 characters (lll)
})

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 047569f

Please sign in to comment.