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

Commit

Permalink
update UT
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis committed Nov 17, 2020
1 parent bc92ece commit 8d8397b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
11 changes: 5 additions & 6 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func (dc *deployCmd) loadAPIModel() error {
return errors.Wrap(err, "error parsing the api model")
}

if dc.containerService.Properties.MasterProfile == nil {
return errors.New("MasterProfile can't be nil")
}

// consume dc.caCertificatePath and dc.caPrivateKeyPath
if (dc.caCertificatePath != "" && dc.caPrivateKeyPath == "") || (dc.caCertificatePath == "" && dc.caPrivateKeyPath != "") {
return errors.New("--ca-certificate-path and --ca-private-key-path must be specified together")
Expand Down Expand Up @@ -255,7 +259,6 @@ func (dc *deployCmd) loadAPIModel() error {
}

func autofillApimodel(dc *deployCmd) error {

if dc.containerService.Properties.LinuxProfile != nil {
if dc.containerService.Properties.LinuxProfile.AdminUsername == "" {
log.Warnf("apimodel: no linuxProfile.adminUsername was specified. Will use 'azureuser'.")
Expand All @@ -280,11 +283,7 @@ func autofillApimodel(dc *deployCmd) error {
}

if dc.outputDirectory == "" {
if dc.containerService.Properties.MasterProfile != nil {
dc.outputDirectory = path.Join("_output", dc.containerService.Properties.MasterProfile.DNSPrefix)
} else {
return errors.New("can't determine output directory from nil MasterProfile")
}
dc.outputDirectory = path.Join("_output", dc.containerService.Properties.MasterProfile.DNSPrefix)
}

if _, err := os.Stat(dc.outputDirectory); !dc.forceOverwrite && err == nil {
Expand Down
25 changes: 25 additions & 0 deletions cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,31 @@ func TestDeployCmdRun(t *testing.T) {
}
}

func TestDeployCmdWithoutMasterProfile(t *testing.T) {
t.Parallel()

outdir, del := makeTmpDir(t)
defer del()

d := &deployCmd{
client: &armhelpers.MockAKSEngineClient{},
authProvider: &mockAuthProvider{
authArgs: &authArgs{},
getClientMock: &armhelpers.MockAKSEngineClient{},
},
apimodelPath: "../pkg/engine/testdata/simple/kubernetes.json",
outputDirectory: outdir,
forceOverwrite: true,
location: "westus",
}
d.set = []string{"masterProfile=nil"}

err := d.loadAPIModel()
if err == nil {
t.Fatalf("expected error loading api model without MasterProfile: %s", err.Error())
}
}

func TestLoadApiModelOnCustomCloud(t *testing.T) {
t.Parallel()

Expand Down
10 changes: 5 additions & 5 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ func (gc *generateCmd) loadAPIModel() error {
return errors.Wrap(err, "error parsing the api model")
}

if gc.containerService.Properties.MasterProfile == nil {
return errors.New("MasterProfile can't be nil")
}

if gc.outputDirectory == "" {
if gc.containerService.Properties.MasterProfile != nil {
gc.outputDirectory = path.Join("_output", gc.containerService.Properties.MasterProfile.DNSPrefix)
} else {
return errors.New("can't determine output directory from nil MasterProfile")
}
gc.outputDirectory = path.Join("_output", gc.containerService.Properties.MasterProfile.DNSPrefix)
}

// consume gc.caCertificatePath and gc.caPrivateKeyPath
Expand Down
21 changes: 21 additions & 0 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ func TestGenerateCmdMLoadAPIModel(t *testing.T) {
}
}

func TestGenerateCmdMLoadAPIModelWithoutMasterProfile(t *testing.T) {
g := &generateCmd{}
r := &cobra.Command{}

g.apimodelPath = "../pkg/engine/testdata/simple/kubernetes.json"
g.set = []string{"masterProfile=nil"}

err := g.validate(r, []string{"../pkg/engine/testdata/simple/kubernetes.json"})
if err != nil {
t.Fatalf("unexpected error validating api model: %s", err.Error())
}
err = g.mergeAPIModel()
if err != nil {
t.Fatalf("unexpected error merging api model: %s", err.Error())
}
err = g.loadAPIModel()
if err == nil {
t.Fatalf("expected error loading api model without MasterProfile: %s", err.Error())
}
}

func TestAPIModelWithoutServicePrincipalProfileAndClientIdAndSecretInGenerateCmd(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 8d8397b

Please sign in to comment.