Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
upgrade validate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CecileRobertMichon committed May 7, 2018
1 parent 3753591 commit 54c8145
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 50 deletions.
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (dc *deployCmd) validate(cmd *cobra.Command, args []string) error {

dc.client, err = dc.authArgs.getClient()
if err != nil {
return fmt.Errorf("failed to get client: %s", err.Error()) // TODO: cleanup
return fmt.Errorf("failed to get client: %s", err.Error())
}

// autofillApimodel calls log.Fatal() directly and does not return errors
Expand Down
8 changes: 4 additions & 4 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func (uc *upgradeCmd) validate(cmd *cobra.Command) error {
return fmt.Errorf("--upgrade-version must be specified")
}

if uc.client, err = uc.authArgs.getClient(); err != nil {
return fmt.Errorf("Failed to get client: %s", err)
}

if uc.deploymentDirectory == "" {
cmd.Usage()
return fmt.Errorf("--deployment-dir must be specified")
}

if uc.client, err = uc.authArgs.getClient(); err != nil {
return fmt.Errorf("Failed to get client: %s", err)
}
return nil
}

Expand Down
147 changes: 113 additions & 34 deletions cmd/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,135 @@
package cmd

import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/pflag"
"github.com/spf13/cobra"
)

var _ = Describe("the upgrade command", func() {

It("should create an upgrade command", func() {
output := newUpgradeCmd()

flags := &pflag.FlagSet{
pflag.formal: {
"location": &pflag.Flag{
Name: "location",
Shorthand: "l",
Usage: "location the cluster is deployed in",
Value: "",
DefValue: "",
Expect(output.Use).Should(Equal(upgradeName))
Expect(output.Short).Should(Equal(upgradeShortDescription))
Expect(output.Long).Should(Equal(upgradeLongDescription))
Expect(output.Flags().Lookup("location")).NotTo(BeNil())
Expect(output.Flags().Lookup("resource-group")).NotTo(BeNil())
Expect(output.Flags().Lookup("deployment-dir")).NotTo(BeNil())
Expect(output.Flags().Lookup("upgrade-version")).NotTo(BeNil())
})

It("should validate an upgrade command", func() {
r := &cobra.Command{}

cases := []struct {
uc *upgradeCmd
expectedErr error
}{
{
uc: &upgradeCmd{
resourceGroupName: "",
deploymentDirectory: "_output/test",
upgradeVersion: "1.8.9",
location: "centralus",
timeoutInMinutes: 60,
authArgs: authArgs{
rawSubscriptionID: "99999999-0000-0000-0000-000000000000",
},
},
expectedErr: fmt.Errorf("--resource-group must be specified"),
},
{
uc: &upgradeCmd{
resourceGroupName: "test",
deploymentDirectory: "_output/test",
upgradeVersion: "1.8.9",
location: "",
timeoutInMinutes: 60,
authArgs: authArgs{
rawSubscriptionID: "99999999-0000-0000-0000-000000000000",
},
},
expectedErr: fmt.Errorf("--location must be specified"),
},
{
uc: &upgradeCmd{
resourceGroupName: "test",
deploymentDirectory: "_output/test",
upgradeVersion: "",
location: "southcentralus",
timeoutInMinutes: 60,
authArgs: authArgs{
rawSubscriptionID: "99999999-0000-0000-0000-000000000000",
},
},
expectedErr: fmt.Errorf("--upgrade-version must be specified"),
},
{
uc: &upgradeCmd{
resourceGroupName: "test",
deploymentDirectory: "",
upgradeVersion: "1.9.0",
location: "southcentralus",
timeoutInMinutes: 60,
authArgs: authArgs{
rawSubscriptionID: "99999999-0000-0000-0000-000000000000",
},
},
"resource-group": &pflag.Flag{
Name: "resource-group",
Shorthand: "g",
Usage: "the resource group where the cluster is deployed",
Value: "",
DefValue: "",
expectedErr: fmt.Errorf("--deployment-dir must be specified"),
},
{
uc: &upgradeCmd{
resourceGroupName: "test",
deploymentDirectory: "",
upgradeVersion: "1.9.0",
location: "southcentralus",
timeoutInMinutes: 60,
authArgs: authArgs{
rawSubscriptionID: "99999999-0000-0000-0000-000000000000",
},
},
"deployment-dir": &pflag.Flag{
Name: "deployment-dir",
Shorthand: "",
Usage: "the location of the output from `generate`",
Value: "",
DefValue: "",
expectedErr: fmt.Errorf("--deployment-dir must be specified"),
},
{
uc: &upgradeCmd{
resourceGroupName: "test",
deploymentDirectory: "_output/mydir",
upgradeVersion: "1.9.0",
location: "southcentralus",
authArgs: authArgs{},
},
"upgrade-version": &pflag.Flag{
Name: "upgrade-version",
Shorthand: "",
Usage: "desired kubernetes version",
Value: "",
DefValue: "",
expectedErr: fmt.Errorf("Failed to get client: --subscription-id is required (and must be a valid UUID)"),
},
{
uc: &upgradeCmd{
resourceGroupName: "test",
deploymentDirectory: "_output/mydir",
upgradeVersion: "1.9.0",
location: "southcentralus",
authArgs: authArgs{
rawSubscriptionID: "99999999-0000-0000-0000-000000000000",
RawAzureEnvironment: "AzurePublicCloud",
AuthMethod: "device",
},
},
expectedErr: nil,
},
}

output := newUpgradeCmd()
for _, c := range cases {
err := c.uc.validate(r)
if c.expectedErr != nil && err != nil {
Expect(err.Error()).To(Equal(c.expectedErr.Error()))
} else {
Expect(err).To(BeNil())
Expect(c.expectedErr).To(BeNil())
}
}

Expect(output.Use).Should(Equal(upgradeName))
Expect(output.Short).Should(Equal(upgradeShortDescription))
Expect(output.Long).Should(Equal(upgradeLongDescription))
Expect(output.Flag("location")).Should(Equal(flags.Lookup("location")))
Expect(output.Flag("location")).Should(Equal(flags.Lookup("location")))
Expect(output.Flag("resource-group")).Should(Equal(flags.Lookup("resource-group")))
})

})
12 changes: 1 addition & 11 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,15 @@ import (
"github.com/Azure/acs-engine/pkg/helpers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
flag "github.com/spf13/pflag"
)

var _ = Describe("the version command", func() {
It("should create a version command", func() {
output := newVersionCmd()

flag := &flag.Flag{
Name: "output",
Shorthand: "o",
Usage: "Output format to use: [human json]",
DefValue: "human",
}
flag.Value.Set("human")

Expect(output.Use).Should(Equal(versionName))
Expect(output.Short).Should(Equal(versionShortDescription))
Expect(output.Long).Should(Equal(versionLongDescription))
Expect(output.Flag("output")).Should(Equal(flag))
Expect(output.Flags().Lookup("output")).NotTo(BeNil())
})

It("should print a json version of ACS-Engine", func() {
Expand Down

0 comments on commit 54c8145

Please sign in to comment.