Skip to content

Commit

Permalink
OCM-7924 | fix: list machinepool should show inline
Browse files Browse the repository at this point in the history
Signed-off-by: Maggie Chen <magchen@redhat.com>

add tests

Signed-off-by: Maggie Chen <magchen@redhat.com>

Empty commit

Signed-off-by: Maggie Chen <magchen@redhat.com>

fix test

Signed-off-by: Maggie Chen <magchen@redhat.com>
  • Loading branch information
chenz4027 committed May 10, 2024
1 parent eee726b commit 689ac81
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
10 changes: 5 additions & 5 deletions cmd/list/machinepool/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const (
" us-east-1a, us-east-1b, us-east-1c Yes (max $5) default " +
"\nnodepool853 Yes 1-100 m5.xlarge test=label test=taint: " +
"us-east-1a, us-east-1b, us-east-1c Yes (max $5) default \n"
multipleNodePoolsOutput = "ID AUTOSCALING REPLICAS INSTANCE TYPE LABELS TAINTS" +
" AVAILABILITY ZONE SUBNET VERSION AUTOREPAIR \nnodepool85 No" +
" /0 m5.xlarge us-east-1a " +
" 4.12.24 No \nnodepool852 Yes " +
"/\n - Min replicas: 100\n - Max replicas: 1000 m5.xlarge test=label us-east-1a 4.12.24 No \n"
multipleNodePoolsOutput = "ID AUTOSCALING REPLICAS INSTANCE TYPE LABELS TAINTS " +
"AVAILABILITY ZONE SUBNET VERSION AUTOREPAIR \nnodepool85 No /0 " +
"m5.xlarge us-east-1a 4.12.24 No " +
"\nnodepool852 Yes /100-1000 m5.xlarge test=label us-east-1a " +
"4.12.24 No \n"
)

var _ = Describe("List machine pool", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/machinepool/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func getNodePoolsString(nodePools []*cmv1.NodePool) string {
ocmOutput.PrintNodePoolAutoscaling(nodePool.Autoscaling()),
ocmOutput.PrintNodePoolReplicasShort(
ocmOutput.PrintNodePoolCurrentReplicas(nodePool.Status()),
ocmOutput.PrintNodePoolReplicas(nodePool.Autoscaling(), nodePool.Replicas()),
ocmOutput.PrintNodePoolReplicasInline(nodePool.Autoscaling(), nodePool.Replicas()),
),
ocmOutput.PrintNodePoolInstanceType(nodePool.AWSNodePool()),
ocmOutput.PrintLabels(nodePool.Labels()),
Expand Down
9 changes: 9 additions & 0 deletions pkg/ocm/output/nodepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ func PrintNodePoolAutoscaling(autoscaling *cmv1.NodePoolAutoscaling) string {
return output.No
}

func PrintNodePoolReplicasInline(autoscaling *cmv1.NodePoolAutoscaling, replicas int) string {
if autoscaling != nil {
return fmt.Sprintf("%d-%d",
autoscaling.MinReplica(),
autoscaling.MaxReplica())
}
return fmt.Sprintf("%d", replicas)
}

func PrintNodePoolReplicas(autoscaling *cmv1.NodePoolAutoscaling, replicas int) string {
if autoscaling != nil {
return fmt.Sprintf(`
Expand Down
22 changes: 18 additions & 4 deletions pkg/ocm/output/nodepools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,31 @@ var _ = Describe("Create node drain grace period builder validations", func() {
output := PrintNodeDrainGracePeriod(period)
Expect(output).To(Equal(expectedOutput))
},
Entry(nil,
Entry("Should return empty string", nil,
"",
),
Entry(zeroValue,
Entry("Should return empty string", zeroValue,
"",
),
Entry(oneValue,
Entry("Should return 1 minute", oneValue,
"1 minute",
),
Entry(twoValue,
Entry("Should return 2 minutes", twoValue,
"2 minutes",
),
)
})

var _ = Describe("PrintNodePoolReplicasInline", func() {
It("Should print the correct output if autoscaling exists", func() {
autoscaling := cmv1.NewNodePoolAutoscaling().MinReplica(2).MaxReplica(6)
output := PrintNodePoolReplicasInline((*cmv1.NodePoolAutoscaling)(autoscaling), 2)
Expect(output).To(Equal("2-6"))
})

It("Should print the correct output if autoscaling is nill", func() {
output := PrintNodePoolReplicasInline(nil, 2)
Expect(output).To(Equal("2"))
})

})
13 changes: 13 additions & 0 deletions pkg/ocm/output/output_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package output

import (
"testing"

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

func TestOutput(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Output Suite")
}

0 comments on commit 689ac81

Please sign in to comment.