Skip to content

Commit

Permalink
Run tests on local Artifactory (#1375)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino authored Jan 17, 2022
1 parent f4cc315 commit ad964a9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,24 @@ jobs:
env:
GRADLE_OPTS: -Dorg.gradle.daemon=false
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
- name: Setup Artifactory
run: |
go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest
~/go/bin/local-rt-setup
env:
RTLIC: ${{secrets.RTLIC}}
GOPROXY: direct
if: ${{ matrix.suite != 'distribution' && matrix.suite != 'xray' }}

- name: Install npm
uses: actions/setup-node@v2
Expand Down Expand Up @@ -78,8 +87,13 @@ jobs:
- name: Run go vet
run: go vet -v ./...

- name: Run tests
- name: Run Artifactory / Build tools tests
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.${{ matrix.suite }}=true --ci.runId=${{ runner.os }}-${{ matrix.suite }}
if: ${{ matrix.suite != 'distribution' && matrix.suite != 'xray' }}

- name: Run Distribution / Xray tests
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.${{ matrix.suite }}=true --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.user=${{ secrets.PLATFORM_USER }} --ci.runId=${{ runner.os }}-${{ matrix.suite }}
if: ${{ matrix.suite == 'distribution' || matrix.suite == 'xray' }}

Docker-tests:
if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push'
Expand All @@ -95,7 +109,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Run Docker tests
run: go test -v -timeout 0 --test.docker=true --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --rt.dockerRepoDomain=ecosysjfrog-docker-virtual.jfrog.io --rt.dockerVirtualRepo=docker-virtual --rt.DockerLocalRepo=docker-local --rt.dockerRemoteRepo=docker-remote
run: go test -v -timeout 0 --test.docker=true --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --rt.dockerRepoDomain=${{ secrets.CONTAINER_REGISTRY }} --rt.dockerVirtualRepo=${{ secrets.DOCKER_VIRTUAL }} --rt.dockerLocalRepo=${{ secrets.DOCKER_LOCAL }} --rt.dockerRemoteRepo=${{ secrets.DOCKER_REMOTE }} --rt.dockerPromoteLocalRepo=${{ secrets.DOCKER_PROMOTE_LOCAL }}

Scripts-tests:
name: scripts (${{ matrix.os }})
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ build/chocolatey/v2/tools/LICENSE

# npm build files
node_modules

# Gradle
.gradle
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ In addition to [general optional flags](#Usage) you _must_ use the following doc

- On Linux machines, [Podman](https://podman.io/) tests will be running, so make sure it's available in the local path.

| Flag | Description |
| ----------------------- | ------------------------------------------- |
| `-rt.dockerRepoDomain` | Artifactory Docker registry domain. |
| `-rt.dockerVirtualRepo` | Artifactory Docker virtual repository name. |
| `-rt.dockerRemoteRepo` | Artifactory Docker remote repository name. |
| `-rt.DockerLocalRepo` | Artifactory Docker local repository name. |
| Flag | Description |
|------------------------------|----------------------------------------------------------------|
| `-rt.dockerRepoDomain` | Artifactory Docker registry domain. |
| `-rt.dockerVirtualRepo` | Artifactory Docker virtual repository name. |
| `-rt.dockerRemoteRepo` | Artifactory Docker remote repository name. |
| `-rt.dockerLocalRepo` | Artifactory Docker local repository name. |
| `-rt.dockerPromoteLocalRepo` | Artifactory Docker local repository name - Used for promotion. |

##### Examples

Expand Down
4 changes: 2 additions & 2 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
func InitDockerTests() {
initArtifactoryCli()
cleanUpOldBuilds()
inttestutils.CleanUpOldImages(serverDetails, artHttpDetails)
inttestutils.CleanUpOldImages(serverDetails)
cleanUpOldRepositories()
tests.AddTimestampToGlobalVars()
createRequiredRepos()
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestDockerPromote(t *testing.T) {
assert.NoError(t, err)

// Promote image
runRt(t, "docker-promote", tests.DockerImageName, *tests.DockerLocalRepo, tests.DockerRepo, "--source-tag=1", "--target-tag=2", "--target-docker-image=docker-target-image", "--copy")
runRt(t, "docker-promote", tests.DockerImageName, *tests.DockerLocalRepo, *tests.DockerPromoteLocalRepo, "--source-tag=1", "--target-tag=2", "--target-docker-image=docker-target-image", "--copy")

// Verify image in source
imagePath := path.Join(*tests.DockerLocalRepo, tests.DockerImageName, "1") + "/"
Expand Down
28 changes: 15 additions & 13 deletions inttestutils/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,24 @@ func ContainerTestCleanup(t *testing.T, serverDetails *config.ServerDetails, art

func getAllImagesNames(serverDetails *config.ServerDetails) ([]string, error) {
var imageNames []string
prefix := *tests.DockerLocalRepo + "/"
specFile := spec.NewBuilder().Pattern(prefix + tests.DockerImageName + "*").IncludeDirs(true).BuildSpec()
searchCmd := generic.NewSearchCommand()
searchCmd.SetServerDetails(serverDetails).SetSpec(specFile)
reader, err := searchCmd.Search()
if err != nil {
return nil, err
for _, repo := range []string{*tests.DockerLocalRepo, *tests.DockerPromoteLocalRepo} {
prefix := repo + "/"
specFile := spec.NewBuilder().Pattern(prefix + tests.DockerImageName + "*").IncludeDirs(true).BuildSpec()
searchCmd := generic.NewSearchCommand()
searchCmd.SetServerDetails(serverDetails).SetSpec(specFile)
reader, err := searchCmd.Search()
if err != nil {
return nil, err
}
defer reader.Close()
for searchResult := new(utils.SearchResult); reader.NextRecord(searchResult) == nil; searchResult = new(utils.SearchResult) {
imageNames = append(imageNames, strings.TrimPrefix(searchResult.Path, prefix))
}
}
defer reader.Close()
for searchResult := new(utils.SearchResult); reader.NextRecord(searchResult) == nil; searchResult = new(utils.SearchResult) {
imageNames = append(imageNames, strings.TrimPrefix(searchResult.Path, prefix))
}
return imageNames, err
return imageNames, nil
}

func CleanUpOldImages(serverDetails *config.ServerDetails, artHttpDetails httputils.HttpClientDetails) {
func CleanUpOldImages(serverDetails *config.ServerDetails) {
getActualItems := func() ([]string, error) { return getAllImagesNames(serverDetails) }
deleteItem := func(imageName string) {
deleteSpec := spec.NewBuilder().Pattern(path.Join(*tests.DockerLocalRepo, imageName)).BuildSpec()
Expand Down
5 changes: 0 additions & 5 deletions testdata/docker_repository_config.json

This file was deleted.

3 changes: 1 addition & 2 deletions utils/tests/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ var (
// Repositories
DistRepo1 = "cli-dist1"
DistRepo2 = "cli-dist2"
DockerRepo = "cli-docker"
GoRepo = "cli-go"
GoRemoteRepo = "cli-go-remote"
GoVirtualRepo = "cli-go-virtual"
Expand Down Expand Up @@ -1568,7 +1567,7 @@ func GetDockerSourceManifest() []string {

func GetDockerDeployedManifest() []string {
return []string{
DockerRepo + "/docker-target-image/2/manifest.json",
*DockerPromoteLocalRepo + "/docker-target-image/2/manifest.json",
}
}

Expand Down
10 changes: 5 additions & 5 deletions utils/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var (
DockerVirtualRepo *string
DockerRemoteRepo *string
DockerLocalRepo *string
DockerPromoteLocalRepo *string
HideUnitTestLog *bool
PipVirtualEnv *string
ciRunId *string
Expand Down Expand Up @@ -96,7 +97,8 @@ func init() {
DockerRepoDomain = flag.String("rt.dockerRepoDomain", "", "Docker repository domain")
DockerVirtualRepo = flag.String("rt.dockerVirtualRepo", "", "Docker virtual repo")
DockerRemoteRepo = flag.String("rt.dockerRemoteRepo", "", "Docker remote repo")
DockerLocalRepo = flag.String("rt.DockerLocalRepo", "", "Docker local repo")
DockerLocalRepo = flag.String("rt.dockerLocalRepo", "", "Docker local repo")
DockerPromoteLocalRepo = flag.String("rt.dockerPromoteLocalRepo", "", "Docker promote local repo")
HideUnitTestLog = flag.Bool("test.hideUnitTestLog", false, "Hide unit tests logs and print it in a file")
PipVirtualEnv = flag.String("rt.pipVirtualEnv", "", "Pip virtual-environment path")
ciRunId = flag.String("ci.runId", "", "A unique identifier used as a suffix to create repositories and builds in the tests")
Expand Down Expand Up @@ -346,7 +348,6 @@ func GetBuildInfo(serverDetails *config.ServerDetails, buildName, buildNumber st
var reposConfigMap = map[*string]string{
&DistRepo1: DistributionRepoConfig1,
&DistRepo2: DistributionRepoConfig2,
&DockerRepo: DockerRepoConfig,
&GoRepo: GoLocalRepositoryConfig,
&GoRemoteRepo: GoRemoteRepositoryConfig,
&GoVirtualRepo: GoVirtualRepositoryConfig,
Expand Down Expand Up @@ -402,7 +403,7 @@ func GetNonVirtualRepositories() map[*string]string {
TestArtifactory: {&RtRepo1, &RtRepo2, &RtLfsRepo, &RtDebianRepo},
TestArtifactoryProject: {&RtRepo1, &RtRepo2, &RtLfsRepo, &RtDebianRepo},
TestDistribution: {&DistRepo1, &DistRepo2},
TestDocker: {&DockerRepo},
TestDocker: {},
TestGo: {&GoRepo, &GoRemoteRepo},
TestGradle: {&GradleRepo, &GradleRemoteRepo},
TestMaven: {&MvnRepo1, &MvnRepo2, &MvnRemoteRepo},
Expand Down Expand Up @@ -478,7 +479,7 @@ func getSubstitutionMap() map[string]string {
"${VIRTUAL_REPO}": RtVirtualRepo,
"${LFS_REPO}": RtLfsRepo,
"${DEBIAN_REPO}": RtDebianRepo,
"${DOCKER_REPO}": DockerRepo,
"${DOCKER_REPO}": *DockerPromoteLocalRepo,
"${DOCKER_IMAGE_NAME}": DockerImageName,
"${DOCKER_REPO_DOMAIN}": *DockerRepoDomain,
"${MAVEN_REPO1}": MvnRepo1,
Expand Down Expand Up @@ -525,7 +526,6 @@ func AddTimestampToGlobalVars() {
uniqueSuffix = "-" + *ciRunId + uniqueSuffix
}
// Repositories
DockerRepo += uniqueSuffix
DistRepo1 += uniqueSuffix
DistRepo2 += uniqueSuffix
GoRepo += uniqueSuffix
Expand Down

0 comments on commit ad964a9

Please sign in to comment.