forked from concourse/oci-build-task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildkitd_test.go
84 lines (64 loc) · 1.67 KB
/
buildkitd_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
package task_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
task "github.com/vito/oci-build-task"
)
type BuildkitdSuite struct {
suite.Suite
*require.Assertions
buildkitd *task.Buildkitd
outputsDir string
req task.Request
}
func (s *BuildkitdSuite) TearDownSuite() {
if s.buildkitd != nil {
err := s.buildkitd.Cleanup()
s.NoError(err)
}
}
func (s *BuildkitdSuite) SetupTest() {
var err error
s.outputsDir, err = ioutil.TempDir("", "oci-build-task-test")
s.NoError(err)
s.req = task.Request{
ResponsePath: filepath.Join(s.outputsDir, "response.json"),
Config: task.Config{},
}
}
func (s *BuildkitdSuite) TearDownTest() {
err := os.RemoveAll(s.outputsDir)
s.NoError(err)
}
func (s *BuildkitdSuite) TestNoConfig() {
var pathExists bool
if _, err := os.Stat(s.configPath()); err == nil {
pathExists = true
}
s.Assert().False(pathExists)
}
func (s *BuildkitdSuite) TestGenerateConfig() {
var err error
s.req.Config.RegistryMirrors = []string{"hub.docker.io"}
s.buildkitd, err = task.SpawnBuildkitd(s.req, &task.BuildkitdOpts{
ConfigPath: s.configPath("mirrors.toml"),
})
s.NoError(err)
configContent, err := ioutil.ReadFile(s.configPath("mirrors.toml"))
s.NoError(err)
expectedContent, err := ioutil.ReadFile("testdata/buildkitd-config/mirrors.toml")
s.NoError(err)
s.Equal(expectedContent, configContent)
}
func (s *BuildkitdSuite) configPath(path ...string) string {
return filepath.Join(append([]string{s.outputsDir, "config"}, path...)...)
}
func TestBuildkitd(t *testing.T) {
suite.Run(t, &BuildkitdSuite{
Assertions: require.New(t),
})
}