github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/utils/tests/files.go (about)

     1  package tests
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  )
     8  
     9  func CreateFileWithContent(fileName, relativePath string) (string, string, error) {
    10  	var err error
    11  	tempDirPath, err := ioutil.TempDir("", "tests")
    12  	if err != nil {
    13  		return tempDirPath, "", err
    14  	}
    15  
    16  	fullPath := ""
    17  	if relativePath != "" {
    18  		fullPath = filepath.Join(tempDirPath, relativePath)
    19  		err = os.MkdirAll(fullPath, 0777)
    20  		if err != nil {
    21  			return tempDirPath, "", err
    22  		}
    23  	}
    24  	fullPath = filepath.Join(fullPath, fileName)
    25  	file, err := os.Create(fullPath)
    26  	if err != nil {
    27  		return tempDirPath, "", err
    28  	}
    29  	defer file.Close()
    30  	_, err = file.Write([]byte(fullPath))
    31  	return tempDirPath, fullPath, err
    32  }