-
Notifications
You must be signed in to change notification settings - Fork 198
/
tmp_dir_data.go
50 lines (39 loc) · 1.14 KB
/
tmp_dir_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package suite_init
import (
"fmt"
"os"
"path/filepath"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/werf/werf/test/pkg/utils"
)
type TmpDirData struct {
TmpDir string
TestDirPath string
}
func NewTmpDirData() *TmpDirData {
data := &TmpDirData{}
SetupTmpDir(&data.TmpDir, &data.TestDirPath)
return data
}
func SetupTmpDir(tmpDir, testDirPath *string) bool {
BeforeEach(func() {
*tmpDir = utils.GetTempDir()
*testDirPath = *tmpDir
})
AfterEach(func() {
err := os.RemoveAll(*tmpDir)
Expect(err).ShouldNot(HaveOccurred())
})
return true
}
func (data *TmpDirData) GetProjectWorktree(projectName string) string {
return filepath.Join(data.TestDirPath, fmt.Sprintf("%s.worktree", projectName))
}
func (data *TmpDirData) CommitProjectWorktree(projectName, worktreeFixtureDir, commitMessage string) {
worktreeDir := data.GetProjectWorktree(projectName)
repoDir := filepath.Join(data.TestDirPath, fmt.Sprintf("%s.repo", projectName))
Expect(os.RemoveAll(worktreeDir)).To(Succeed())
utils.CopyIn(worktreeFixtureDir, worktreeDir)
Expect(utils.SetGitRepoState(worktreeDir, repoDir, commitMessage)).To(Succeed())
}