Skip to content

Commit

Permalink
Fix flaky lifecycle test (#2486)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Mar 20, 2024
1 parent bf797d1 commit 56e8cf8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
30 changes: 20 additions & 10 deletions lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/jfrog/gofrog/io"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
configUtils "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/jfrog/jfrog-client-go/lifecycle/services"
clientUtils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"net/http"
Expand Down Expand Up @@ -156,9 +158,9 @@ func assertExpectedArtifacts(t *testing.T, specFileName string, expected []strin
}

func uploadBuilds(t *testing.T) func() {
uploadBuild(t, tests.UploadDevSpecA, tests.LcBuildName1, number1, false)
uploadBuild(t, tests.UploadDevSpecB, tests.LcBuildName2, number2, false)
uploadBuild(t, tests.UploadDevSpecC, tests.LcBuildName3, number3, true)
uploadBuildWithArtifacts(t, tests.UploadDevSpecA, tests.LcBuildName1, number1)
uploadBuildWithArtifacts(t, tests.UploadDevSpecB, tests.LcBuildName2, number2)
uploadBuildWithDeps(t, tests.LcBuildName3, number3)
return func() {
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.LcBuildName1, artHttpDetails)
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.LcBuildName2, artHttpDetails)
Expand Down Expand Up @@ -309,16 +311,24 @@ func remoteDeleteReleaseBundle(t *testing.T, lcManager *lifecycle.LifecycleServi
}
*/

func uploadBuild(t *testing.T, specFileName, buildName, buildNumber string, uploadAsDependencies bool) {
func uploadBuildWithArtifacts(t *testing.T, specFileName, buildName, buildNumber string) {
specFile, err := tests.CreateSpec(specFileName)
assert.NoError(t, err)

if uploadAsDependencies {
runRt(t, "upload", "--spec="+specFile)
assert.NoError(t, lcCli.WithoutCredentials().Exec("rt", "bad", buildName, buildNumber, tests.RtDevRepo+"/c*.in", "--from-rt"))
} else {
runRt(t, "upload", "--spec="+specFile, "--build-name="+buildName, "--build-number="+buildNumber)
}
runRt(t, "upload", "--spec="+specFile, "--build-name="+buildName, "--build-number="+buildNumber)
runRt(t, "build-publish", buildName, buildNumber)
}

func uploadBuildWithDeps(t *testing.T, buildName, buildNumber string) {
err := fileutils.CreateDirIfNotExist(tests.Out)
assert.NoError(t, err)

randFile, err := io.CreateRandFile(filepath.Join(tests.Out, "dep-file"), 1000)
assert.NoError(t, err)

runRt(t, "upload", randFile.Name(), tests.RtDevRepo, "--flat")
assert.NoError(t, lcCli.WithoutCredentials().Exec("rt", "bad", buildName, buildNumber, tests.RtDevRepo+"/dep-file", "--from-rt"))

runRt(t, "build-publish", buildName, buildNumber)
}

Expand Down
10 changes: 0 additions & 10 deletions testdata/filespecs/upload_dev_spec_c.json

This file was deleted.

9 changes: 2 additions & 7 deletions utils/tests/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ const (
UploadDevSpec = "upload_dev_spec.json"
UploadDevSpecA = "upload_dev_spec_a.json"
UploadDevSpecB = "upload_dev_spec_b.json"
UploadDevSpecC = "upload_dev_spec_c.json"
UploadEmptyDirs = "upload_empty_dir_spec.json"
UploadExcludeIncludeDir = "upload_exclude_include_dir.json"
UploadExcludeIncludeDirAntPattern = "upload_exclude_include_dir_ant_pattern.json"
Expand Down Expand Up @@ -2103,9 +2102,7 @@ func GetExpectedBackwardCompatibleLifecycleArtifacts() []string {
RtDevRepo + "/b1.in",
RtDevRepo + "/b2.in",
RtDevRepo + "/b3.in",
RtDevRepo + "/c1.in",
RtDevRepo + "/c2.in",
RtDevRepo + "/c3.in",
RtDevRepo + "/dep-file",
}
}

Expand All @@ -2132,9 +2129,7 @@ func GetExpectedLifecycleArtifacts() []string {
RtProdRepo1 + "/b1.in",
RtProdRepo1 + "/b2.in",
RtProdRepo1 + "/b3.in",
RtProdRepo1 + "/c1.in",
RtProdRepo1 + "/c2.in",
RtProdRepo1 + "/c3.in",
RtProdRepo1 + "/dep-file",
}
}

Expand Down

0 comments on commit 56e8cf8

Please sign in to comment.