Skip to content

Commit

Permalink
Move content from jfrog-cli to jfrog-cli-core (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas authored Jan 10, 2024
1 parent 21e24cd commit 3b84760
Show file tree
Hide file tree
Showing 41 changed files with 175 additions and 1,155 deletions.
8 changes: 4 additions & 4 deletions access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var (
accessDetails *config.ServerDetails
accessCli *tests.JfrogCli
accessCli *coreTests.JfrogCli
accessHttpDetails httputils.HttpClientDetails
)

Expand All @@ -37,7 +37,7 @@ func initAccessCli() {
if accessCli != nil {
return
}
accessCli = tests.NewJfrogCli(execMain, "jfrog", authenticateAccess())
accessCli = coreTests.NewJfrogCli(execMain, "jfrog", authenticateAccess())
}

func InitAccessTests() {
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestRefreshableAccessTokens(t *testing.T) {
defer deleteServerConfig(t)

// Upload a file and assert the refreshable tokens were generated.
artifactoryCommandExecutor := tests.NewJfrogCli(execMain, "jfrog rt", "")
artifactoryCommandExecutor := coreTests.NewJfrogCli(execMain, "jfrog rt", "")
uploadedFiles := 1
err = uploadWithSpecificServerAndVerify(t, artifactoryCommandExecutor, "testdata/a/a1.in", uploadedFiles)
if !assert.NoError(t, err) {
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestAccessTokenCreate(t *testing.T) {
assertNotEmptyIfExpected(t, test.expectedReference, token.ReferenceToken)

// Try pinging Artifactory with the new token.
assert.NoError(t, tests.NewJfrogCli(execMain, "jfrog rt",
assert.NoError(t, coreTests.NewJfrogCli(execMain, "jfrog rt",
"--url="+*tests.JfrogUrl+tests.ArtifactoryEndpoint+" --access-token="+token.AccessToken).Exec("ping"))
})
}
Expand Down
18 changes: 3 additions & 15 deletions artifactory/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
containerutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
"github.com/jfrog/jfrog-cli-core/v2/common/build"
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/common/progressbar"
"github.com/jfrog/jfrog-cli-core/v2/common/project"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common"
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
"github.com/jfrog/jfrog-cli/buildtools"
"github.com/jfrog/jfrog-cli/docs/artifactory/accesstokencreate"
"github.com/jfrog/jfrog-cli/docs/artifactory/buildadddependencies"
Expand Down Expand Up @@ -110,7 +111,6 @@ import (
"github.com/jfrog/jfrog-cli/docs/artifactory/yarnconfig"
"github.com/jfrog/jfrog-cli/docs/common"
"github.com/jfrog/jfrog-cli/utils/cliutils"
"github.com/jfrog/jfrog-cli/utils/progressbar"
buildinfocmd "github.com/jfrog/jfrog-client-go/artifactory/buildinfo"
"github.com/jfrog/jfrog-client-go/artifactory/services"
clientutils "github.com/jfrog/jfrog-client-go/utils"
Expand Down Expand Up @@ -2682,23 +2682,11 @@ func createDefaultBuildAddDependenciesSpec(c *cli.Context) *spec.SpecFiles {
func fixWinPathsForDownloadCmd(uploadSpec *spec.SpecFiles, c *cli.Context) {
if coreutils.IsWindows() {
for i, file := range uploadSpec.Files {
uploadSpec.Files[i].Target = fixWinPathBySource(file.Target, c.IsSet("spec"))
uploadSpec.Files[i].Target = commonCliUtils.FixWinPathBySource(file.Target, c.IsSet("spec"))
}
}
}

func fixWinPathBySource(path string, fromSpec bool) string {
if strings.Count(path, "/") > 0 {
// Assuming forward slashes - not doubling backslash to allow regexp escaping
return ioutils.UnixToWinPathSeparator(path)
}
if fromSpec {
// Doubling backslash only for paths from spec files (that aren't forward slashed)
return ioutils.DoubleWinPathSeparator(path)
}
return path
}

func createUploadConfiguration(c *cli.Context) (uploadConfiguration *utils.UploadConfiguration, err error) {
uploadConfiguration = new(utils.UploadConfiguration)
uploadConfiguration.Threads, err = cliutils.GetThreadsCount(c)
Expand Down
40 changes: 21 additions & 19 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import (
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/common/project"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
commontests "github.com/jfrog/jfrog-cli-core/v2/common/tests"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/utils/dependencies"
Expand Down Expand Up @@ -68,13 +70,13 @@ import (
const terraformMinArtifactoryVersion = "7.38.4"

// JFrog CLI for Artifactory sub-commands (jfrog rt ...)
var artifactoryCli *tests.JfrogCli
var artifactoryCli *coretests.JfrogCli

// JFrog CLI for Platform commands (jfrog ...)
var platformCli *tests.JfrogCli
var platformCli *coretests.JfrogCli

// JFrog CLI for config command only (doesn't pass the --ssh-passphrase flag)
var configCli *tests.JfrogCli
var configCli *coretests.JfrogCli

var serverDetails *config.ServerDetails
var artAuth auth.ServiceDetails
Expand Down Expand Up @@ -126,11 +128,11 @@ func authenticate(configCli bool) string {

// A Jfrog CLI to be used to execute a config task.
// Removed the ssh-passphrase flag that cannot be passed to with a config command
func createConfigJfrogCLI(cred string) *tests.JfrogCli {
func createConfigJfrogCLI(cred string) *coretests.JfrogCli {
if strings.Contains(cred, " --ssh-passphrase=") {
cred = strings.ReplaceAll(cred, " --ssh-passphrase="+*tests.JfrogSshPassphrase, "")
}
return tests.NewJfrogCli(execMain, "jfrog config", cred)
return coretests.NewJfrogCli(execMain, "jfrog config", cred)
}

func getArtifactoryTestCredentials() string {
Expand Down Expand Up @@ -212,7 +214,7 @@ func TestArtifactorySimpleUploadSpecUsingConfig(t *testing.T) {
passphrase, err := createServerConfigAndReturnPassphrase(t)
defer deleteServerConfig(t)
assert.NoError(t, err)
artifactoryCommandExecutor := tests.NewJfrogCli(execMain, "jfrog rt", "")
artifactoryCommandExecutor := coretests.NewJfrogCli(execMain, "jfrog rt", "")
specFile, err := tests.CreateSpec(tests.UploadFlatRecursive)
assert.NoError(t, err)
assert.NoError(t, artifactoryCommandExecutor.Exec("upload", "--spec="+specFile, "--server-id="+tests.ServerId, passphrase))
Expand Down Expand Up @@ -349,7 +351,7 @@ func TestArtifactoryDownloadFromVirtual(t *testing.T) {
func TestArtifactoryDownloadAndUploadWithProgressBar(t *testing.T) {
initArtifactoryTest(t, "")

callback := tests.MockProgressInitialization()
callback := commontests.MockProgressInitialization()
defer callback()

runRt(t, "upload", "testdata/a/*", tests.RtRepo1, "--flat=false")
Expand Down Expand Up @@ -793,7 +795,7 @@ func verifyUsersExistInArtifactory(csvFilePath string, t *testing.T) {
break
}
user, password := record[0], record[1]
err = tests.NewJfrogCli(execMain, "jfrog rt", "--url="+serverDetails.ArtifactoryUrl+" --user="+user+" --password="+password).Exec("ping")
err = coretests.NewJfrogCli(execMain, "jfrog rt", "--url="+serverDetails.ArtifactoryUrl+" --user="+user+" --password="+password).Exec("ping")
assert.NoError(t, err)
}

Expand Down Expand Up @@ -1805,7 +1807,7 @@ func TestXrayScanBuild(t *testing.T) {
initArtifactoryTest(t, "")
xrayServerPort := xray.StartXrayMockServer()
serverUrl := "--url=http://localhost:" + strconv.Itoa(xrayServerPort)
artifactoryCommandExecutor := tests.NewJfrogCli(execMain, "jfrog rt", serverUrl+getArtifactoryTestCredentials())
artifactoryCommandExecutor := coretests.NewJfrogCli(execMain, "jfrog rt", serverUrl+getArtifactoryTestCredentials())
assert.NoError(t, artifactoryCommandExecutor.Exec("build-scan", xray.CleanScanBuildName, "3"))

cleanArtifactoryTest()
Expand Down Expand Up @@ -3090,7 +3092,7 @@ func prepareDownloadByBuildWithDependenciesTests(t *testing.T) {
runRt(t, "upload", "--spec="+specFileB)

// Add build dependencies.
artifactoryCliNoCreds := tests.NewJfrogCli(execMain, "jfrog rt", "")
artifactoryCliNoCreds := coretests.NewJfrogCli(execMain, "jfrog rt", "")
assert.NoError(t, artifactoryCliNoCreds.Exec("bad", "--spec="+specFileB, tests.RtBuildName1, buildNumber))

// Publish build.
Expand Down Expand Up @@ -4222,7 +4224,7 @@ func TestUploadDetailedSummary(t *testing.T) {

func createUploadConfiguration() *utils.UploadConfiguration {
uploadConfiguration := new(utils.UploadConfiguration)
uploadConfiguration.Threads = cliutils.Threads
uploadConfiguration.Threads = commonCliUtils.Threads
return uploadConfiguration
}

Expand Down Expand Up @@ -5098,9 +5100,9 @@ func TestConfigEncryption(t *testing.T) {
assert.NoError(t, configCli.Exec("add", "server-2"))

// Expect no error after reading it
assert.NoError(t, tests.NewJfrogCli(execMain, "jfrog config", "").Exec("show"))
assert.NoError(t, tests.NewJfrogCli(execMain, "jfrog rt", "--server-id=server-1").Exec("ping"))
assert.NoError(t, tests.NewJfrogCli(execMain, "jfrog rt", "--server-id=server-2").Exec("ping"))
assert.NoError(t, coretests.NewJfrogCli(execMain, "jfrog config", "").Exec("show"))
assert.NoError(t, coretests.NewJfrogCli(execMain, "jfrog rt", "--server-id=server-1").Exec("ping"))
assert.NoError(t, coretests.NewJfrogCli(execMain, "jfrog rt", "--server-id=server-2").Exec("ping"))
}

func TestConfigEncryptionMissingKey(t *testing.T) {
Expand Down Expand Up @@ -5194,7 +5196,7 @@ func pipeStdinSecret(t *testing.T, secret string) func() {
func TestArtifactoryReplicationCreate(t *testing.T) {
initArtifactoryTest(t, "")
// Configure server with dummy credentials
err := tests.NewJfrogCli(execMain, "jfrog config", "").Exec("add", tests.ServerId, "--artifactory-url="+*tests.JfrogUrl+tests.ArtifactoryEndpoint, "--user=admin", "--password=password", "--enc-password=false")
err := coretests.NewJfrogCli(execMain, "jfrog config", "").Exec("add", tests.ServerId, "--artifactory-url="+*tests.JfrogUrl+tests.ArtifactoryEndpoint, "--user=admin", "--password=password", "--enc-password=false")
defer deleteServerConfig(t)
assert.NoError(t, err)

Expand Down Expand Up @@ -5244,7 +5246,7 @@ func TestArtifactoryAccessTokenCreate(t *testing.T) {
*tests.JfrogAccessToken = origAccessToken
}()
*tests.JfrogAccessToken = ""
err := tests.NewJfrogCli(execMain, "jfrog rt", authenticate(false)).Exec("atc")
err := coretests.NewJfrogCli(execMain, "jfrog rt", authenticate(false)).Exec("atc")
assert.NoError(t, err)
} else {
runRt(t, "atc")
Expand Down Expand Up @@ -5273,7 +5275,7 @@ func checkAccessToken(t *testing.T, buffer *bytes.Buffer) {
assert.NoError(t, err)

// Try ping with the new token
err = tests.NewJfrogCli(execMain, "jfrog rt", "--url="+*tests.JfrogUrl+tests.ArtifactoryEndpoint+" --access-token="+token).Exec("ping")
err = coretests.NewJfrogCli(execMain, "jfrog rt", "--url="+*tests.JfrogUrl+tests.ArtifactoryEndpoint+" --access-token="+token).Exec("ping")
assert.NoError(t, err)
}

Expand All @@ -5290,7 +5292,7 @@ func TestRefreshableArtifactoryTokens(t *testing.T) {
assert.NoError(t, err)

// Upload a file and assert the refreshable tokens were generated.
artifactoryCommandExecutor := tests.NewJfrogCli(execMain, "jfrog rt", "")
artifactoryCommandExecutor := coretests.NewJfrogCli(execMain, "jfrog rt", "")
uploadedFiles := 1
err = uploadWithSpecificServerAndVerify(t, artifactoryCommandExecutor, "testdata/a/a1.in", uploadedFiles)
if err != nil {
Expand Down Expand Up @@ -5415,7 +5417,7 @@ func assertTokensChanged(t *testing.T, curAccessToken, curRefreshToken string) (
return newAccessToken, newRefreshToken, nil
}

func uploadWithSpecificServerAndVerify(t *testing.T, cli *tests.JfrogCli, source string, expectedResults int) error {
func uploadWithSpecificServerAndVerify(t *testing.T, cli *coretests.JfrogCli, source string, expectedResults int) error {
err := cli.Exec("upload", source, tests.RtRepo1, "--server-id="+tests.ServerId)
if err != nil {
assert.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestBuildAddDependenciesDryRun(t *testing.T) {
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, "testdata")
defer chdirCallback()

noCredsCli := tests.NewJfrogCli(execMain, "jfrog rt", "")
noCredsCli := coretests.NewJfrogCli(execMain, "jfrog rt", "")
// Execute the bad command on the local file system
assert.NoError(t, noCredsCli.Exec("bad", tests.RtBuildName1, "1", "a/*", "--dry-run=true"))
buildDir, err := build.GetBuildDir(tests.RtBuildName1, "1", "")
Expand Down Expand Up @@ -660,7 +660,7 @@ func TestBuildAddGitEnvBuildNameAndNumber(t *testing.T) {

func testBuildAddGit(t *testing.T, useEnvBuildNameAndNumber bool) {
initArtifactoryTest(t, "")
gitCollectCliRunner := tests.NewJfrogCli(execMain, "jfrog rt", "")
gitCollectCliRunner := coretests.NewJfrogCli(execMain, "jfrog rt", "")
buildNumber := "13"

// Populate cli config with 'default' server
Expand Down Expand Up @@ -843,7 +843,7 @@ func TestModuleName(t *testing.T) {
}

func collectDepsAndPublishBuild(badTest buildAddDepsBuildInfoTestParams, useEnvBuildNameAndNumber bool, t *testing.T) {
noCredsCli := tests.NewJfrogCli(execMain, "jfrog rt", "")
noCredsCli := coretests.NewJfrogCli(execMain, "jfrog rt", "")
// Remove old tests data from fs if exists
err := build.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "")
assert.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/yarn"
containerutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
"github.com/jfrog/jfrog-cli-core/v2/common/build"
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
outputFormat "github.com/jfrog/jfrog-cli-core/v2/common/format"
"github.com/jfrog/jfrog-cli-core/v2/common/project"
Expand Down Expand Up @@ -602,7 +603,7 @@ func extractThreadsFlag(args []string) (cleanArgs []string, threadsCount int, er
cleanArgs = append([]string(nil), args...)
threadsFlagIndex, threadsValueIndex, threads, err := coreutils.FindFlag("--threads", cleanArgs)
if err != nil || threadsFlagIndex < 0 {
threadsCount = cliutils.Threads
threadsCount = commonCliUtils.Threads
return
}
coreutils.RemoveFlagFromCommand(&cleanArgs, threadsFlagIndex, threadsValueIndex)
Expand Down
7 changes: 4 additions & 3 deletions completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ package main
import (
"testing"

coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli/completion/shells/bash"
"github.com/jfrog/jfrog-cli/completion/shells/zsh"
"github.com/jfrog/jfrog-cli/utils/tests"
"github.com/stretchr/testify/assert"
)

func TestBashCompletion(t *testing.T) {
jfrogCli := tests.NewJfrogCli(execMain, "jfrog", "")
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
content, err := tests.GetCmdOutput(t, jfrogCli, "completion", "bash")
assert.NoError(t, err)
assert.Equal(t, bash.BashAutocomplete, string(content))
}

func TestZshCompletion(t *testing.T) {
jfrogCli := tests.NewJfrogCli(execMain, "jfrog", "")
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
content, err := tests.GetCmdOutput(t, jfrogCli, "completion", "zsh")
assert.NoError(t, err)
assert.Equal(t, zsh.ZshAutocomplete, string(content))
}

func TestFishCompletion(t *testing.T) {
jfrogCli := tests.NewJfrogCli(execMain, "jfrog", "")
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
content, err := tests.GetCmdOutput(t, jfrogCli, "completion", "fish")
assert.NoError(t, err)
assert.Contains(t, string(content), "complete -c")
Expand Down
3 changes: 2 additions & 1 deletion distribution/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package distribution

import (
"errors"
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
distributionCommands "github.com/jfrog/jfrog-cli-core/v2/distribution/commands"
Expand Down Expand Up @@ -311,7 +312,7 @@ func populateReleaseNotesSyntax(c *cli.Context) (distributionServicesUtils.Relea
}

func createDistributionDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) {
dsDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, cliutils.Ds)
dsDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, commonCliUtils.Ds)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
distAuth auth.ServiceDetails
distHttpDetails httputils.HttpClientDetails
// JFrog CLI for Distribution commands
distributionCli *tests.JfrogCli
distributionCli *coreTests.JfrogCli
)

func InitDistributionTests() {
Expand Down Expand Up @@ -80,7 +80,7 @@ func initDistributionCli() {
return
}
cred := authenticateDistribution()
distributionCli = tests.NewJfrogCli(execMain, "jfrog ds", cred)
distributionCli = coreTests.NewJfrogCli(execMain, "jfrog ds", cred)
}

func initDistributionTest(t *testing.T) {
Expand Down Expand Up @@ -610,7 +610,7 @@ func TestDistributeSyncTimeout(t *testing.T) {
maxWaitMinutes := 1
distributionRulesPath := filepath.Join(tests.GetTestResourcesPath(), "distribution", tests.DistributionRules)

mockDsCli := tests.NewJfrogCli(execMain, "jfrog ds", "--url="+mockServerDetails.DistributionUrl)
mockDsCli := coreTests.NewJfrogCli(execMain, "jfrog ds", "--url="+mockServerDetails.DistributionUrl)
err := mockDsCli.Exec("rbd", tests.BundleName, bundleVersion, "--dist-rules="+distributionRulesPath, "--sync", "--max-wait-minutes="+strconv.Itoa(maxWaitMinutes), "--create-repo")
assert.ErrorContains(t, err, "executor timeout after")
assert.ErrorAs(t, err, &clientUtils.RetryExecutorTimeoutError{})
Expand Down
Loading

0 comments on commit 3b84760

Please sign in to comment.