Skip to content

Commit

Permalink
Fix Go tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Dec 13, 2018
1 parent 2ad78d9 commit 3e20ff1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 3 additions & 3 deletions appveyor.yml
Expand Up @@ -63,9 +63,9 @@ environment:
- NUGET_TESTS:
TEST_SUIT:
"%COMMON_TESTS_ARGS% --test.artifactory=false --test.nuget=true"
# - GO_TESTS:
# TEST_SUIT:
# "%COMMON_TESTS_ARGS% --test.artifactory=false -test.go=true"
- GO_TESTS:
TEST_SUIT:
"%COMMON_TESTS_ARGS% --test.artifactory=false -test.go=true"

test_script:
- "%TEST_SUIT%"
4 changes: 2 additions & 2 deletions jfrog-cli/artifactory/commands/golang/go.go
Expand Up @@ -147,9 +147,9 @@ func downloadFromVcsAndPublish(targetRepo, goArg string, recursiveTidy, recursiv
log.Error("Received an error:", err)
}
// Lets run the same command again now that all the dependencies were downloaded.
// Need to run only if the command is not go mod download or go mod tidy since this was run by the CLI to download and publish to Artifactory
// Need to run only if the command is not go mod download and go mod tidy since this was run by the CLI to download and publish to Artifactory
log.Info(fmt.Sprintf("Done building and publishing %d go dependencies to Artifactory out of a total of %d dependencies.", cache.GetSuccesses(), cache.GetTotal()))
if !strings.Contains(goArg, "mod download") || !strings.Contains(goArg, "mod tidy") {
if !strings.Contains(goArg, "mod download") && !strings.Contains(goArg, "mod tidy") {
if recursiveTidy {
// Remove the go.sum file, since it includes information which is not up to date (it was created by the "go mod tidy" command executed without Artifactory
err = removeGoSumFile(wd, rootDir)
Expand Down
31 changes: 31 additions & 0 deletions jfrog-cli/jfrog/buildtools_test.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/jfrog/jfrog-cli-go/jfrog-cli/artifactory/utils/golang"
"github.com/jfrog/jfrog-cli-go/jfrog-cli/artifactory/commands/generic"
"github.com/jfrog/jfrog-cli-go/jfrog-cli/artifactory/commands/gradle"
"github.com/jfrog/jfrog-cli-go/jfrog-cli/artifactory/commands/mvn"
Expand Down Expand Up @@ -184,6 +185,7 @@ func initGoTest(t *testing.T) {
}
execCreateRepoRest(repoConfig, tests.GoLocalRepo)
}
authenticate()
}

func initNugetTest(t *testing.T) {
Expand Down Expand Up @@ -241,7 +243,10 @@ func TestGoBuildInfo(t *testing.T) {
// 2. Publish build-info.
// 3. Validate the total count of dependencies added to the build-info.
buildNumber := "1"

artifactoryCli.Exec("go", "build", tests.GoLocalRepo, "--build-name="+buildName, "--build-number="+buildNumber)
cleanGoCache(t)

artifactoryCli.Exec("bp", buildName, buildNumber)
buildInfo := inttestutils.GetBuildInfo(artifactoryDetails.Url, buildName, buildNumber, t, artHttpDetails)
validateBuildInfo(buildInfo, t, 6, 0)
Expand All @@ -252,8 +257,13 @@ func TestGoBuildInfo(t *testing.T) {
// 3. Validate the total count of dependencies and artifacts added to the build-info.
// 4. Validate that the artifacts are tagged with the build.name and build.number properties.
buildNumber = "2"

artifactoryCli.Exec("go", "build", tests.GoLocalRepo, "--build-name="+buildName, "--build-number="+buildNumber)
cleanGoCache(t)

artifactoryCli.Exec("gp", tests.GoLocalRepo, "v1.0.0", "--build-name="+buildName, "--build-number="+buildNumber, "--deps=rsc.io/quote:v1.5.2")
cleanGoCache(t)

artifactoryCli.Exec("bp", buildName, buildNumber)
buildInfo = inttestutils.GetBuildInfo(artifactoryDetails.Url, buildName, buildNumber, t, artHttpDetails)
validateBuildInfo(buildInfo, t, 6, 2)
Expand Down Expand Up @@ -290,8 +300,11 @@ func TestGoPublishResolve(t *testing.T) {

// Download dependencies without Artifactory
artifactoryCli.Exec("go", "build", tests.GoLocalRepo)
cleanGoCache(t)

// Publish dependency project to Artifactory
artifactoryCli.Exec("gp", tests.GoLocalRepo, "v1.0.0")
cleanGoCache(t)

err = os.Chdir(project2Path)
if err != nil {
Expand All @@ -300,6 +313,7 @@ func TestGoPublishResolve(t *testing.T) {

// Build the second project, download dependencies from Artifactory
artifactoryCli.Exec("go", "build", tests.GoLocalRepo)
cleanGoCache(t)

// Restore workspace
err = os.Chdir(wd)
Expand All @@ -309,6 +323,23 @@ func TestGoPublishResolve(t *testing.T) {
cleanGoTest()
}

func cleanGoCache(t *testing.T) {
log.Info("Cleaning go cache by running: 'go clean -modcache'")

golang.SetGoProxyEnvVar(artifactoryDetails, tests.GoLocalRepo)
defer os.Unsetenv(golang.GOPROXY)

goCmd, err := golang.NewCmd()
if err != nil {
t.Error(err)
}
goCmd.Command = []string{"clean", "-modcache"}
err = utils.RunCmd(goCmd)
if err != nil {
t.Error(err)
}
}

func createGoProject(t *testing.T, projectName string) string {
projectSrc := filepath.Join(tests.GetTestResourcesPath(), "go", projectName)
projectTarget := filepath.Join(tests.Out, projectName)
Expand Down

0 comments on commit 3e20ff1

Please sign in to comment.