Skip to content

Commit

Permalink
Add assert command
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekMichali committed Jan 9, 2025
1 parent 1afadfa commit 89dd0ad
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions testing/e2e/skr-tester/pkg/command/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package command

import (
"errors"
"fmt"

kcp "skr-tester/pkg/kcp"
"skr-tester/pkg/logger"

"github.com/spf13/cobra"
)

type AssertCommand struct {
cobraCmd *cobra.Command
log logger.Logger
instanceID string
machineType string
}

func NewAsertCmd() *cobra.Command {
cmd := AssertCommand{}
cobraCmd := &cobra.Command{
Use: "assert",
Aliases: []string{"a"},
Short: "Does an assertion",
Long: "Does an assertion",
Example: "skr-tester assert -i instanceID -m m6i.large Asserts the instance has the machine type m6i.large.",

PreRunE: func(_ *cobra.Command, _ []string) error { return cmd.Validate() },
RunE: func(_ *cobra.Command, _ []string) error { return cmd.Run() },
}
cmd.cobraCmd = cobraCmd

cobraCmd.Flags().StringVarP(&cmd.instanceID, "instanceID", "i", "", "InstanceID of the specific instance.")
cobraCmd.Flags().StringVarP(&cmd.machineType, "machineType", "m", "", "MachineType of the specific instance.")

return cobraCmd
}

func (cmd *AssertCommand) Run() error {
cmd.log = logger.New()
if cmd.machineType != "" {
kcpClient := kcp.NewKCPClient()
currentMachineType, err := kcpClient.GetCurrentMachineType(cmd.instanceID)
if err != nil {
return fmt.Errorf("failed to get current machine type: %v", err)
}
if cmd.machineType != *currentMachineType {
return fmt.Errorf("machine types are not equal: expected %s, got %s", cmd.machineType, *currentMachineType)
} else {
fmt.Println("Machine type assertion passed: expected and got", cmd.machineType)
}
}
return nil
}

func (cmd *AssertCommand) Validate() error {
if cmd.instanceID != "" {
return nil
} else {
return errors.New("at least one of the following options have to be specified: instanceID")
}
}
1 change: 1 addition & 0 deletions testing/e2e/skr-tester/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func New() *cobra.Command {
NewDeprovisionCmd(),
NewCheckOperationCommand(),
NewUpdateCommand(),
NewAsertCmd(),
)

return cmd
Expand Down

0 comments on commit 89dd0ad

Please sign in to comment.