This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CecileRobertMichon
committed
May 7, 2018
1 parent
3753591
commit 54c8145
Showing
4 changed files
with
119 additions
and
50 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 |
---|---|---|
@@ -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"))) | ||
}) | ||
|
||
}) |
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