diff --git a/cli/cmd/secrets_test.go b/cli/cmd/secrets_test.go index 70968136..37bb25c3 100644 --- a/cli/cmd/secrets_test.go +++ b/cli/cmd/secrets_test.go @@ -35,5 +35,5 @@ func TestPrintList(t *testing.T) { } out := &bytes.Buffer{} printList(out, secrets) - golden.Assert(t, out.String(), "secrets-out.golden") + golden.Assert(t, out.String(), "volumes-out.golden") } diff --git a/cli/cmd/volume/create.go b/cli/cmd/volume/list.go similarity index 65% rename from cli/cmd/volume/create.go rename to cli/cmd/volume/list.go index 07b2ebcf..7e8c4e33 100644 --- a/cli/cmd/volume/create.go +++ b/cli/cmd/volume/list.go @@ -22,54 +22,11 @@ import ( "os" "strings" "text/tabwriter" - - "github.com/docker/compose-cli/aci" - "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/volumes" ) -// Command manage volumes -func Command() *cobra.Command { - cmd := &cobra.Command{ - Use: "volume", - Short: "Manages volumes", - } - - cmd.AddCommand( - createVolume(), - listVolume(), - ) - return cmd -} - -func createVolume() *cobra.Command { - opts := aci.VolumeCreateOptions{} - cmd := &cobra.Command{ - Use: "create", - Short: "Creates an Azure file share to use as ACI volume.", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - c, err := client.New(cmd.Context()) - if err != nil { - return err - } - id, err := c.VolumeService().Create(cmd.Context(), opts) - if err != nil { - return err - } - fmt.Println(id) - return nil - }, - } - - cmd.Flags().StringVar(&opts.Account, "storage-account", "", "Storage account name") - cmd.Flags().StringVar(&opts.Fileshare, "fileshare", "", "Fileshare name") - return cmd -} - func listVolume() *cobra.Command { cmd := &cobra.Command{ Use: "ls", diff --git a/cli/cmd/volume/list_test.go b/cli/cmd/volume/list_test.go new file mode 100644 index 00000000..ab21c75d --- /dev/null +++ b/cli/cmd/volume/list_test.go @@ -0,0 +1,22 @@ +package volume + +import ( + "bytes" + "github.com/docker/compose-cli/api/volumes" + "gotest.tools/v3/golden" + "testing" +) + +func TestPrintList(t *testing.T) { + secrets := []volumes.Volume{ + { + ID: "volume@123", + Name: "123", + Description: "volume 123", + }, + } + out := &bytes.Buffer{} + printList(out, secrets) + golden.Assert(t, out.String(), "volumes-out.golden") +} + diff --git a/cli/cmd/volume/testdata/volumes-out.golden b/cli/cmd/volume/testdata/volumes-out.golden new file mode 100644 index 00000000..ed27e449 --- /dev/null +++ b/cli/cmd/volume/testdata/volumes-out.golden @@ -0,0 +1,2 @@ +ID NAME DESCRIPTION +volume@123 123 volume 123 diff --git a/cli/cmd/volume/volume.go b/cli/cmd/volume/volume.go new file mode 100644 index 00000000..77362467 --- /dev/null +++ b/cli/cmd/volume/volume.go @@ -0,0 +1,63 @@ +package volume + +/* + Copyright 2020 Docker, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import ( + "fmt" + "github.com/spf13/cobra" + "github.com/docker/compose-cli/aci" + "github.com/docker/compose-cli/api/client" +) + +// Command manage volumes +func Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "volume", + Short: "Manages volumes", + } + + cmd.AddCommand( + createVolume(), + listVolume(), + ) + return cmd +} + +func createVolume() *cobra.Command { + opts := aci.VolumeCreateOptions{} + cmd := &cobra.Command{ + Use: "create", + Short: "Creates an Azure file share to use as ACI volume.", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + c, err := client.New(cmd.Context()) + if err != nil { + return err + } + id, err := c.VolumeService().Create(cmd.Context(), opts) + if err != nil { + return err + } + fmt.Println(id) + return nil + }, + } + + cmd.Flags().StringVar(&opts.Account, "storage-account", "", "Storage account name") + cmd.Flags().StringVar(&opts.Fileshare, "fileshare", "", "Fileshare name") + return cmd +} \ No newline at end of file