github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/step/step_validate_test.go (about) 1 // +build unit 2 3 package step_test 4 5 import ( 6 "testing" 7 8 step2 "github.com/jenkins-x/jx/v2/pkg/cmd/opts/step" 9 "github.com/jenkins-x/jx/v2/pkg/cmd/step" 10 "github.com/jenkins-x/jx/v2/pkg/cmd/testhelpers" 11 12 "github.com/jenkins-x/jx/v2/pkg/cmd/opts" 13 "github.com/jenkins-x/jx/v2/pkg/config" 14 gits_test "github.com/jenkins-x/jx/v2/pkg/gits/mocks" 15 helm_test "github.com/jenkins-x/jx/v2/pkg/helm/mocks" 16 "github.com/stretchr/testify/assert" 17 ) 18 19 func TestStepValidate(t *testing.T) { 20 t.Parallel() 21 AssertValidateWorks(t, &step.StepValidateOptions{StepOptions: step2.StepOptions{CommonOptions: &opts.CommonOptions{}}}) 22 AssertValidateWorks(t, &step.StepValidateOptions{StepOptions: step2.StepOptions{CommonOptions: &opts.CommonOptions{}}, MinimumJxVersion: "0.0.1"}) 23 24 AssertValidateFails(t, &step.StepValidateOptions{StepOptions: step2.StepOptions{CommonOptions: &opts.CommonOptions{}}, MinimumJxVersion: "100.0.1"}) 25 26 // lets check the test data has a valid addon 27 projectDir := "test_data/project_with_kubeless" 28 cfg, fileName, err := config.LoadProjectConfig(projectDir) 29 assert.Nil(t, err, "Failed to load project config %s", fileName) 30 assert.NotEmpty(t, cfg.Addons, "Failed to find addons in project config %s", fileName) 31 32 AssertValidateFails(t, &step.StepValidateOptions{StepOptions: step2.StepOptions{CommonOptions: &opts.CommonOptions{}}, Dir: projectDir}) 33 } 34 35 func AssertValidateWorks(t *testing.T, options *step.StepValidateOptions) { 36 //options.Out = tests.Output() 37 //options.Factory = cmd_mocks.NewMockFactory() 38 testhelpers.ConfigureTestOptions(options.CommonOptions, gits_test.NewMockGitter(), helm_test.NewMockHelmer()) 39 err := options.Run() 40 assert.NoError(t, err, "Command failed: %#v", options) 41 } 42 43 func AssertValidateFails(t *testing.T, options *step.StepValidateOptions) { 44 //options.Out = tests.Output() 45 //options.Factory = cmd_mocks.NewMockFactory() 46 testhelpers.ConfigureTestOptions(options.CommonOptions, gits_test.NewMockGitter(), helm_test.NewMockHelmer()) 47 err := options.Run() 48 assert.NotNil(t, err, "Command should have failed: %#v", options) 49 }