diff --git a/httpclient/client.go b/httpclient/client.go index 9f32d675f..d0c554722 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -6,12 +6,12 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/jfrog/jfrog-client-go/utils" - "github.com/jfrog/jfrog-client-go/utils/errorutils" - ioutils "github.com/jfrog/jfrog-client-go/utils/io" - "github.com/jfrog/jfrog-client-go/utils/io/fileutils" - "github.com/jfrog/jfrog-client-go/utils/io/httputils" - "github.com/jfrog/jfrog-client-go/utils/log" + "github.com/arcolife/jfrog-client-go/utils" + "github.com/arcolife/jfrog-client-go/utils/errorutils" + ioutils "github.com/arcolife/jfrog-client-go/utils/io" + "github.com/arcolife/jfrog-client-go/utils/io/fileutils" + "github.com/arcolife/jfrog-client-go/utils/io/httputils" + "github.com/arcolife/jfrog-client-go/utils/log" "github.com/mholt/archiver" "hash" "io" diff --git a/httpclient/clientBuilder.go b/httpclient/clientBuilder.go index c923f975b..65c86d08f 100644 --- a/httpclient/clientBuilder.go +++ b/httpclient/clientBuilder.go @@ -3,8 +3,8 @@ package httpclient import ( "crypto/tls" "errors" - "github.com/jfrog/jfrog-client-go/artifactory/auth/cert" - "github.com/jfrog/jfrog-client-go/utils/errorutils" + "github.com/arcolife/jfrog-client-go/artifactory/auth/cert" + "github.com/arcolife/jfrog-client-go/utils/errorutils" "net" "net/http" "time" diff --git a/httpclient/retryableconnection.go b/httpclient/retryableconnection.go index 0124883a9..72538d997 100644 --- a/httpclient/retryableconnection.go +++ b/httpclient/retryableconnection.go @@ -3,8 +3,8 @@ package httpclient import ( "bufio" "errors" - "github.com/jfrog/jfrog-client-go/utils/errorutils" - "github.com/jfrog/jfrog-client-go/utils/log" + "github.com/arcolife/jfrog-client-go/utils/errorutils" + "github.com/arcolife/jfrog-client-go/utils/log" "io" "net/http" "time" diff --git a/httpclient/retryableconnection_test.go b/httpclient/retryableconnection_test.go index 38e87e1e2..a2c387c17 100644 --- a/httpclient/retryableconnection_test.go +++ b/httpclient/retryableconnection_test.go @@ -3,10 +3,10 @@ package httpclient import ( "errors" "fmt" - "github.com/jfrog/jfrog-client-go/utils/errorutils" - "github.com/jfrog/jfrog-client-go/utils/io/httputils" - "github.com/jfrog/jfrog-client-go/utils/log" - "github.com/jfrog/jfrog-client-go/utils/tests" + "github.com/arcolife/jfrog-client-go/utils/errorutils" + "github.com/arcolife/jfrog-client-go/utils/io/httputils" + "github.com/arcolife/jfrog-client-go/utils/log" + "github.com/arcolife/jfrog-client-go/utils/tests" "io" "io/ioutil" "net/http" diff --git a/tests/artifactory_test.go b/tests/artifactory_test.go deleted file mode 100644 index 6fe2e3233..000000000 --- a/tests/artifactory_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package tests - -import ( - "testing" -) - -func TestGetArtifactoryVersion(t *testing.T) { - version, err := getArtDetails().GetVersion() - if err != nil { - t.Error(err) - } - if version == "" { - t.Error("Expected a version, got empty string") - } -} diff --git a/tests/artifactorydownload_test.go b/tests/artifactorydownload_test.go deleted file mode 100644 index 8ba7cea21..000000000 --- a/tests/artifactorydownload_test.go +++ /dev/null @@ -1,291 +0,0 @@ -package tests - -import ( - "github.com/jfrog/jfrog-client-go/artifactory/services" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests" - "github.com/jfrog/jfrog-client-go/utils/io/fileutils" - "github.com/mholt/archiver" - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestArtifactoryDownload(t *testing.T) { - uploadDummyFile(t) - t.Run("flat", flatDownload) - t.Run("recursive", recursiveDownload) - t.Run("placeholder", placeholderDownload) - t.Run("includeDirs", includeDirsDownload) - t.Run("excludePatterns", excludePatternsDownload) - t.Run("explodeArchive", explodeArchiveDownload) - artifactoryCleanup(t) -} - -func uploadDummyFile(t *testing.T) { - workingDir, _, err := tests.CreateFileWithContent("a.in", "/out/") - if err != nil { - t.Error(err) - t.FailNow() - } - defer os.RemoveAll(workingDir) - pattern := FixWinPath(filepath.Join(workingDir, "*")) - up := services.NewUploadParams() - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: pattern, Recursive: true, Target: RtTargetRepo + "test/"} - up.Flat = true - _, uploaded, failed, err := testsUploadService.UploadFiles(up) - if uploaded != 1 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - if err != nil { - t.Error(err) - } - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: pattern, Recursive: true, Target: RtTargetRepo + "b.in"} - up.Flat = true - _, uploaded, failed, err = testsUploadService.UploadFiles(up) - if uploaded != 1 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - archivePath := filepath.Join(workingDir, "c.tar.gz") - err = archiver.TarGz.Make(archivePath, []string{filepath.Join(workingDir, "out/a.in")}) - if err != nil { - t.Error(err) - } - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: archivePath, Recursive: true, Target: RtTargetRepo} - up.Flat = true - _, uploaded, failed, err = testsUploadService.UploadFiles(up) - if uploaded != 1 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - if err != nil { - t.Error(err) - } -} - -func flatDownload(t *testing.T) { - var err error - workingDir, err := ioutil.TempDir("", "downloadTests") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir) - downloadPattern := RtTargetRepo + "*" - downloadTarget := workingDir + string(filepath.Separator) - // Download all from TargetRepo with flat = true - _, _, err = testsDownloadService.DownloadFiles(services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, Recursive: true, Target: downloadTarget}, Flat: true}) - if err != nil { - t.Error(err) - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "a.in"), false) { - t.Error("Missing file a.in") - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "b.in"), false) { - t.Error("Missing file b.in") - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "c.tar.gz"), false) { - t.Error("Missing file c.tar.gz") - } - - workingDir2, err := ioutil.TempDir("", "downloadTests") - downloadTarget = workingDir2 + string(filepath.Separator) - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir2) - // Download all from TargetRepo with flat = false - _, _, err = testsDownloadService.DownloadFiles(services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, Recursive: true, Target: downloadTarget}, Flat: false}) - if err != nil { - t.Error(err) - } - if !fileutils.IsPathExists(filepath.Join(workingDir2, "test", "a.in"), false) { - t.Error("Missing file a.in") - } - if !fileutils.IsPathExists(filepath.Join(workingDir2, "b.in"), false) { - t.Error("Missing file b.in") - } - if !fileutils.IsPathExists(filepath.Join(workingDir2, "c.tar.gz"), false) { - t.Error("Missing file c.tar.gz") - } -} - -func recursiveDownload(t *testing.T) { - uploadDummyFile(t) - var err error - workingDir, err := ioutil.TempDir("", "downloadTests") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir) - downloadPattern := RtTargetRepo + "*" - downloadTarget := workingDir + string(filepath.Separator) - _, _, err = testsDownloadService.DownloadFiles(services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, Recursive: true, Target: downloadTarget}, Flat: true}) - if err != nil { - t.Error(err) - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "a.in"), false) { - t.Error("Missing file a.in") - } - - if !fileutils.IsPathExists(filepath.Join(workingDir, "b.in"), false) { - t.Error("Missing file b.in") - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "c.tar.gz"), false) { - t.Error("Missing file c.tar.gz") - } - - workingDir2, err := ioutil.TempDir("", "downloadTests") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir2) - downloadTarget = workingDir2 + string(filepath.Separator) - _, _, err = testsDownloadService.DownloadFiles(services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, Recursive: false, Target: downloadTarget}, Flat: true}) - if err != nil { - t.Error(err) - } - if fileutils.IsPathExists(filepath.Join(workingDir2, "a.in"), false) { - t.Error("Should not download a.in") - } - - if !fileutils.IsPathExists(filepath.Join(workingDir2, "b.in"), false) { - t.Error("Missing file b.in") - } - if !fileutils.IsPathExists(filepath.Join(workingDir2, "c.tar.gz"), false) { - t.Error("Missing file c.tar.gz") - } -} - -func placeholderDownload(t *testing.T) { - uploadDummyFile(t) - var err error - workingDir, err := ioutil.TempDir("", "downloadTests") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir) - downloadPattern := RtTargetRepo + "(*).in" - downloadTarget := workingDir + string(filepath.Separator) + "{1}" + string(filepath.Separator) - _, _, err = testsDownloadService.DownloadFiles(services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, Recursive: true, Target: downloadTarget}, Flat: true}) - if err != nil { - t.Error(err) - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "test", "a", "a.in"), false) { - t.Error("Missing file a.in") - } - - if !fileutils.IsPathExists(filepath.Join(workingDir, "b", "b.in"), false) { - t.Error("Missing file b.in") - } -} - -func includeDirsDownload(t *testing.T) { - var err error - workingDir, err := ioutil.TempDir("", "downloadTests") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir) - downloadPattern := RtTargetRepo + "*" - downloadTarget := workingDir + string(filepath.Separator) - _, _, err = testsDownloadService.DownloadFiles(services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, IncludeDirs: true, Recursive: false, Target: downloadTarget}, Flat: false}) - if err != nil { - t.Error(err) - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "test"), false) { - t.Error("Missing test folder") - } - - if !fileutils.IsPathExists(filepath.Join(workingDir, "b.in"), false) { - t.Error("Missing file b.in") - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "c.tar.gz"), false) { - t.Error("Missing file c.tsr.gz") - } -} - -func excludePatternsDownload(t *testing.T) { - workingDir, err := ioutil.TempDir("", "downloadTests") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir) - downloadPattern := RtTargetRepo + "*" - downloadTarget := workingDir + string(filepath.Separator) - excludePatterns := []string{"b.in", "*.tar.gz"} - _, _, err = testsDownloadService.DownloadFiles(services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, Recursive: true, Target: downloadTarget, ExcludePatterns: excludePatterns}, Flat: true}) - if err != nil { - t.Error(err) - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "a.in"), false) { - t.Error("Missing file a.in") - } - - if fileutils.IsPathExists(filepath.Join(workingDir, "b.in"), false) { - t.Error("File b.in should have been excluded") - } - if fileutils.IsPathExists(filepath.Join(workingDir, "c.tar.gz"), false) { - t.Error("File c.tar.gz should have been excluded") - } -} - -func explodeArchiveDownload(t *testing.T) { - workingDir, err := ioutil.TempDir("", "downloadTests") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(workingDir) - downloadPattern := RtTargetRepo + "*.tar.gz" - downloadTarget := workingDir + string(filepath.Separator) - downloadParams := services.DownloadParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{Pattern: downloadPattern, Recursive: true, Target: downloadTarget}, Flat: true, Explode: false} - // First we'll download c.tar.gz without extracting it (explode = false by default). - _, _, err = testsDownloadService.DownloadFiles(downloadParams) - if err != nil { - t.Error(err) - } - if fileutils.IsPathExists(filepath.Join(workingDir, "a.in"), false) { - t.Error("File a.in should not have been downloaded") - } - if fileutils.IsPathExists(filepath.Join(workingDir, "b.in"), false) { - t.Error("File b.in should not have been downloaded") - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "c.tar.gz"), false) { - t.Error("Missing file c.tar.gz") - } - - // Scenario 1: Download c.tar.gz with explode = true, when it already exists in the target dir. - // Artifactory should perform "checksum download" and not actually downloading it, but still need to extract it. - downloadParams.Explode = true - explodeDownloadAndVerify(t, &downloadParams, workingDir) - - // Remove the download target dir. - err = os.RemoveAll(workingDir) - if err != nil { - t.Error(err) - } - // Scenario 2: Download c.tar.gz with explode = true, when it does not exist in the target dir. - // Artifactory should download the file and extract it. - explodeDownloadAndVerify(t, &downloadParams, workingDir) -} - -func explodeDownloadAndVerify(t *testing.T, downloadParams *services.DownloadParams, workingDir string) { - _, _, err := testsDownloadService.DownloadFiles(*downloadParams) - if err != nil { - t.Error(err) - } - if fileutils.IsPathExists(filepath.Join(workingDir, "c.tar.gz"), false) { - t.Error("File c.tar.gz should have been extracted") - } - if !fileutils.IsPathExists(filepath.Join(workingDir, "a.in"), false) { - t.Error("Missing file a.in") - } -} diff --git a/tests/artifactoryupload_test.go b/tests/artifactoryupload_test.go deleted file mode 100644 index ff8efbb00..000000000 --- a/tests/artifactoryupload_test.go +++ /dev/null @@ -1,242 +0,0 @@ -package tests - -import ( - "github.com/jfrog/jfrog-client-go/artifactory/services" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests" - "github.com/jfrog/jfrog-client-go/utils/io/fileutils" - "os" - "path/filepath" - "testing" -) - -func TestArtifactoryUpload(t *testing.T) { - t.Run("flat", flatUpload) - t.Run("recursive", recursiveUpload) - t.Run("placeholder", placeholderUpload) - t.Run("includeDirs", includeDirsUpload) - t.Run("explode", explodeUpload) -} - -func flatUpload(t *testing.T) { - workingDir, _, err := tests.CreateFileWithContent("a.in", "/out/") - if err != nil { - t.Error(err) - t.FailNow() - } - defer os.RemoveAll(workingDir) - pattern := FixWinPath(filepath.Join(workingDir, "out", "*")) - up := services.NewUploadParams() - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: pattern, Recursive: true, Target: RtTargetRepo} - up.Flat = true - _, uploaded, failed, err := testsUploadService.UploadFiles(up) - if uploaded != 1 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - if err != nil { - t.Error(err) - } - searchParams := services.NewSearchParams() - searchParams.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{} - searchParams.Pattern = RtTargetRepo - items, err := testsSearchService.Search(searchParams) - if err != nil { - t.Error(err) - } - if len(items) > 1 { - t.Error("Expected single file.") - } - for _, item := range items { - if item.Path != "." { - t.Error("Expected path to be root due to using the flat flag.", "Got:", item.Path) - } - } - artifactoryCleanup(t) -} - -func recursiveUpload(t *testing.T) { - workingDir, _, err := tests.CreateFileWithContent("a.in", "/out/") - if err != nil { - t.Error(err) - t.FailNow() - } - defer os.RemoveAll(workingDir) - pattern := FixWinPath(filepath.Join(workingDir, "*")) - up := services.NewUploadParams() - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: pattern, Recursive: true, Target: RtTargetRepo} - up.Flat = true - _, uploaded, failed, err := testsUploadService.UploadFiles(up) - if uploaded != 1 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - if err != nil { - t.Error(err) - } - searchParams := services.NewSearchParams() - searchParams.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{} - searchParams.Pattern = RtTargetRepo - items, err := testsSearchService.Search(searchParams) - if err != nil { - t.Error(err) - } - if len(items) > 1 { - t.Error("Expected single file.") - } - for _, item := range items { - if item.Path != "." { - t.Error("Expected path to be root(flat by default).", "Got:", item.Path) - } - if item.Name != "a.in" { - t.Error("Missing File a.in") - } - } - artifactoryCleanup(t) -} - -func placeholderUpload(t *testing.T) { - workingDir, _, err := tests.CreateFileWithContent("a.in", "/out/") - if err != nil { - t.Error(err) - t.FailNow() - } - defer os.RemoveAll(workingDir) - pattern := FixWinPath(filepath.Join(workingDir, "(*).in")) - up := services.NewUploadParams() - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: pattern, Recursive: true, Target: RtTargetRepo + "{1}"} - up.Flat = true - _, uploaded, failed, err := testsUploadService.UploadFiles(up) - if uploaded != 1 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - if err != nil { - t.Error(err) - } - searchParams := services.NewSearchParams() - searchParams.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{} - searchParams.Pattern = RtTargetRepo - items, err := testsSearchService.Search(searchParams) - if err != nil { - t.Error(err) - } - if len(items) > 1 { - t.Error("Expected single file.") - } - for _, item := range items { - if item.Path != "out" { - t.Error("Expected path to be out.", "Got:", item.Path) - } - if item.Name != "a" { - t.Error("Missing File a") - } - } - artifactoryCleanup(t) -} - -func includeDirsUpload(t *testing.T) { - workingDir, _, err := tests.CreateFileWithContent("a.in", "/out/") - if err != nil { - t.Error(err) - t.FailNow() - } - defer os.RemoveAll(workingDir) - pattern := FixWinPath(filepath.Join(workingDir, "*")) - up := services.NewUploadParams() - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: pattern, IncludeDirs: true, Recursive: false, Target: RtTargetRepo} - up.Flat = true - _, uploaded, failed, err := testsUploadService.UploadFiles(up) - if uploaded != 0 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - if err != nil { - t.Error(err) - } - searchParams := services.NewSearchParams() - searchParams.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{} - searchParams.Pattern = RtTargetRepo - searchParams.IncludeDirs = true - items, err := testsSearchService.Search(searchParams) - if err != nil { - t.Error(err) - } - if len(items) < 2 { - t.Error("Expected to get at least two items, default and the out folder.") - } - for _, item := range items { - if item.Name == "." { - continue - } - if item.Path != "." { - t.Error("Expected path to be root(flat by default).", "Got:", item.Path) - } - if item.Name != "out" { - t.Error("Missing directory out.") - } - } - artifactoryCleanup(t) -} - -func explodeUpload(t *testing.T) { - workingDir, filePath, err := tests.CreateFileWithContent("a.in", "/out/") - if err != nil { - t.Error(err) - t.FailNow() - } - defer os.RemoveAll(workingDir) - err = fileutils.ZipFolderFiles(filePath, filepath.Join(workingDir, "zipFile.zip")) - if err != nil { - t.Error(err) - t.FailNow() - } - err = os.Remove(filePath) - if err != nil { - t.Error(err) - t.FailNow() - } - pattern := FixWinPath(filepath.Join(workingDir, "*.zip")) - up := services.NewUploadParams() - up.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{Pattern: pattern, IncludeDirs: true, Recursive: false, Target: RtTargetRepo} - up.Flat = true - up.ExplodeArchive = true - _, uploaded, failed, err := testsUploadService.UploadFiles(up) - if uploaded != 1 { - t.Error("Expected to upload 1 file.") - } - if failed != 0 { - t.Error("Failed to upload", failed, "files.") - } - if err != nil { - t.Error(err) - } - searchParams := services.NewSearchParams() - searchParams.ArtifactoryCommonParams = &utils.ArtifactoryCommonParams{} - searchParams.Pattern = RtTargetRepo - searchParams.IncludeDirs = true - items, err := testsSearchService.Search(searchParams) - if err != nil { - t.Error(err) - } - if len(items) < 2 { - t.Error("Expected to get at least two items, default and the out folder.") - } - for _, item := range items { - if item.Name == "." { - continue - } - if item.Name != "a.in" { - t.Error("Missing file a.in") - } - } - artifactoryCleanup(t) -} diff --git a/tests/jfrogclient_test.go b/tests/jfrogclient_test.go deleted file mode 100644 index 1cd655b2f..000000000 --- a/tests/jfrogclient_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package tests - -import ( - "flag" - "github.com/jfrog/jfrog-client-go/utils/log" - "github.com/jfrog/jfrog-client-go/utils/tests" - "os" - "path/filepath" - "testing" -) - -const ( - JfrogTestsHome = ".jfrogTest" - JfrogHomeEnv = "JFROG_CLI_HOME" - CliIntegrationTests = "github.com/jfrog/jfrog-client-go/tests" -) - -func TestMain(m *testing.M) { - InitArtifactoryServiceManager() - result := m.Run() - os.Exit(result) -} - -func InitArtifactoryServiceManager() { - flag.Parse() - log.SetLogger(log.NewLogger(log.DEBUG, nil)) - createArtifactoryUploadManager() - createArtifactorySearchManager() - createArtifactoryDeleteManager() - createArtifactoryDownloadManager() - createReposIfNeeded() -} - -func TestUnitTests(t *testing.T) { - homePath, err := filepath.Abs(JfrogTestsHome) - if err != nil { - log.Error(err) - os.Exit(1) - } - - setJfrogHome(homePath) - packages := tests.GetTestPackages("./../...") - packages = tests.ExcludeTestsPackage(packages, CliIntegrationTests) - tests.RunTests(packages, false) - cleanUnitTestsJfrogHome(homePath) -} - -func setJfrogHome(homePath string) { - if err := os.Setenv(JfrogHomeEnv, homePath); err != nil { - log.Error(err) - os.Exit(1) - } -} - -func cleanUnitTestsJfrogHome(homePath string) { - os.RemoveAll(homePath) - if err := os.Unsetenv(JfrogHomeEnv); err != nil { - os.Exit(1) - } -} diff --git a/tests/testsdata/reposconfig/specs_test_repository_config.json b/tests/testsdata/reposconfig/specs_test_repository_config.json deleted file mode 100644 index f479f2941..000000000 --- a/tests/testsdata/reposconfig/specs_test_repository_config.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "key": "jfrog-client-tests-repo1", - "packageType": "generic", - "description": "", - "notes": "", - "includesPattern": "**/*", - "excludesPattern": "", - "repoLayoutRef": "simple-default", - "enableNuGetSupport": false, - "enableGemsSupport": false, - "enableNpmSupport": false, - "enableBowerSupport": false, - "enableCocoaPodsSupport": false, - "enableDebianSupport": false, - "debianTrivialLayout": false, - "enablePypiSupport": false, - "enableDockerSupport": false, - "dockerApiVersion": "V1", - "forceDockerAuthentication": false, - "forceNugetAuthentication": false, - "enableVagrantSupport": false, - "enableGitLfsSupport": false, - "checksumPolicyType": "client-checksums", - "handleReleases": true, - "handleSnapshots": true, - "maxUniqueSnapshots": 0, - "snapshotVersionBehavior": "unique", - "suppressPomConsistencyChecks": true, - "blackedOut": false, - "propertySets": [ - "artifactory" - ], - "archiveBrowsingEnabled": false, - "calculateYumMetadata": false, - "yumRootDepth": 0, - "rclass": "local" -} \ No newline at end of file diff --git a/tests/utils.go b/tests/utils.go deleted file mode 100644 index d03be18f4..000000000 --- a/tests/utils.go +++ /dev/null @@ -1,209 +0,0 @@ -package tests - -import ( - "errors" - "flag" - "fmt" - "github.com/jfrog/jfrog-client-go/artifactory/auth" - rthttpclient "github.com/jfrog/jfrog-client-go/artifactory/httpclient" - "github.com/jfrog/jfrog-client-go/artifactory/services" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" - "github.com/jfrog/jfrog-client-go/httpclient" - clientutils "github.com/jfrog/jfrog-client-go/utils" - "github.com/jfrog/jfrog-client-go/utils/io/fileutils" - "github.com/jfrog/jfrog-client-go/utils/log" - "io/ioutil" - "net/http" - "os" - "path/filepath" - "strings" - "testing" -) - -var RtUrl *string -var RtUser *string -var RtPassword *string -var RtApiKey *string -var RtSshKeyPath *string -var RtSshPassphrase *string -var RtAccessToken *string -var LogLevel *string -var testsUploadService *services.UploadService -var testsSearchService *services.SearchService -var testsDeleteService *services.DeleteService -var testsDownloadService *services.DownloadService - -const ( - RtTargetRepo = "jfrog-client-tests-repo1/" - SpecsTestRepositoryConfig = "specs_test_repository_config.json" - RepoDetailsUrl = "api/repositories/" - HttpClientCreationFailureMessage = "Failed while attempting to create HttpClient: %s" -) - -func init() { - RtUrl = flag.String("rt.url", "http://localhost:8081/artifactory/", "Artifactory url") - RtUser = flag.String("rt.user", "admin", "Artifactory username") - RtPassword = flag.String("rt.password", "password", "Artifactory password") - RtApiKey = flag.String("rt.apikey", "", "Artifactory user API key") - RtSshKeyPath = flag.String("rt.sshKeyPath", "", "Ssh key file path") - RtSshPassphrase = flag.String("rt.sshPassphrase", "", "Ssh key passphrase") - RtAccessToken = flag.String("rt.accessToken", "", "Artifactory access token") - LogLevel = flag.String("log-level", "INFO", "Sets the log level") -} - -func createArtifactorySearchManager() { - artDetails := getArtDetails() - client, err := rthttpclient.ArtifactoryClientBuilder().SetArtDetails(&artDetails).Build() - failOnHttpClientCreation(err) - testsSearchService = services.NewSearchService(client) - testsSearchService.ArtDetails = artDetails -} - -func createArtifactoryDeleteManager() { - artDetails := getArtDetails() - client, err := rthttpclient.ArtifactoryClientBuilder().SetArtDetails(&artDetails).Build() - failOnHttpClientCreation(err) - testsDeleteService = services.NewDeleteService(client) - testsDeleteService.ArtDetails = artDetails -} - -func createArtifactoryUploadManager() { - artDetails := getArtDetails() - client, err := rthttpclient.ArtifactoryClientBuilder().SetArtDetails(&artDetails).Build() - failOnHttpClientCreation(err) - testsUploadService = services.NewUploadService(client) - testsUploadService.ArtDetails = artDetails - testsUploadService.Threads = 3 -} - -func createArtifactoryDownloadManager() { - artDetails := getArtDetails() - client, err := rthttpclient.ArtifactoryClientBuilder().SetArtDetails(&artDetails).Build() - failOnHttpClientCreation(err) - testsDownloadService = services.NewDownloadService(client) - testsDownloadService.ArtDetails = artDetails - testsDownloadService.SetThreads(3) -} - -func failOnHttpClientCreation(err error) { - if err != nil { - log.Error(fmt.Sprintf(HttpClientCreationFailureMessage, err.Error())) - os.Exit(1) - } -} - -func getArtDetails() auth.ArtifactoryDetails { - rtDetails := auth.NewArtifactoryDetails() - rtDetails.SetUrl(clientutils.AddTrailingSlashIfNeeded(*RtUrl)) - if !fileutils.IsSshUrl(rtDetails.GetUrl()) { - if *RtApiKey != "" { - rtDetails.SetApiKey(*RtApiKey) - } else if *RtAccessToken != "" { - rtDetails.SetAccessToken(*RtAccessToken) - } else { - rtDetails.SetUser(*RtUser) - rtDetails.SetPassword(*RtPassword) - } - return rtDetails - } - - err := rtDetails.AuthenticateSsh(*RtSshKeyPath, *RtSshPassphrase) - if err != nil { - log.Error("Failed while attempting to authenticate with Artifactory: " + err.Error()) - os.Exit(1) - } - return rtDetails -} - -func artifactoryCleanup(t *testing.T) { - params := &utils.ArtifactoryCommonParams{Pattern: RtTargetRepo} - toDelete, err := testsDeleteService.GetPathsToDelete(services.DeleteParams{ArtifactoryCommonParams: params}) - if err != nil { - t.Error(err) - t.FailNow() - } - deleteItems := make([]utils.ResultItem, len(toDelete)) - for i, item := range toDelete { - deleteItems[i] = item - } - deletedCount, err := testsDeleteService.DeleteFiles(deleteItems) - if err != nil { - t.Error(err) - t.FailNow() - } - if len(toDelete) != deletedCount { - t.Errorf("Failed to delete files from Artifactory expected %d items to be deleted got %d.", len(toDelete), deletedCount) - } -} - -func createReposIfNeeded() error { - var err error - var repoConfig string - repo := RtTargetRepo - if strings.HasSuffix(repo, "/") { - repo = repo[0:strings.LastIndex(repo, "/")] - } - if !isRepoExist(repo) { - repoConfig = filepath.Join(getTestDataPath(), "reposconfig", SpecsTestRepositoryConfig) - err = execCreateRepoRest(repoConfig, repo) - if err != nil { - log.Error(err) - return err - } - } - return nil -} - -func isRepoExist(repoName string) bool { - artDetails := getArtDetails() - artHttpDetails := artDetails.CreateHttpClientDetails() - client, err := httpclient.ClientBuilder().Build() - if err != nil { - log.Error(err) - os.Exit(1) - } - resp, _, _, err := client.SendGet(artDetails.GetUrl()+RepoDetailsUrl+repoName, true, artHttpDetails) - if err != nil { - log.Error(err) - os.Exit(1) - } - - if resp.StatusCode != http.StatusBadRequest { - return true - } - return false -} - -func execCreateRepoRest(repoConfig, repoName string) error { - content, err := ioutil.ReadFile(repoConfig) - if err != nil { - return err - } - artDetails := getArtDetails() - artHttpDetails := artDetails.CreateHttpClientDetails() - - artHttpDetails.Headers = map[string]string{"Content-Type": "application/json"} - client, err := httpclient.ClientBuilder().Build() - if err != nil { - return err - } - resp, _, err := client.SendPut(artDetails.GetUrl()+"api/repositories/"+repoName, content, artHttpDetails) - if err != nil { - return err - } - if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { - return errors.New("Fail to create repository. Reason local repository with key: " + repoName + " already exist\n") - } - log.Info("Repository", repoName, "created.") - return nil -} - -func getTestDataPath() string { - dir, _ := os.Getwd() - return filepath.Join(dir, "testsdata") -} - -func FixWinPath(filePath string) string { - fixedPath := strings.Replace(filePath, "\\", "\\\\", -1) - return fixedPath -} diff --git a/tests/xrayscan_test.go b/tests/xrayscan_test.go deleted file mode 100644 index 636c25e44..000000000 --- a/tests/xrayscan_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package tests - -import ( - rthttpclient "github.com/jfrog/jfrog-client-go/artifactory/httpclient" - "github.com/jfrog/jfrog-client-go/artifactory/services" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests/xray" - "strconv" - "strings" - "testing" -) - -var testsXrayScanService *services.XrayScanService - -func TestNewXrayScanService(t *testing.T) { - xrayServerPort := xray.StartXrayMockServer() - artDetails := getArtDetails() - client, err := rthttpclient.ArtifactoryClientBuilder().SetArtDetails(&artDetails).Build() - if err != nil { - t.Error(err) - } - testsXrayScanService = services.NewXrayScanService(client) - testsXrayScanService.ArtDetails = artDetails - testsXrayScanService.ArtDetails.SetUrl("http://localhost:" + strconv.Itoa(xrayServerPort) + "/") - - // Run tests - tests := []struct { - name string - buildName string - buildNumber string - expected string - }{ - {name: "scanCleanBuild", buildName: xray.CleanScanBuildName, buildNumber: "3", expected: xray.CleanXrayScanResponse}, - {name: "scanVulnerableBuild", buildName: xray.VulnerableBuildName, buildNumber: "3", expected: xray.VulnerableXrayScanResponse}, - {name: "scanFatalBuild", buildName: xray.FatalScanBuildName, buildNumber: "3", expected: xray.FatalErrorXrayScanResponse}, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - scanBuild(t, test.buildName, test.buildNumber, test.expected) - }) - } -} - -func scanBuild(t *testing.T, buildName, buildNumber, expected string) { - params := services.NewXrayScanParams() - params.BuildName = buildName - params.BuildNumber = buildNumber - result, err := testsXrayScanService.ScanBuild(params) - if err != nil { - t.Error(err) - } - - expected = strings.Replace(expected, "\n", "", -1) - if string(result) != expected { - t.Error("Expected:", string(result), "Got: ", expected) - } -}