From 50152fcd0a8edd3a51c5145aa6588c0262428b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Falvai?= Date: Wed, 4 Dec 2024 09:44:22 +0100 Subject: [PATCH] Move some tests to integration tests --- _tests/integration/plugins_test.go | 26 ++++ {cli => _tests/integration}/run_test.go | 173 ++++++++++++------------ _tests/integration/tools_test.go | 72 ++++++++++ cli/run.go | 4 +- plugins/git_test.go | 51 ------- plugins/install_test.go | 28 ---- tools/tools_test.go | 61 --------- 7 files changed, 188 insertions(+), 227 deletions(-) create mode 100644 _tests/integration/plugins_test.go rename {cli => _tests/integration}/run_test.go (90%) create mode 100644 _tests/integration/tools_test.go diff --git a/_tests/integration/plugins_test.go b/_tests/integration/plugins_test.go new file mode 100644 index 000000000..f1d03cccb --- /dev/null +++ b/_tests/integration/plugins_test.go @@ -0,0 +1,26 @@ +package integration + +import ( + "testing" + + "github.com/bitrise-io/bitrise/plugins" + "github.com/stretchr/testify/require" +) + + + +const examplePluginGitURL = "https://github.com/bitrise-io/bitrise-plugins-example.git" + +func TestDownloadPluginBin(t *testing.T) { + t.Log("example plugin bin - specific version") + { + _, _, err := plugins.InstallPlugin(examplePluginGitURL, "0.9.0") + require.NoError(t, err) + } + + t.Log("example plugin bin - latest version") + { + _, _, err := plugins.InstallPlugin(examplePluginGitURL, "") + require.NoError(t, err) + } +} diff --git a/cli/run_test.go b/_tests/integration/run_test.go similarity index 90% rename from cli/run_test.go rename to _tests/integration/run_test.go index b6debecca..b8f08fff1 100644 --- a/cli/run_test.go +++ b/_tests/integration/run_test.go @@ -1,4 +1,4 @@ -package cli +package integration import ( "bytes" @@ -12,6 +12,7 @@ import ( cliAnalytics "github.com/bitrise-io/bitrise/analytics" "github.com/bitrise-io/bitrise/bitrise" + "github.com/bitrise-io/bitrise/cli" "github.com/bitrise-io/bitrise/configs" "github.com/bitrise-io/bitrise/log" "github.com/bitrise-io/bitrise/models" @@ -56,9 +57,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "skip_if_empty"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "skip_if_empty"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 1, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -97,9 +98,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "skip_if_empty"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "skip_if_empty"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 1, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -157,9 +158,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 4, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -223,9 +224,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 5, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -268,9 +269,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 1, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -331,9 +332,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} - runner := NewWorkflowRunner(runConfig, nil) - _, err = runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} + runner := cli.NewWorkflowRunner(runConfig, nil) + _, err = runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) } @@ -374,9 +375,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} - runner := NewWorkflowRunner(runConfig, nil) - _, err = runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} + runner := cli.NewWorkflowRunner(runConfig, nil) + _, err = runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) } @@ -419,9 +420,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} - runner := NewWorkflowRunner(runConfig, nil) - _, err = runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} + runner := cli.NewWorkflowRunner(runConfig, nil) + _, err = runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) } @@ -470,9 +471,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} - runner := NewWorkflowRunner(runConfig, nil) - _, err = runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} + runner := cli.NewWorkflowRunner(runConfig, nil) + _, err = runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) } } @@ -771,9 +772,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} - runner := NewWorkflowRunner(runConfig, nil) - res, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test", Secrets: inventory.Envs} + runner := cli.NewWorkflowRunner(runConfig, nil) + res, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.False(t, res.IsBuildFailed()) }) @@ -805,9 +806,9 @@ func Test0Steps1Workflows(t *testing.T) { require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "zero_steps"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err = runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "zero_steps"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err = runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 0, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -851,9 +852,9 @@ func Test0Steps3WorkflowsBeforeAfter(t *testing.T) { require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err = runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err = runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 0, len(buildRunResults.SuccessSteps)) @@ -910,9 +911,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "trivial_fail"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err = runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "trivial_fail"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err = runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 3, len(buildRunResults.SuccessSteps)) @@ -993,9 +994,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 3, len(buildRunResults.SuccessSteps)) require.Equal(t, 2, len(buildRunResults.FailedSteps)) @@ -1101,9 +1102,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 3, len(buildRunResults.SuccessSteps)) require.Equal(t, 1, len(buildRunResults.FailedSteps)) @@ -1158,9 +1159,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 3, len(buildRunResults.SuccessSteps)) require.Equal(t, 1, len(buildRunResults.FailedSteps)) @@ -1193,9 +1194,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 1, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -1251,9 +1252,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 1, len(buildRunResults.SuccessSteps)) require.Equal(t, 1, len(buildRunResults.FailedSteps)) @@ -1302,9 +1303,9 @@ workflows: require.Equal(t, 0, len(warnings)) require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 1, len(buildRunResults.SuccessSteps)) @@ -1368,9 +1369,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 2, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -1429,9 +1430,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 2, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -1478,9 +1479,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 1, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -1535,9 +1536,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 2, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -1596,9 +1597,10 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "out-test"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "out-test"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) + require.NoError(t, err) require.Equal(t, 0, len(buildRunResults.SkippedSteps)) require.Equal(t, 3, len(buildRunResults.SuccessSteps)) require.Equal(t, 1, len(buildRunResults.FailedSteps)) @@ -1646,9 +1648,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.NoError(t, err) require.Equal(t, 2, len(buildRunResults.SuccessSteps)) require.Equal(t, 0, len(buildRunResults.FailedSteps)) @@ -1700,9 +1702,9 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "test"} - runner := NewWorkflowRunner(runConfig, nil) - buildRunResults, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test"} + runner := cli.NewWorkflowRunner(runConfig, nil) + buildRunResults, err := runner.RunWorkflows(noOpTracker{}) require.Equal(t, nil, err) require.Equal(t, 0, len(buildRunResults.SkippedSteps)) require.Equal(t, 2, len(buildRunResults.SuccessSteps)) @@ -1730,9 +1732,10 @@ workflows: require.NoError(t, configs.InitPaths()) - runConfig := RunConfig{Config: config, Workflow: "target"} - runner := NewWorkflowRunner(runConfig, nil) - results, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "target"} + runner := cli.NewWorkflowRunner(runConfig, nil) + results, err := runner.RunWorkflows(noOpTracker{}) + require.NoError(t, err) require.Equal(t, 1, len(results.StepmanUpdates)) } @@ -1823,9 +1826,9 @@ route_map: opts.Writer = &buf log.InitGlobalLogger(opts) - runConfig := RunConfig{Config: config, Workflow: "test"} - runner := NewWorkflowRunner(runConfig, nil) - _, err := runner.runWorkflows(noOpTracker{}) + runConfig := cli.RunConfig{Config: config, Workflow: "test"} + runner := cli.NewWorkflowRunner(runConfig, nil) + _, err := runner.RunWorkflows(noOpTracker{}) opts.Writer = origWiter // Then diff --git a/_tests/integration/tools_test.go b/_tests/integration/tools_test.go new file mode 100644 index 000000000..38ec60e5c --- /dev/null +++ b/_tests/integration/tools_test.go @@ -0,0 +1,72 @@ +package integration + +import ( + "os" + "os/exec" + "path/filepath" + "runtime" + "testing" + + "github.com/bitrise-io/bitrise/configs" + "github.com/bitrise-io/bitrise/tools" + "github.com/bitrise-io/go-utils/command" + "github.com/stretchr/testify/require" +) + + +func TestMoveFileDifferentDevices(t *testing.T) { + require.True(t, runtime.GOOS == "linux" || runtime.GOOS == "darwin") + + ramdiskPath := "" + ramdiskName := "RAMDISK" + volumeName := "" + if runtime.GOOS == "linux" { + tmpDir := t.TempDir() + + ramdiskPath = tmpDir + require.NoError(t, exec.Command("mount", "-t", "tmpfs", "-o", "size=12m", "tmpfs", ramdiskPath).Run()) + } else if runtime.GOOS == "darwin" { + out, err := command.New("hdiutil", "attach", "-nomount", "ram://64").RunAndReturnTrimmedCombinedOutput() + require.NoError(t, err) + + volumeName = out + require.NoError(t, exec.Command("diskutil", "erasevolume", "MS-DOS", ramdiskName, volumeName).Run()) + + ramdiskPath = "/Volumes/" + ramdiskName + } + + filename := "test.tmp" + srcPath := filepath.Join(os.TempDir(), filename) + _, err := os.Create(srcPath) + require.NoError(t, err) + + dstPath := filepath.Join(ramdiskPath, filename) + require.NoError(t, tools.MoveFile(srcPath, dstPath)) + + info, err := os.Stat(dstPath) + require.NoError(t, err) + require.False(t, info.IsDir()) + + if runtime.GOOS == "linux" { + require.NoError(t, exec.Command("umount", ramdiskPath).Run()) + require.NoError(t, os.RemoveAll(ramdiskPath)) + } else if runtime.GOOS == "darwin" { + require.NoError(t, exec.Command("hdiutil", "detach", volumeName).Run()) + } +} + +func TestStepmanJSONStepLibStepInfo(t *testing.T) { + // setup + require.NoError(t, configs.InitPaths()) + + // Valid params -- Err should empty, output filled + require.Equal(t, nil, tools.StepmanSetup("https://github.com/bitrise-io/bitrise-steplib")) + + info, err := tools.StepmanStepInfo("https://github.com/bitrise-io/bitrise-steplib", "script", "0.9.0") + require.NoError(t, err) + require.NotEqual(t, "", info.JSON()) + + // Invalid params -- Err returned, output is invalid + _, err = tools.StepmanStepInfo("https://github.com/bitrise-io/bitrise-steplib", "script", "2.x") + require.Error(t, err) +} diff --git a/cli/run.go b/cli/run.go index cf4440f1b..fda790875 100644 --- a/cli/run.go +++ b/cli/run.go @@ -224,7 +224,7 @@ func (r WorkflowRunner) RunWorkflowsWithSetupAndCheckForUpdate() (int, error) { }() } - if buildRunResults, err := r.runWorkflows(globalTracker); err != nil { + if buildRunResults, err := r.RunWorkflows(globalTracker); err != nil { return 1, fmt.Errorf("failed to run workflow: %s", err) } else if buildRunResults.IsBuildFailed() { return buildRunResults.ExitCode(), errWorkflowRunFailed @@ -237,7 +237,7 @@ func (r WorkflowRunner) RunWorkflowsWithSetupAndCheckForUpdate() (int, error) { return 0, nil } -func (r WorkflowRunner) runWorkflows(tracker analytics.Tracker) (models.BuildRunResultsModel, error) { +func (r WorkflowRunner) RunWorkflows(tracker analytics.Tracker) (models.BuildRunResultsModel, error) { startTime := time.Now() // Register run modes diff --git a/plugins/git_test.go b/plugins/git_test.go index 14d2956c9..06bd5d384 100644 --- a/plugins/git_test.go +++ b/plugins/git_test.go @@ -1,10 +1,8 @@ package plugins import ( - "os" "testing" - "github.com/bitrise-io/go-utils/pathutil" "github.com/stretchr/testify/require" ) @@ -38,52 +36,3 @@ func TestFilterVersionTags(t *testing.T) { require.Equal(t, "1.0.0", versionTags[0].String()) } } - -func TestClonePluginSrc(t *testing.T) { - t.Log("example plugin - latest version") - { - pluginSource := examplePluginGitURL - versionTag := "" - destinationDir, err := pathutil.NormalizedOSTempDirPath("TestClonePluginSrc") - require.NoError(t, err) - - exist, err := pathutil.IsPathExists(destinationDir) - require.NoError(t, err) - if exist { - err := os.RemoveAll(destinationDir) - require.NoError(t, err) - } - - version, err := GitCloneAndCheckoutVersionOrLatestVersion(destinationDir, pluginSource, versionTag) - require.NoError(t, err) - require.NotNil(t, version) - - exist, err = pathutil.IsPathExists(destinationDir) - require.NoError(t, err) - require.Equal(t, true, exist) - } - - t.Log("example plugin - 0.9.0 version") - { - pluginSource := examplePluginGitURL - versionTag := "0.9.0" - destinationDir, err := pathutil.NormalizedOSTempDirPath("TestClonePluginSrc") - require.NoError(t, err) - - exist, err := pathutil.IsPathExists(destinationDir) - require.NoError(t, err) - if exist { - err := os.RemoveAll(destinationDir) - require.NoError(t, err) - } - - version, err := GitCloneAndCheckoutVersionOrLatestVersion(destinationDir, pluginSource, versionTag) - require.NoError(t, err) - require.NotNil(t, version) - require.Equal(t, "0.9.0", version) - - exist, err = pathutil.IsPathExists(destinationDir) - require.NoError(t, err) - require.Equal(t, true, exist) - } -} diff --git a/plugins/install_test.go b/plugins/install_test.go index 5de87bb3b..b1daec4e1 100644 --- a/plugins/install_test.go +++ b/plugins/install_test.go @@ -1,17 +1,12 @@ package plugins import ( - "os" - "path/filepath" "testing" - "github.com/bitrise-io/go-utils/pathutil" ver "github.com/hashicorp/go-version" "github.com/stretchr/testify/require" ) -const examplePluginGitURL = "https://github.com/bitrise-io/bitrise-plugins-example.git" -const testPluginBinURL = "https://github.com/bitrise-io/bitrise-plugins-step/releases/download/0.10.4/bitrise-plugins-step-Darwin-arm64" func TestIsLocalURL(t *testing.T) { t.Log("local url - absolute") @@ -196,30 +191,7 @@ func TestValidateRequirements(t *testing.T) { } } -func TestDownloadPluginBin(t *testing.T) { - t.Log("example plugin bin - ") - { - destinationDir, err := pathutil.NormalizedOSTempDirPath("TestDownloadPluginBin") - require.NoError(t, err) - - exist, err := pathutil.IsPathExists(destinationDir) - require.NoError(t, err) - if exist { - err := os.RemoveAll(destinationDir) - require.NoError(t, err) - } - - require.NoError(t, os.MkdirAll(destinationDir, 0755)) - destinationPth := filepath.Join(destinationDir, "example") - - require.NoError(t, downloadPluginBin(testPluginBinURL, destinationPth)) - - exist, err = pathutil.IsPathExists(destinationPth) - require.NoError(t, err) - require.Equal(t, true, exist) - } -} func Test_isSourceURIChanged(t *testing.T) { for _, tt := range []struct { diff --git a/tools/tools_test.go b/tools/tools_test.go index b7b56a077..2e7f007c2 100644 --- a/tools/tools_test.go +++ b/tools/tools_test.go @@ -2,15 +2,11 @@ package tools import ( "os" - "os/exec" "path/filepath" - "runtime" "testing" "github.com/bitrise-io/envman/models" - "github.com/bitrise-io/bitrise/configs" - "github.com/bitrise-io/go-utils/command" "github.com/bitrise-io/go-utils/pathutil" "github.com/stretchr/testify/require" ) @@ -30,63 +26,6 @@ func TestMoveFile(t *testing.T) { require.NoError(t, os.Remove(dstPath)) } -func TestMoveFileDifferentDevices(t *testing.T) { - require.True(t, runtime.GOOS == "linux" || runtime.GOOS == "darwin") - - ramdiskPath := "" - ramdiskName := "RAMDISK" - volumeName := "" - if runtime.GOOS == "linux" { - tmpDir := t.TempDir() - - ramdiskPath = tmpDir - require.NoError(t, exec.Command("mount", "-t", "tmpfs", "-o", "size=12m", "tmpfs", ramdiskPath).Run()) - } else if runtime.GOOS == "darwin" { - out, err := command.New("hdiutil", "attach", "-nomount", "ram://64").RunAndReturnTrimmedCombinedOutput() - require.NoError(t, err) - - volumeName = out - require.NoError(t, exec.Command("diskutil", "erasevolume", "MS-DOS", ramdiskName, volumeName).Run()) - - ramdiskPath = "/Volumes/" + ramdiskName - } - - filename := "test.tmp" - srcPath := filepath.Join(os.TempDir(), filename) - _, err := os.Create(srcPath) - require.NoError(t, err) - - dstPath := filepath.Join(ramdiskPath, filename) - require.NoError(t, MoveFile(srcPath, dstPath)) - - info, err := os.Stat(dstPath) - require.NoError(t, err) - require.False(t, info.IsDir()) - - if runtime.GOOS == "linux" { - require.NoError(t, exec.Command("umount", ramdiskPath).Run()) - require.NoError(t, os.RemoveAll(ramdiskPath)) - } else if runtime.GOOS == "darwin" { - require.NoError(t, exec.Command("hdiutil", "detach", volumeName).Run()) - } -} - -func TestStepmanJSONStepLibStepInfo(t *testing.T) { - // setup - require.NoError(t, configs.InitPaths()) - - // Valid params -- Err should empty, output filled - require.Equal(t, nil, StepmanSetup("https://github.com/bitrise-io/bitrise-steplib")) - - info, err := StepmanStepInfo("https://github.com/bitrise-io/bitrise-steplib", "script", "0.9.0") - require.NoError(t, err) - require.NotEqual(t, "", info.JSON()) - - // Invalid params -- Err returned, output is invalid - info, err = StepmanStepInfo("https://github.com/bitrise-io/bitrise-steplib", "script", "2.x") - require.Error(t, err) -} - func TestEnvmanJSONPrint(t *testing.T) { // Initialized envstore -- Err should empty, output filled testDirPth, err := pathutil.NormalizedOSTempDirPath("test_env_store")