github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/commands/utils/result_test.go (about) 1 package utils 2 3 import ( 4 biutils "github.com/jfrog/build-info-go/utils" 5 ioutils "github.com/jfrog/gofrog/io" 6 testsutils "github.com/jfrog/jfrog-client-go/utils/tests" 7 "os" 8 "path" 9 "path/filepath" 10 "strings" 11 "testing" 12 13 "github.com/jfrog/jfrog-cli-core/v2/common/tests" 14 clientutils "github.com/jfrog/jfrog-client-go/utils" 15 "github.com/jfrog/jfrog-client-go/utils/errorutils" 16 "github.com/jfrog/jfrog-client-go/utils/io/fileutils" 17 "github.com/stretchr/testify/assert" 18 ) 19 20 // Checks a case that targetRepository is not written in a deployableArtifacts file and needs to be read from the config file. 21 func TestUnmarshalDeployableArtifacts(t *testing.T) { 22 cleanUpJfrogHome, err := tests.ConfigTestServer(t) 23 assert.NoError(t, err) 24 defer cleanUpJfrogHome() 25 // DeployableArtifact file is changed at runtime so a copy needs to be created. 26 tempDeployableArtifacts, err := createTempDeployableArtifactFile() 27 assert.NoError(t, err) 28 // Delete DeployableArtifacts tempDir 29 defer testsutils.RemoveAllAndAssert(t, filepath.Dir(tempDeployableArtifacts)) 30 gradleConfigFile := path.Join(getTestsDataGradlePath(), "config", "gradle.yaml") 31 result, err := UnmarshalDeployableArtifacts(tempDeployableArtifacts, gradleConfigFile, false) 32 assert.NoError(t, err) 33 for transferDetails := new(clientutils.FileTransferDetails); result.reader.NextRecord(transferDetails) == nil; transferDetails = new(clientutils.FileTransferDetails) { 34 assert.Equal(t, transferDetails.RtUrl, "http://localhost:8080/artifactory/") 35 assert.True(t, strings.HasPrefix(transferDetails.TargetPath, "gradle-local-repo")) 36 } 37 } 38 39 // createTempDeployableArtifactFile copies a deployableArtifacts file from gradle testdata directory to a tempDir 40 func createTempDeployableArtifactFile() (filePath string, err error) { 41 filePath = "" 42 testsDataGradlePath := getTestsDataGradlePath() 43 summary, err := os.Open(path.Join(testsDataGradlePath, "deployableArtifacts", "artifacts")) 44 if errorutils.CheckError(err) != nil { 45 return 46 } 47 defer ioutils.Close(summary, &err) 48 tmpDir, err := fileutils.CreateTempDir() 49 if err != nil { 50 return 51 } 52 err = biutils.CopyFile(tmpDir, summary.Name()) 53 if err != nil { 54 return 55 } 56 filePath = filepath.Join(tmpDir, "artifacts") 57 return 58 } 59 60 func getTestsDataGradlePath() string { 61 return path.Join("..", "testdata", "gradle") 62 }