-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * add task commands, pull in sdk, fix breaking changes * move task waiting to /tasks/{id} method * expose instance tasks * update argument help wording * update commands to use task responses * update sdk * remove unused method
- Loading branch information
Showing
40 changed files
with
2,183 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ecloud | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/ukfast/cli/internal/pkg/factory" | ||
"github.com/ukfast/cli/internal/pkg/helper" | ||
"github.com/ukfast/cli/internal/pkg/output" | ||
"github.com/ukfast/sdk-go/pkg/service/ecloud" | ||
) | ||
|
||
func ecloudFirewallPolicyTaskRootCmd(f factory.ClientFactory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "task", | ||
Short: "sub-commands relating to firewall policy tasks", | ||
} | ||
|
||
// Child commands | ||
cmd.AddCommand(ecloudFirewallPolicyTaskListCmd(f)) | ||
|
||
return cmd | ||
} | ||
|
||
func ecloudFirewallPolicyTaskListCmd(f factory.ClientFactory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list <policy: id>", | ||
Short: "Lists firewall policy tasks", | ||
Long: "This command lists firewall policy tasks", | ||
Example: "ukfast ecloud firewall policy task list i-abcdef12", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) < 1 { | ||
return errors.New("Missing firewall policy") | ||
} | ||
|
||
return nil | ||
}, | ||
RunE: ecloudCobraRunEFunc(f, ecloudFirewallPolicyTaskList), | ||
} | ||
|
||
cmd.Flags().String("id", "", "Task ID for filtering") | ||
cmd.Flags().String("name", "", "Task name for filtering") | ||
|
||
return cmd | ||
} | ||
|
||
func ecloudFirewallPolicyTaskList(service ecloud.ECloudService, cmd *cobra.Command, args []string) error { | ||
params, err := helper.GetAPIRequestParametersFromFlags(cmd, | ||
helper.NewStringFilterFlagOption("id", "id"), | ||
helper.NewStringFilterFlagOption("name", "name"), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tasks, err := service.GetFirewallPolicyTasks(args[0], params) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving firewall policy tasks: %s", err) | ||
} | ||
|
||
return output.CommandOutput(cmd, OutputECloudTasksProvider(tasks)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package ecloud | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
gomock "github.com/golang/mock/gomock" | ||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/ukfast/cli/internal/pkg/clierrors" | ||
"github.com/ukfast/cli/test/mocks" | ||
"github.com/ukfast/sdk-go/pkg/service/ecloud" | ||
) | ||
|
||
func Test_ecloudFirewallPolicyTaskListCmd_Args(t *testing.T) { | ||
t.Run("ValidArgs_NoError", func(t *testing.T) { | ||
err := ecloudFirewallPolicyTaskListCmd(nil).Args(nil, []string{"i-abcdef12"}) | ||
|
||
assert.Nil(t, err) | ||
}) | ||
|
||
t.Run("InvalidArgs_Error", func(t *testing.T) { | ||
err := ecloudFirewallPolicyTaskListCmd(nil).Args(nil, []string{}) | ||
|
||
assert.NotNil(t, err) | ||
assert.Equal(t, "Missing firewall policy", err.Error()) | ||
}) | ||
} | ||
|
||
func Test_ecloudFirewallPolicyTaskList(t *testing.T) { | ||
t.Run("DefaultRetrieve", func(t *testing.T) { | ||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
|
||
service := mocks.NewMockECloudService(mockCtrl) | ||
|
||
service.EXPECT().GetFirewallPolicyTasks("i-abcdef12", gomock.Any()).Return([]ecloud.Task{}, nil).Times(1) | ||
|
||
ecloudFirewallPolicyTaskList(service, &cobra.Command{}, []string{"i-abcdef12"}) | ||
}) | ||
|
||
t.Run("MalformedFlag_ReturnsError", func(t *testing.T) { | ||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
|
||
service := mocks.NewMockECloudService(mockCtrl) | ||
cmd := &cobra.Command{} | ||
cmd.Flags().StringArray("filter", []string{"invalidfilter"}, "") | ||
|
||
err := ecloudFirewallPolicyTaskList(service, cmd, []string{}) | ||
|
||
assert.IsType(t, &clierrors.ErrInvalidFlagValue{}, err) | ||
}) | ||
|
||
t.Run("GetFirewallPolicysError_ReturnsError", func(t *testing.T) { | ||
|
||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
|
||
service := mocks.NewMockECloudService(mockCtrl) | ||
|
||
service.EXPECT().GetFirewallPolicyTasks("i-abcdef12", gomock.Any()).Return([]ecloud.Task{}, errors.New("test error")).Times(1) | ||
|
||
err := ecloudFirewallPolicyTaskList(service, &cobra.Command{}, []string{"i-abcdef12"}) | ||
|
||
assert.Equal(t, "Error retrieving firewall policy tasks: test error", err.Error()) | ||
}) | ||
} |
Oops, something went wrong.