github.com/jfrog/jfrog-cli-core/v2@v2.52.0/utils/config/tests/utils.go (about) 1 package tests 2 3 import ( 4 biutils "github.com/jfrog/build-info-go/utils" 5 "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" 6 testsutils "github.com/jfrog/jfrog-client-go/utils/tests" 7 "github.com/stretchr/testify/assert" 8 "os" 9 "testing" 10 ) 11 12 const certsConversionResources = "testdata/config/configconversion" 13 const encryptionResources = "testdata/config/encryption" 14 15 // Set JFROG_CLI_HOME_DIR environment variable to be a new temp directory 16 func CreateTempEnv(t *testing.T, copyEncryptionKey bool) (cleanUp func()) { 17 tmpDir, err := os.MkdirTemp("", "config_test") 18 assert.NoError(t, err) 19 oldHome := os.Getenv(coreutils.HomeDir) 20 testsutils.SetEnvAndAssert(t, coreutils.HomeDir, tmpDir) 21 copyResources(t, certsConversionResources, tmpDir) 22 if copyEncryptionKey { 23 copyResources(t, encryptionResources, tmpDir) 24 } 25 return func() { 26 testsutils.RemoveAllAndAssert(t, tmpDir) 27 testsutils.SetEnvAndAssert(t, coreutils.HomeDir, oldHome) 28 } 29 } 30 31 func copyResources(t *testing.T, sourcePath string, destPath string) { 32 assert.NoError(t, biutils.CopyDir(sourcePath, destPath, true, nil)) 33 }