From 22b68e96385c140f6fdfd436019bb7266de44032 Mon Sep 17 00:00:00 2001 From: Nic Jackson Date: Fri, 23 Aug 2024 10:25:00 +0100 Subject: [PATCH] Fix variables when passed to command --- cmd/up.go | 44 +++--- cmd/{up_test.bak => up_test.go} | 234 ++++++++++++----------------- pkg/clients/getter/getter.go | 1 + pkg/clients/getter/mocks/getter.go | 47 ++++++ pkg/clients/system/mocks/system.go | 120 +++++++++++++++ pkg/clients/system/system.go | 2 + 6 files changed, 288 insertions(+), 160 deletions(-) rename cmd/{up_test.bak => up_test.go} (55%) create mode 100644 pkg/clients/getter/mocks/getter.go create mode 100644 pkg/clients/system/mocks/system.go diff --git a/cmd/up.go b/cmd/up.go index 53704658..3cf866e1 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -82,9 +82,13 @@ func newRunCmdFunc(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Gette // parse the vars into a map vars := map[string]string{} for _, v := range *variables { + // if the variable is wrapped in single quotes remove them + v = strings.TrimPrefix(v, "'") + v = strings.TrimSuffix(v, "'") + parts := strings.Split(v, "=") - if len(parts) == 2 { - vars[parts[0]] = parts[1] + if len(parts) >= 2 { + vars[parts[0]] = strings.Join(parts[1:], "=") } } @@ -174,7 +178,7 @@ func newRunCmdFunc(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Gette cancel() }() - res, err := e.ApplyWithVariables(ctx, dst, vars, *variablesFile) + config, err := e.ApplyWithVariables(ctx, dst, vars, *variablesFile) if err != nil { return err } @@ -185,30 +189,26 @@ func newRunCmdFunc(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Gette browserList := []string{} checkDuration := 30 * time.Second - for _, r := range res.Resources { - switch r.Metadata().Type { - case container.TypeContainer: - c := r.(*container.Container) - for _, p := range c.Ports { + for _, r := range config.Resources { + switch v := r.(type) { + case *container.Container: + for _, p := range v.Ports { if p.Host != "" && p.OpenInBrowser != "" { browserList = append(browserList, buildBrowserPath(r.Metadata().Name, p.Host, r.Metadata().Type, p.OpenInBrowser)) } } - case ingress.TypeIngress: - c := r.(*ingress.Ingress) - if c.OpenInBrowser != "" { - browserList = append(browserList, buildBrowserPath(r.Metadata().Name, fmt.Sprintf("%d", c.Port), r.Metadata().Type, c.OpenInBrowser)) + case *ingress.Ingress: + if v.OpenInBrowser != "" { + browserList = append(browserList, buildBrowserPath(r.Metadata().Name, fmt.Sprintf("%d", v.Port), r.Metadata().Type, v.OpenInBrowser)) } - case nomad.TypeNomadCluster: - c := r.(*nomad.NomadCluster) - if c.OpenInBrowser { + case *nomad.NomadCluster: + if v.OpenInBrowser { // get the API port - browserList = append(browserList, buildBrowserPath("server."+r.Metadata().Name, fmt.Sprintf("%d", c.APIPort), r.Metadata().Type, "/")) + browserList = append(browserList, buildBrowserPath("server."+r.Metadata().Name, fmt.Sprintf("%d", v.APIPort), r.Metadata().Type, "/")) } - case docs.TypeDocs: - c := r.(*docs.Docs) - if c.OpenInBrowser { - port := strconv.Itoa(c.Port) + case *docs.Docs: + if v.OpenInBrowser { + port := strconv.Itoa(v.Port) if port == "0" { port = "80" } @@ -226,7 +226,7 @@ func newRunCmdFunc(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Gette for _, b := range browserList { go func(uri string) { // health check the URL - err := hc.HealthCheckHTTP(uri, "", nil, "", []int{200}, checkDuration) + err := hc.HealthCheckHTTP(uri, "", map[string][]string{}, "", []int{200}, checkDuration) if err == nil { be := bc.OpenBrowser(uri) if be != nil { @@ -247,7 +247,7 @@ func newRunCmdFunc(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Gette // if we have a blueprint show the header var b *blueprint.Blueprint - bps, _ := e.Config().FindResourcesByType(blueprint.TypeBlueprint) + bps, _ := config.FindResourcesByType(blueprint.TypeBlueprint) for _, bp := range bps { // pick the first blueprint in the root if bp.Metadata().Module == "" { diff --git a/cmd/up_test.bak b/cmd/up_test.go similarity index 55% rename from cmd/up_test.bak rename to cmd/up_test.go index 2c109527..de967003 100644 --- a/cmd/up_test.bak +++ b/cmd/up_test.go @@ -9,54 +9,64 @@ import ( "testing" "time" - "github.com/hashicorp/go-hclog" + "github.com/jumppad-labs/hclconfig" + hcltypes "github.com/jumppad-labs/hclconfig/types" "github.com/jumppad-labs/jumppad/pkg/clients" - "github.com/jumppad-labs/jumppad/pkg/clients/mocks" - "github.com/jumppad-labs/jumppad/pkg/config" - "github.com/jumppad-labs/jumppad/pkg/config/resources" + conmock "github.com/jumppad-labs/jumppad/pkg/clients/connector/mocks" + "github.com/jumppad-labs/jumppad/pkg/clients/connector/types" + cmock "github.com/jumppad-labs/jumppad/pkg/clients/container/mocks" + gettermock "github.com/jumppad-labs/jumppad/pkg/clients/getter/mocks" + httpmock "github.com/jumppad-labs/jumppad/pkg/clients/http/mocks" + "github.com/jumppad-labs/jumppad/pkg/clients/logger" + systemmock "github.com/jumppad-labs/jumppad/pkg/clients/system/mocks" + "github.com/jumppad-labs/jumppad/pkg/config/resources/blueprint" + "github.com/jumppad-labs/jumppad/pkg/config/resources/container" + "github.com/jumppad-labs/jumppad/pkg/config/resources/docs" + "github.com/jumppad-labs/jumppad/pkg/config/resources/ingress" + "github.com/jumppad-labs/jumppad/pkg/config/resources/nomad" enginemocks "github.com/jumppad-labs/jumppad/pkg/jumppad/mocks" "github.com/jumppad-labs/jumppad/pkg/utils" "github.com/jumppad-labs/jumppad/testutils" - gvm "github.com/shipyard-run/version-manager" "github.com/spf13/cobra" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" assert "github.com/stretchr/testify/require" ) type runMocks struct { engine *enginemocks.Engine - getter *mocks.Getter - http *mocks.HTTP - system *mocks.System - vm *gvm.MockVersions - connector *clients.ConnectorMock + getter *gettermock.Getter + http *httpmock.HTTP + system *systemmock.System + tasks *cmock.ContainerTasks + connector *conmock.Connector } func setupRun(t *testing.T, timeout string) (*cobra.Command, *runMocks) { - mockHTTP := &mocks.HTTP{} - mockHTTP.On("HealthCheckHTTP", mock.Anything, mock.Anything, mock.Anything).Return(nil) + mockContainer := &cmock.ContainerTasks{} + mockContainer.On("SetForce", mock.Anything) - mockGetter := &mocks.Getter{} + mockHTTP := &httpmock.HTTP{} + mockHTTP.On("HealthCheckHTTP", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) + + mockGetter := &gettermock.Getter{} mockGetter.On("Get", mock.Anything, mock.Anything).Return(nil) mockGetter.On("SetForce", mock.Anything) - mockSystem := &mocks.System{} + mockSystem := &systemmock.System{} mockSystem.On("OpenBrowser", mock.Anything).Return(nil) mockSystem.On("Preflight").Return(nil) mockSystem.On("PromptInput", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return("") mockSystem.On("CheckVersion", mock.Anything).Return("", false) - mockTasks := &mocks.ContainerTasks{} - mockTasks.On("SetForce", mock.Anything) - - mockConnector := &clients.ConnectorMock{} + mockConnector := &conmock.Connector{} mockConnector.On("GetLocalCertBundle", mock.Anything).Return( - &clients.CertBundle{}, + &types.CertBundle{}, nil, ) mockConnector.On("GenerateLocalCertBundle", mock.Anything).Return( - &clients.CertBundle{}, + &types.CertBundle{}, nil, ) @@ -69,20 +79,20 @@ func setupRun(t *testing.T, timeout string) (*cobra.Command, *runMocks) { ) clients := &clients.Clients{ - HTTP: mockHTTP, - Getter: mockGetter, - Browser: mockSystem, - ContainerTasks: mockTasks, - Connector: mockConnector, + HTTP: mockHTTP, + Getter: mockGetter, + Connector: mockConnector, } + hclconfig := hclconfig.Config{} + mockEngine := &enginemocks.Engine{} mockEngine.On("ParseConfigWithVariables", mock.Anything, mock.Anything, mock.Anything).Return(nil) - mockEngine.On("ApplyWithVariables", mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) + mockEngine.On("ApplyWithVariables", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&hclconfig, nil) mockEngine.On("GetClients", mock.Anything).Return(clients) mockEngine.On("ResourceCountForType", mock.Anything).Return(0) - bp := resources.Blueprint{} + bp := blueprint.Blueprint{} mockEngine.On("Blueprint").Return(&bp) @@ -92,58 +102,25 @@ func setupRun(t *testing.T, timeout string) (*cobra.Command, *runMocks) { http: mockHTTP, system: mockSystem, connector: mockConnector, + tasks: mockContainer, } - cmd := newRunCmd(mockEngine, mockGetter, mockHTTP, mockSystem, vm, mockConnector, hclog.Default()) + cmd := newRunCmd(mockEngine, mockContainer, mockGetter, mockHTTP, mockSystem, nil, mockConnector, logger.NewTestLogger(t)) cmd.SetOut(bytes.NewBuffer([]byte(""))) return cmd, rm } -func TestRunSetsForceOnGetter(t *testing.T) { +func TestRunSetsForceOnClients(t *testing.T) { rf, rm := setupRun(t, "") + rf.Flags().Set("no-browser", "true") rf.Flags().Set("force-update", "true") err := rf.Execute() assert.NoError(t, err) rm.getter.AssertCalled(t, "SetForce", true) -} - -func TestRunPreflightsSystem(t *testing.T) { - rf, rm := setupRun(t, "") - rf.SetArgs([]string{"/tmp"}) - - err := rf.Execute() - assert.NoError(t, err) - - rm.system.AssertCalled(t, "Preflight") -} - -func TestRunOtherVersionChecksInstalledVersions(t *testing.T) { - version := "v0.0.99" - rf, rm := setupRun(t, "") - rf.SetArgs([]string{"/tmp"}) - rf.Flags().Set("version", version) - - err := rf.Execute() - assert.NoError(t, err) - - rm.vm.AssertCalled(t, "ListInstalledVersions", version) - rm.vm.AssertCalled(t, "GetLatestReleaseURL", version) -} - -func TestRunOtherVersionPromptsInstallWhenNotInstalled(t *testing.T) { - version := "v0.0.99" - rf, rm := setupRun(t, "") - rf.SetArgs([]string{"/tmp"}) - rf.Flags().Set("version", version) - - err := rf.Execute() - assert.NoError(t, err) - - rm.vm.AssertCalled(t, "ListInstalledVersions", version) - rm.vm.AssertCalled(t, "GetLatestReleaseURL", version) + rm.tasks.AssertCalled(t, "SetForce", true) } func TestRunChecksForCertBundle(t *testing.T) { @@ -172,7 +149,7 @@ func TestRunGeneratesCertBundleWhenNotExist(t *testing.T) { testutils.RemoveOn(&rm.connector.Mock, "GetLocalCertBundle") rm.connector.On("GetLocalCertBundle", mock.Anything).Return(nil, fmt.Errorf("boom")).Once() - rm.connector.On("GetLocalCertBundle", mock.Anything).Return(clients.CertBundle{}, nil).Once() + rm.connector.On("GetLocalCertBundle", mock.Anything).Return(&types.CertBundle{}, nil).Once() err := rf.Execute() assert.NoError(t, err) @@ -208,7 +185,7 @@ func TestRunConnectorStartErrorWhenGetCertBundleFails(t *testing.T) { rf.SetArgs([]string{"/tmp"}) testutils.RemoveOn(&rm.connector.Mock, "GetLocalCertBundle") - rm.connector.On("GetLocalCertBundle", mock.Anything).Return(clients.CertBundle{}, nil).Once() + rm.connector.On("GetLocalCertBundle", mock.Anything).Return(&types.CertBundle{}, nil).Once() rm.connector.On("GetLocalCertBundle", mock.Anything).Return(nil, fmt.Errorf("boom")).Once() err := rf.Execute() @@ -224,7 +201,30 @@ func TestRunSetsDestinationFromArgsWhenPresent(t *testing.T) { err := rf.Execute() assert.NoError(t, err) - rm.engine.AssertCalled(t, "ApplyWithVariables", "/tmp", mock.Anything, mock.Anything) + rm.engine.AssertCalled(t, "ApplyWithVariables", mock.Anything, "/tmp", mock.Anything, mock.Anything) +} + +func TestRunSetsVariablesFromFlag(t *testing.T) { + rf, rm := setupRun(t, "") + rf.SetArgs([]string{ + "--var=abc=1234", + "--var='foo=bar'", + "--var=\"erik=smells\"", + "--var=nic=cool=beans", + "/tmp", + }) + + err := rf.Execute() + assert.NoError(t, err) + + args := rm.engine.Calls[0].Arguments[2] + + require.Equal(t, map[string]string{ + "abc": "1234", + "foo": "bar", + "erik": "smells", + "nic": "cool=beans", + }, args) } func TestRunSetsVariablesFileReturnsErrorWhenMissing(t *testing.T) { @@ -249,7 +249,7 @@ func TestRunSetsVariablesFileWhenPresent(t *testing.T) { err = rf.Execute() assert.NoError(t, err) - rm.engine.AssertCalled(t, "ApplyWithVariables", "/tmp", mock.Anything, tmpFile.Name()) + rm.engine.AssertCalled(t, "ApplyWithVariables", mock.Anything, "/tmp", mock.Anything, tmpFile.Name()) } func TestRunSetsDestinationToDownloadedBlueprintFromArgsWhenRemote(t *testing.T) { @@ -259,7 +259,7 @@ func TestRunSetsDestinationToDownloadedBlueprintFromArgsWhenRemote(t *testing.T) err := rf.Execute() assert.NoError(t, err) - rm.engine.AssertCalled(t, "ApplyWithVariables", filepath.Join(utils.JumppadHome(), "blueprints/github.com/shipyard-run/blueprints/vault-k8s"), mock.Anything, mock.Anything) + rm.engine.AssertCalled(t, "ApplyWithVariables", mock.Anything, filepath.Join(utils.JumppadHome(), "blueprints/github.com/shipyard-run/blueprints/vault-k8s"), mock.Anything, mock.Anything) } func TestRunFetchesBlueprint(t *testing.T) { @@ -285,48 +285,6 @@ func TestRunFetchesBlueprintErrorReturnsError(t *testing.T) { assert.Error(t, err) } -func TestRunOpensBrowserWindow(t *testing.T) { - rf, rm := setupRun(t, "") - rf.SetArgs([]string{"/tmp"}) - - err := rf.Execute() - assert.NoError(t, err) - - rm.http.AssertNumberOfCalls(t, "HealthCheckHTTP", 2) - rm.system.AssertNumberOfCalls(t, "OpenBrowser", 2) - - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost", []int{200}, 30*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost2", []int{200}, 30*time.Second) -} - -func TestRunOpensBrowserWindowWithCustomTimeout(t *testing.T) { - rf, rm := setupRun(t, "60s") - rf.SetArgs([]string{"/tmp"}) - - err := rf.Execute() - assert.NoError(t, err) - - rm.http.AssertNumberOfCalls(t, "HealthCheckHTTP", 2) - rm.system.AssertNumberOfCalls(t, "OpenBrowser", 2) - - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost", []int{200}, 60*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost2", []int{200}, 60*time.Second) -} - -func TestRunOpensBrowserWindowWithInvalidTimeout(t *testing.T) { - rf, rm := setupRun(t, "6e") - rf.SetArgs([]string{"/tmp"}) - - err := rf.Execute() - assert.NoError(t, err) - - rm.http.AssertNumberOfCalls(t, "HealthCheckHTTP", 2) - rm.system.AssertNumberOfCalls(t, "OpenBrowser", 2) - - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost", []int{200}, 30*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost2", []int{200}, 30*time.Second) -} - func TestRunOpensBrowserWindowForResources(t *testing.T) { rf, rm := setupRun(t, "") rf.SetArgs([]string{"/tmp"}) @@ -334,53 +292,53 @@ func TestRunOpensBrowserWindowForResources(t *testing.T) { testutils.RemoveOn(&rm.engine.Mock, "ApplyWithVariables") // should open - d := config.NewDocs("test") + d := &docs.Docs{ResourceBase: hcltypes.ResourceBase{Meta: hcltypes.Meta{Name: "test", Type: "docs"}}} d.OpenInBrowser = true // should open - i := config.NewIngress("test") - i.Source.Driver = config.IngressSourceLocal - i.Source.Config.Port = "8080" - i.Source.Config.OpenInBrowser = "/" + i := &ingress.Ingress{ResourceBase: hcltypes.ResourceBase{Meta: hcltypes.Meta{Name: "test", Type: "ingress"}}} + i.Port = 8080 + i.OpenInBrowser = "/" // should open - c := config.NewContainer("test") - c.Ports = []config.Port{config.Port{Host: "8080", OpenInBrowser: "https://test.container.jumppad.dev:8080"}} + c := &container.Container{ResourceBase: hcltypes.ResourceBase{Meta: hcltypes.Meta{Name: "test", Type: "container"}}} + c.Ports = []container.Port{container.Port{Host: "8080", OpenInBrowser: "https://test.container.jumppad.dev:8080"}} // should not be opened - c2 := config.NewContainer("test2") - c2.Ports = []config.Port{config.Port{OpenInBrowser: ""}} + c2 := &container.Container{} + c2.Ports = []container.Port{container.Port{OpenInBrowser: ""}} // should not be opened - i2 := config.NewIngress("test") - i.Source.Driver = config.IngressSourceLocal - i2.Source.Config.Port = "8080" + i2 := &ingress.Ingress{} + i2.Port = 8080 // should not be opened - d2 := config.NewDocs("test2") + d2 := &docs.Docs{} // should be opened - n1 := config.NewNomadCluster("test") + n1 := &nomad.NomadCluster{ResourceBase: hcltypes.ResourceBase{Meta: hcltypes.Meta{Name: "test", Type: "nomad_cluster"}}} n1.OpenInBrowser = true - nomadConfig, _ := utils.GetClusterConfig("nomad_cluster.test") + n1.APIPort = 4646 + + hclconfig := hclconfig.Config{} + hclconfig.Resources = []hcltypes.Resource{d, i, c, d2, i2, c2, n1} - rm.engine.On("ApplyWithVariables", mock.Anything, mock.Anything, mock.Anything).Return( - []config.Resource{d, i, c, d2, i2, c2, n1}, + testutils.RemoveOn(&rm.engine.Mock, "ApplyWithVariables") + rm.engine.On("ApplyWithVariables", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( + &hclconfig, nil, ) err := rf.Execute() assert.NoError(t, err) - rm.http.AssertNumberOfCalls(t, "HealthCheckHTTP", 6) - rm.system.AssertNumberOfCalls(t, "OpenBrowser", 6) + rm.http.AssertNumberOfCalls(t, "HealthCheckHTTP", 4) + rm.system.AssertNumberOfCalls(t, "OpenBrowser", 4) - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://test.ingress.jumppad.dev:8080/", []int{200}, 30*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", "https://test.container.jumppad.dev:8080", []int{200}, 30*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost", []int{200}, 30*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://localhost2", []int{200}, 30*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", "http://test.docs.jumppad.dev:80", []int{200}, 30*time.Second) - rm.http.AssertCalled(t, "HealthCheckHTTP", fmt.Sprintf("http://server.test.nomad-cluster.jumppad.dev:%d/", nomadConfig.APIPort), []int{200}, 30*time.Second) + rm.http.AssertCalled(t, "HealthCheckHTTP", "http://test.ingress.local.jmpd.in:8080/", "", map[string][]string{}, "", []int{200}, 30*time.Second) + rm.http.AssertCalled(t, "HealthCheckHTTP", "https://test.container.jumppad.dev:8080", "", map[string][]string{}, "", []int{200}, 30*time.Second) + rm.http.AssertCalled(t, "HealthCheckHTTP", "http://test.docs.local.jmpd.in:80", "", map[string][]string{}, "", []int{200}, 30*time.Second) + rm.http.AssertCalled(t, "HealthCheckHTTP", "http://server.test.nomad-cluster.local.jmpd.in:4646/", "", map[string][]string{}, "", []int{200}, 30*time.Second) } func TestRunDoesNotOpensBrowserWindowWhenCheckError(t *testing.T) { @@ -388,7 +346,7 @@ func TestRunDoesNotOpensBrowserWindowWhenCheckError(t *testing.T) { rf.SetArgs([]string{"/tmp"}) testutils.RemoveOn(&rm.http.Mock, "HealthCheckHTTP") - rm.http.On("HealthCheckHTTP", mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("boom")) + rm.http.On("HealthCheckHTTP", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("boom")) err := rf.Execute() assert.NoError(t, err) diff --git a/pkg/clients/getter/getter.go b/pkg/clients/getter/getter.go index 59c4a537..a1e00cc8 100644 --- a/pkg/clients/getter/getter.go +++ b/pkg/clients/getter/getter.go @@ -10,6 +10,7 @@ import ( // Getter is an interface which defines interations for // downloading remote folders +//go:generate mockery --name Getter --filename getter.go type Getter interface { Get(uri, dst string) error SetForce(force bool) diff --git a/pkg/clients/getter/mocks/getter.go b/pkg/clients/getter/mocks/getter.go new file mode 100644 index 00000000..746c3307 --- /dev/null +++ b/pkg/clients/getter/mocks/getter.go @@ -0,0 +1,47 @@ +// Code generated by mockery v2.42.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// Getter is an autogenerated mock type for the Getter type +type Getter struct { + mock.Mock +} + +// Get provides a mock function with given fields: uri, dst +func (_m *Getter) Get(uri string, dst string) error { + ret := _m.Called(uri, dst) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { + r0 = rf(uri, dst) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SetForce provides a mock function with given fields: force +func (_m *Getter) SetForce(force bool) { + _m.Called(force) +} + +// NewGetter creates a new instance of Getter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *Getter { + mock := &Getter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/clients/system/mocks/system.go b/pkg/clients/system/mocks/system.go new file mode 100644 index 00000000..d8960450 --- /dev/null +++ b/pkg/clients/system/mocks/system.go @@ -0,0 +1,120 @@ +// Code generated by mockery v2.42.3. DO NOT EDIT. + +package mocks + +import ( + io "io" + + mock "github.com/stretchr/testify/mock" +) + +// System is an autogenerated mock type for the System type +type System struct { + mock.Mock +} + +// CheckVersion provides a mock function with given fields: _a0 +func (_m *System) CheckVersion(_a0 string) (string, bool) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for CheckVersion") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func(string) (string, bool)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) bool); ok { + r1 = rf(_a0) + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// OpenBrowser provides a mock function with given fields: _a0 +func (_m *System) OpenBrowser(_a0 string) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for OpenBrowser") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Preflight provides a mock function with given fields: +func (_m *System) Preflight() (string, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Preflight") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func() (string, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PromptInput provides a mock function with given fields: in, out, message +func (_m *System) PromptInput(in io.Reader, out io.Writer, message string) string { + ret := _m.Called(in, out, message) + + if len(ret) == 0 { + panic("no return value specified for PromptInput") + } + + var r0 string + if rf, ok := ret.Get(0).(func(io.Reader, io.Writer, string) string); ok { + r0 = rf(in, out, message) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// NewSystem creates a new instance of System. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewSystem(t interface { + mock.TestingT + Cleanup(func()) +}) *System { + mock := &System{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/clients/system/system.go b/pkg/clients/system/system.go index 3937f2a5..02b2247e 100644 --- a/pkg/clients/system/system.go +++ b/pkg/clients/system/system.go @@ -23,6 +23,8 @@ const ( ) // System handles interactions between Shipyard and the OS +// +//go:generate mockery --name System --filename system.go type System interface { OpenBrowser(string) error Preflight() (string, error)