From fed3ea3a10b6e4d5c97ea8c4992dc507a852dc58 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Tue, 14 Jun 2022 17:06:51 -0400 Subject: [PATCH] resolve comments --- pkg/executables/config/deploy-opts.json | 9 -- pkg/executables/govc.go | 39 +++++++- pkg/executables/govc_test.go | 123 ++++++++++++++---------- 3 files changed, 106 insertions(+), 65 deletions(-) delete mode 100644 pkg/executables/config/deploy-opts.json diff --git a/pkg/executables/config/deploy-opts.json b/pkg/executables/config/deploy-opts.json deleted file mode 100644 index 5b413201a7b4e..0000000000000 --- a/pkg/executables/config/deploy-opts.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "DiskProvisioning": "thin", - "NetworkMapping": [ - { - "Name": "nic0", - "Network": "%s" - } - ] -} diff --git a/pkg/executables/govc.go b/pkg/executables/govc.go index da659e54628cf..7ca5d958239b5 100644 --- a/pkg/executables/govc.go +++ b/pkg/executables/govc.go @@ -36,13 +36,20 @@ const ( vSpherePasswordKey = "EKSA_VSPHERE_PASSWORD" vSphereServerKey = "VSPHERE_SERVER" byteToGiB = 1073741824.0 - deployOptsFile = "deploy-opts.json" + DeployOptsFile = "deploy-opts.json" ) var requiredEnvs = []string{govcUsernameKey, govcPasswordKey, govcURLKey, govcInsecure} -//go:embed config/deploy-opts.json -var deployOpts string +type NetworkMapping struct { + Name string + Network string +} + +type DeployOption struct { + DiskProvisioning string + NetworkMapping []NetworkMapping +} type FolderType string @@ -354,7 +361,12 @@ func (g *Govc) deployTemplate(ctx context.Context, library, templateName, deploy templateInLibraryPath = fmt.Sprintf("/%s", templateInLibraryPath) } - deployOptsPath, err := g.writer.Write(deployOptsFile, []byte(fmt.Sprintf(deployOpts, network)), filewriter.PersistentFile) + deployOpts, err := GetDeployOptions(network) + if err != nil { + return err + } + + deployOptsPath, err := g.writer.Write(DeployOptsFile, deployOpts, filewriter.PersistentFile) if err != nil { return fmt.Errorf("failed writing deploy options file to disk: %v", err) } @@ -897,3 +909,22 @@ func (g *Govc) createCategory(ctx context.Context, name string, objectTypes []ob } return nil } + +func GetDeployOptions(network string) ([]byte, error) { + deployOptsStruct := DeployOption{ + DiskProvisioning: "thin", + NetworkMapping: []NetworkMapping{ + { + Name: "nic0", + Network: network, + }, + }, + } + + deployOpts, err := json.Marshal(deployOptsStruct) + if err != nil { + return nil, fmt.Errorf("marshalling template deployment options: %v", err) + } + + return deployOpts, err +} diff --git a/pkg/executables/govc_test.go b/pkg/executables/govc_test.go index eab17e6ef4d2a..fd4e1ef4d93ec 100644 --- a/pkg/executables/govc_test.go +++ b/pkg/executables/govc_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "errors" + "io/ioutil" "net/http" "net/http/httptest" "os" @@ -13,6 +14,7 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/aws/eks-anywhere/internal/test" @@ -88,14 +90,14 @@ func setupContext(t *testing.T) { }) } -func setup(t *testing.T) (govc *executables.Govc, mockExecutable *mockexecutables.MockExecutable, env map[string]string) { +func setup(t *testing.T) (dir string, govc *executables.Govc, mockExecutable *mockexecutables.MockExecutable, env map[string]string) { setupContext(t) - _, writer := test.NewWriter(t) + dir, writer := test.NewWriter(t) mockCtrl := gomock.NewController(t) executable := mockexecutables.NewMockExecutable(mockCtrl) g := executables.NewGovc(executable, writer) - return g, executable, govcEnvironment + return dir, g, executable, govcEnvironment } type deployTemplateTest struct { @@ -104,6 +106,7 @@ type deployTemplateTest struct { env map[string]string datacenter string datastore string + dir string network string resourcePool string templatePath string @@ -118,13 +121,14 @@ type deployTemplateTest struct { } func newDeployTemplateTest(t *testing.T) *deployTemplateTest { - g, exec, env := setup(t) + dir, g, exec, env := setup(t) return &deployTemplateTest{ govc: g, mockExecutable: exec, env: env, datacenter: "SDDC-Datacenter", datastore: "/SDDC-Datacenter/datastore/WorkloadDatastore", + dir: dir, network: "/SDDC-Datacenter/network/sddc-cgw-network-1", resourcePool: "*/Resources/Compute-ResourcePool", templatePath: "/SDDC-Datacenter/vm/Templates/ubuntu-2004-kube-v1.19.6", @@ -198,11 +202,25 @@ func (dt *deployTemplateTest) assertDeployTemplateError(t *testing.T) { } } +func (dt *deployTemplateTest) assertDeployOptsMatches(t *testing.T) { + expected, err := executables.GetDeployOptions(dt.network) + if err != nil { + t.Fatalf("failed to get deploy options: %v", err) + } + + actual, err := ioutil.ReadFile(filepath.Join(dt.dir, executables.DeployOptsFile)) + if err != nil { + t.Fatalf("failed to read deploy options file: %v", err) + } + + assert.Equal(t, expected, actual) +} + func TestSearchTemplateItExists(t *testing.T) { ctx := context.Background() datacenter := "SDDC-Datacenter" - g, executable, env := setup(t) + _, g, executable, env := setup(t) machineConfig := newMachineConfig(t) machineConfig.Spec.Template = "/SDDC Datacenter/vm/Templates/ubuntu 2004-kube-v1.19.6" executable.EXPECT().ExecuteWithEnv(ctx, env, "find", "-json", "/"+datacenter, "-type", "VirtualMachine", "-name", filepath.Base(machineConfig.Spec.Template)).Return(*bytes.NewBufferString("[\"/SDDC Datacenter/vm/Templates/ubuntu 2004-kube-v1.19.6\"]"), nil) @@ -218,7 +236,7 @@ func TestSearchTemplateItDoesNotExists(t *testing.T) { ctx := context.Background() datacenter := "SDDC-Datacenter" - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "find", "-json", "/"+datacenter, "-type", "VirtualMachine", "-name", filepath.Base(machineConfig.Spec.Template)).Return(*bytes.NewBufferString(""), nil) templateFullPath, err := g.SearchTemplate(ctx, datacenter, machineConfig) @@ -232,7 +250,7 @@ func TestSearchTemplateError(t *testing.T) { ctx := context.Background() datacenter := "SDDC-Datacenter" - g, executable, env := setup(t) + _, g, executable, env := setup(t) g.Retrier = retrier.NewWithMaxRetries(5, 0) executable.EXPECT().ExecuteWithEnv(ctx, env, gomock.Any()).Return(bytes.Buffer{}, errors.New("error from execute with env")).Times(5) @@ -245,7 +263,7 @@ func TestSearchTemplateError(t *testing.T) { func TestLibraryElementExistsItExists(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.ls", templateLibrary).Return(*bytes.NewBufferString("testing"), nil) exists, err := g.LibraryElementExists(ctx, templateLibrary) @@ -260,7 +278,7 @@ func TestLibraryElementExistsItExists(t *testing.T) { func TestLibraryElementExistsItDoesNotExists(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.ls", templateLibrary).Return(*bytes.NewBufferString(""), nil) exists, err := g.LibraryElementExists(ctx, templateLibrary) @@ -275,7 +293,7 @@ func TestLibraryElementExistsItDoesNotExists(t *testing.T) { func TestLibraryElementExistsError(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.ls", templateLibrary).Return(bytes.Buffer{}, errors.New("error from execute with env")) _, err := g.LibraryElementExists(ctx, templateLibrary) @@ -293,7 +311,7 @@ func TestGetLibraryElementContentVersionSuccess(t *testing.T) { ]` libraryElement := "/eks-a-templates/ubuntu-2004-kube-v1.19.6" - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.info", "-json", libraryElement).Return(*bytes.NewBufferString(response), nil) _, err := g.GetLibraryElementContentVersion(ctx, libraryElement) @@ -306,7 +324,7 @@ func TestGetLibraryElementContentVersionError(t *testing.T) { ctx := context.Background() libraryElement := "/eks-a-templates/ubuntu-2004-kube-v1.19.6" - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.info", "-json", libraryElement).Return(bytes.Buffer{}, errors.New("error from execute with env")) _, err := g.GetLibraryElementContentVersion(ctx, libraryElement) @@ -319,7 +337,7 @@ func TestDeleteLibraryElementSuccess(t *testing.T) { ctx := context.Background() libraryElement := "/eks-a-templates/ubuntu-2004-kube-v1.19.6" - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.rm", libraryElement).Return(*bytes.NewBufferString(""), nil) err := g.DeleteLibraryElement(ctx, libraryElement) @@ -332,7 +350,7 @@ func TestDeleteLibraryElementError(t *testing.T) { ctx := context.Background() libraryElement := "/eks-a-templates/ubuntu-2004-kube-v1.19.6" - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.rm", libraryElement).Return(bytes.Buffer{}, errors.New("error from execute with env")) err := g.DeleteLibraryElement(ctx, libraryElement) @@ -418,6 +436,7 @@ func TestDeployTemplateFromLibrarySuccess(t *testing.T) { tt.expectMarkAsTemplateToReturn(nil) tt.assertDeployTemplateSuccess(t) + tt.assertDeployOptsMatches(t) } func TestDeployTemplateFromLibraryErrorDeploy(t *testing.T) { @@ -544,7 +563,7 @@ func TestCreateLibrarySuccess(t *testing.T) { datastore := "/SDDC-Datacenter/datastore/WorkloadDatastore" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.create", "-ds", datastore, templateLibrary).Return(*bytes.NewBufferString("testing"), nil) err := g.CreateLibrary(ctx, datastore, templateLibrary) @@ -557,7 +576,7 @@ func TestCreateLibraryError(t *testing.T) { datastore := "/SDDC-Datacenter/datastore/WorkloadDatastore" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.create", "-ds", datastore, templateLibrary).Return(bytes.Buffer{}, errors.New("error from execute with env")) err := g.CreateLibrary(ctx, datastore, templateLibrary) @@ -570,7 +589,7 @@ func TestGetTagsSuccessNoTags(t *testing.T) { path := "/SDDC-Datacenter/vm/Templates/ubuntu-2004-kube-v1.19.6" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.attached.ls", "-json", "-r", path).Return(*bytes.NewBufferString("null"), nil) tags, err := g.GetTags(ctx, path) @@ -593,7 +612,7 @@ func TestGetTagsSuccessHasTags(t *testing.T) { ]` wantTags := []string{"kubernetesChannel:1.19", "eksd:1.19-4"} - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.attached.ls", "-json", "-r", path).Return(*bytes.NewBufferString(tagsReponse), nil) gotTags, err := g.GetTags(ctx, path) @@ -610,7 +629,7 @@ func TestGetTagsErrorGovc(t *testing.T) { path := "/SDDC-Datacenter/vm/Templates/ubuntu-2004-kube-v1.19.6" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) g.Retrier = retrier.NewWithMaxRetries(5, 0) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.attached.ls", "-json", "-r", path).Return(bytes.Buffer{}, errors.New("error from exec")).Times(5) @@ -624,7 +643,7 @@ func TestGetTagsErrorUnmarshalling(t *testing.T) { path := "/SDDC-Datacenter/vm/Templates/ubuntu-2004-kube-v1.19.6" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.attached.ls", "-json", "-r", path).Return(*bytes.NewBufferString("invalid"), nil) _, err := g.GetTags(ctx, path) @@ -636,7 +655,7 @@ func TestGetTagsErrorUnmarshalling(t *testing.T) { func TestListTagsSuccessNoTags(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.ls", "-json").Return(*bytes.NewBufferString("null"), nil) tags, err := g.ListTags(ctx) @@ -666,7 +685,7 @@ func TestListTagsSuccessHasTags(t *testing.T) { ]` wantTags := []string{"eksd:1.19-4", "kubernetesChannel:1.19"} - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.ls", "-json").Return(*bytes.NewBufferString(tagsReponse), nil) gotTags, err := g.ListTags(ctx) @@ -682,7 +701,7 @@ func TestListTagsSuccessHasTags(t *testing.T) { func TestListTagsErrorGovc(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.ls", "-json").Return(bytes.Buffer{}, errors.New("error from exec")) _, err := g.ListTags(ctx) @@ -694,7 +713,7 @@ func TestListTagsErrorGovc(t *testing.T) { func TestListTagsErrorUnmarshalling(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.ls", "-json").Return(*bytes.NewBufferString("invalid"), nil) _, err := g.ListTags(ctx) @@ -708,7 +727,7 @@ func TestAddTagSuccess(t *testing.T) { path := "/SDDC-Datacenter/vm/Templates/ubuntu-2004-kube-v1.19.6" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.attach", tag, path).Return(*bytes.NewBufferString(""), nil) err := g.AddTag(ctx, path, tag) @@ -722,7 +741,7 @@ func TestAddTagError(t *testing.T) { path := "/SDDC-Datacenter/vm/Templates/ubuntu-2004-kube-v1.19.6" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.attach", tag, path).Return(bytes.Buffer{}, errors.New("error from execute with env")) err := g.AddTag(ctx, path, tag) @@ -736,7 +755,7 @@ func TestCreateTagSuccess(t *testing.T) { tag := "tag" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.create", "-c", category, tag).Return(*bytes.NewBufferString(""), nil) err := g.CreateTag(ctx, tag, category) @@ -750,7 +769,7 @@ func TestCreateTagError(t *testing.T) { tag := "tag" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.create", "-c", category, tag).Return(bytes.Buffer{}, errors.New("error from execute with env")) err := g.CreateTag(ctx, tag, category) @@ -762,7 +781,7 @@ func TestCreateTagError(t *testing.T) { func TestListCategoriesSuccessNoCategories(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.category.ls", "-json").Return(*bytes.NewBufferString("null"), nil) gotCategories, err := g.ListCategories(ctx) @@ -799,7 +818,7 @@ func TestListCategoriesSuccessHasCategories(t *testing.T) { ]` wantCats := []string{"eksd", "kubernetesChannel"} - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.category.ls", "-json").Return(*bytes.NewBufferString(catsResponse), nil) gotCats, err := g.ListCategories(ctx) @@ -815,7 +834,7 @@ func TestListCategoriesSuccessHasCategories(t *testing.T) { func TestListCategoriesErrorGovc(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.category.ls", "-json").Return(bytes.Buffer{}, errors.New("error from exec")) _, err := g.ListCategories(ctx) @@ -827,7 +846,7 @@ func TestListCategoriesErrorGovc(t *testing.T) { func TestListCategoriesErrorUnmarshalling(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.category.ls", "-json").Return(*bytes.NewBufferString("invalid"), nil) _, err := g.ListCategories(ctx) @@ -840,7 +859,7 @@ func TestCreateCategoryForVMSuccess(t *testing.T) { category := "category" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.category.create", "-t", "VirtualMachine", category).Return(*bytes.NewBufferString(""), nil) err := g.CreateCategoryForVM(ctx, category) @@ -853,7 +872,7 @@ func TestCreateCategoryForVMError(t *testing.T) { category := "category" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "tags.category.create", "-t", "VirtualMachine", category).Return(bytes.Buffer{}, errors.New("error from execute with env")) err := g.CreateCategoryForVM(ctx, category) @@ -867,7 +886,7 @@ func TestImportTemplateSuccess(t *testing.T) { name := "name" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.import", "-k", "-pull", "-n", name, templateLibrary, ovaURL).Return(*bytes.NewBufferString(""), nil) if err := g.ImportTemplate(ctx, templateLibrary, ovaURL, name); err != nil { @@ -880,7 +899,7 @@ func TestImportTemplateError(t *testing.T) { name := "name" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "library.import", "-k", "-pull", "-n", name, templateLibrary, ovaURL).Return(bytes.Buffer{}, errors.New("error from execute with env")) if err := g.ImportTemplate(ctx, templateLibrary, ovaURL, name); err == nil { @@ -893,7 +912,7 @@ func TestDeleteTemplateSuccess(t *testing.T) { resourcePool := "resourcePool" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "vm.markasvm", "-pool", resourcePool, template).Return(*bytes.NewBufferString(""), nil) executable.EXPECT().ExecuteWithEnv(ctx, env, "snapshot.remove", "-vm", template, "*").Return(*bytes.NewBufferString(""), nil) executable.EXPECT().ExecuteWithEnv(ctx, env, "vm.destroy", template).Return(*bytes.NewBufferString(""), nil) @@ -908,7 +927,7 @@ func TestDeleteTemplateMarkAsVMError(t *testing.T) { resourcePool := "resourcePool" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "vm.markasvm", "-pool", resourcePool, template).Return(bytes.Buffer{}, errors.New("error from execute with env")) if err := g.DeleteTemplate(ctx, resourcePool, template); err == nil { @@ -921,7 +940,7 @@ func TestDeleteTemplateRemoveSnapshotError(t *testing.T) { resourcePool := "resourcePool" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "vm.markasvm", "-pool", resourcePool, template).Return(*bytes.NewBufferString(""), nil) executable.EXPECT().ExecuteWithEnv(ctx, env, "snapshot.remove", "-vm", template, "*").Return(bytes.Buffer{}, errors.New("error from execute with env")) @@ -935,7 +954,7 @@ func TestDeleteTemplateDeleteVMError(t *testing.T) { resourcePool := "resourcePool" ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "vm.markasvm", "-pool", resourcePool, template).Return(*bytes.NewBufferString(""), nil) executable.EXPECT().ExecuteWithEnv(ctx, env, "snapshot.remove", "-vm", template, "*").Return(*bytes.NewBufferString(""), nil) executable.EXPECT().ExecuteWithEnv(ctx, env, "vm.destroy", template).Return(bytes.Buffer{}, errors.New("error from execute with env")) @@ -947,7 +966,7 @@ func TestDeleteTemplateDeleteVMError(t *testing.T) { func TestGovcLogoutSuccess(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "session.logout").Return(*bytes.NewBufferString(""), nil) executable.EXPECT().ExecuteWithEnv(ctx, env, "session.logout", "-k").Return(*bytes.NewBufferString(""), nil) @@ -960,7 +979,7 @@ func TestGovcLogoutSuccess(t *testing.T) { func TestGovcValidateVCenterConnectionSuccess(t *testing.T) { ctx := context.Background() ts := newHTTPSServer(t) - g, _, _ := setup(t) + _, g, _, _ := setup(t) if err := g.ValidateVCenterConnection(ctx, strings.TrimPrefix(ts.URL, "https://")); err != nil { t.Fatalf("Govc.ValidateVCenterConnection() err = %v, want err nil", err) @@ -969,7 +988,7 @@ func TestGovcValidateVCenterConnectionSuccess(t *testing.T) { func TestGovcValidateVCenterAuthenticationSuccess(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "about", "-k").Return(*bytes.NewBufferString(""), nil) @@ -980,7 +999,7 @@ func TestGovcValidateVCenterAuthenticationSuccess(t *testing.T) { func TestGovcIsCertSelfSignedTrue(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "about").Return(*bytes.NewBufferString(""), errors.New("")) @@ -991,7 +1010,7 @@ func TestGovcIsCertSelfSignedTrue(t *testing.T) { func TestGovcIsCertSelfSignedFalse(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) executable.EXPECT().ExecuteWithEnv(ctx, env, "about").Return(*bytes.NewBufferString(""), nil) @@ -1002,7 +1021,7 @@ func TestGovcIsCertSelfSignedFalse(t *testing.T) { func TestGovcGetCertThumbprintSuccess(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) wantThumbprint := "AB:AB:AB" executable.EXPECT().ExecuteWithEnv(ctx, env, "about.cert", "-thumbprint", "-k").Return(*bytes.NewBufferString("server.com AB:AB:AB"), nil) @@ -1019,7 +1038,7 @@ func TestGovcGetCertThumbprintSuccess(t *testing.T) { func TestGovcGetCertThumbprintBadOutput(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) wantErr := "invalid thumbprint format" executable.EXPECT().ExecuteWithEnv(ctx, env, "about.cert", "-thumbprint", "-k").Return(*bytes.NewBufferString("server.comAB:AB:AB"), nil) @@ -1031,7 +1050,7 @@ func TestGovcGetCertThumbprintBadOutput(t *testing.T) { func TestGovcConfigureCertThumbprint(t *testing.T) { ctx := context.Background() - g, _, _ := setup(t) + _, g, _, _ := setup(t) server := "server.com" thumbprint := "AB:AB:AB" wantKnownHostsContent := "server.com AB:AB:AB" @@ -1053,7 +1072,7 @@ func TestGovcConfigureCertThumbprint(t *testing.T) { func TestGovcDatacenterExistsTrue(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) datacenter := "datacenter_1" executable.EXPECT().ExecuteWithEnv(ctx, env, "datacenter.info", datacenter).Return(*bytes.NewBufferString(""), nil) @@ -1070,7 +1089,7 @@ func TestGovcDatacenterExistsTrue(t *testing.T) { func TestGovcDatacenterExistsFalse(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) datacenter := "datacenter_1" executable.EXPECT().ExecuteWithEnv(ctx, env, "datacenter.info", datacenter).Return(*bytes.NewBufferString("datacenter_1 not found"), errors.New("exit code 1")) @@ -1087,7 +1106,7 @@ func TestGovcDatacenterExistsFalse(t *testing.T) { func TestGovcNetworkExistsTrue(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) network := "/Networks/network_1" networkName := "network_1" networkDir := "/Networks" @@ -1106,7 +1125,7 @@ func TestGovcNetworkExistsTrue(t *testing.T) { func TestGovcNetworkExistsFalse(t *testing.T) { ctx := context.Background() - g, executable, env := setup(t) + _, g, executable, env := setup(t) network := "/Networks/network_1" networkName := "network_1" networkDir := "/Networks"