This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
project_test.go
107 lines (88 loc) · 1.96 KB
/
project_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_project(t *testing.T) {
t.Parallel()
homeDir, err := os.UserHomeDir()
require.NoError(t, err)
conf := mustReadConfig(filepath.Join(metaRoot(), ".sail.toml"))
var tests = []struct {
schema string
name string
repo string
expCntName string
expEnsureDirErr bool
expCustomBldImg bool
}{
{
"ssh",
"OK",
"codercom/bigdur",
"codercom_bigdur",
false,
true,
},
{
"ssh",
"RepoNotExist",
"codercom/do-not-exist",
"codercom_do-not-exist",
true,
false,
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
rb := newRollback()
defer rb.run()
repo, err := parseRepo(test.schema, "github.com", "", test.repo)
require.NoError(t, err)
p := &project{
conf: conf,
repo: repo,
}
name := p.cntName()
require.Equal(t, test.expCntName, name)
expLocalDir := filepath.Join(homeDir, "Projects", test.repo)
require.Equal(t, expLocalDir, p.localDir())
require.Equal(t,
filepath.Join(expLocalDir, ".sail", "Dockerfile"),
p.dockerfilePath(),
)
t.Run("EnsureDir", func(t *testing.T) {
err = p.ensureDir()
if test.expEnsureDirErr {
require.Error(t, err)
return
}
require.NoError(t, err)
rb.add(func() {
err := os.RemoveAll(p.localDir())
require.NoError(t, err)
})
})
t.Run("BuildImage", func(t *testing.T) {
image, isCustom, err := p.buildImage()
require.NoError(t, err)
if !test.expCustomBldImg {
assert.False(t, isCustom)
assert.Empty(t, image)
return
}
assert.True(t, isCustom)
labels := requireGetImageLabels(t, image)
assertLabel(t, labels, baseImageLabel, p.repo.DockerName())
rb.add(func() {
requireImageRemove(t, p.repo.DockerName())
})
})
})
}
}