-
Notifications
You must be signed in to change notification settings - Fork 51
/
fakekpt.go
35 lines (28 loc) · 1.07 KB
/
fakekpt.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
package fakekpt
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner"
"github.com/jenkins-x/jx-helpers/v3/pkg/files"
"github.com/pkg/errors"
)
// FakeKpt a simple command to simulate kpt using local files for use in a fake cmdrunner
func FakeKpt(t *testing.T, c *cmdrunner.Command, versionStreamDir, targetDir string) (string, error) {
if len(c.Args) < 4 {
return "", errors.Errorf("unsupported kpt command %s", c.CLI())
}
valuesDir := c.Args[3]
// lets trim the versionStream folder from the valuesDir
dirs := strings.Split(valuesDir, string(os.PathSeparator))
srcValuesDir := filepath.Join(versionStreamDir, filepath.Join(dirs[1:]...))
// lets copy the file from the src dir to the target to simulate kpt
targetValuesDir := filepath.Join(targetDir, valuesDir)
t.Logf("copying version stream dir %s to %s\n", srcValuesDir, targetValuesDir)
err := files.CopyDir(srcValuesDir, targetValuesDir, true)
if err != nil {
return "", errors.Wrapf(err, "failed to copy %s to %s", srcValuesDir, targetValuesDir)
}
return "", nil
}