/
import_test.go
48 lines (35 loc) · 1.13 KB
/
import_test.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
package cmd
import (
"testing"
"io/ioutil"
"path"
"os"
"github.com/jenkins-x/jx/pkg/util"
"github.com/stretchr/testify/assert"
)
func TestReplacePlaceholders(t *testing.T) {
f, err := ioutil.TempDir("", "test-extract-domain")
assert.NoError(t, err)
testData := path.Join("test_data", "replace_placeholders")
_, err = os.Stat(testData)
assert.NoError(t, err)
util.CopyDir(testData, f, true)
assert.NoError(t, err)
o := ImportOptions{}
o.Dir = f
o.AppName = "bar"
o.GitRepositoryOptions.ServerURL = "github.com"
o.Organisation = "foo"
o.replacePlaceholders()
// root file
testFile, err := util.LoadBytes(f, "file.txt")
assert.Equal(t, "/home/jenkins/go/src/github.com/foo/bar", string(testFile), "replaced placeholder")
// dir1
testDir1 := path.Join(f, "dir1")
testFile, err = util.LoadBytes(testDir1, "file.txt")
assert.Equal(t, "/home/jenkins/go/src/github.com/foo/bar", string(testFile), "replaced placeholder")
// dir2
testDir2 := path.Join(f, "dir2")
testFile, err = util.LoadBytes(testDir2, "file.txt")
assert.Equal(t, "/home/jenkins/go/src/github.com/foo/bar", string(testFile), "replaced placeholder")
}