forked from containers/buildah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildah_test.go
75 lines (71 loc) · 2.01 KB
/
buildah_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
package buildah
import (
"context"
"flag"
"os"
"testing"
"github.com/containers/storage"
"github.com/containers/storage/types"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
var logLevel string
debug := false
if InitReexec() {
return
}
flag.BoolVar(&debug, "debug", false, "turn on debug logging")
flag.StringVar(&logLevel, "log-level", "error", "log level")
flag.Parse()
level, err := logrus.ParseLevel(logLevel)
if err != nil {
logrus.Fatalf("error parsing log level %q: %v", logLevel, err)
}
if debug && level < logrus.DebugLevel {
level = logrus.DebugLevel
}
logrus.SetLevel(level)
os.Exit(m.Run())
}
func TestOpenBuilderCommonBuildOpts(t *testing.T) {
ctx := context.TODO()
store, err := storage.GetStore(types.StoreOptions{
RunRoot: t.TempDir(),
GraphRoot: t.TempDir(),
GraphDriverName: "vfs",
})
require.NoError(t, err)
t.Cleanup(func() { _, err := store.Shutdown(true); assert.NoError(t, err) })
b, err := NewBuilder(ctx, store, BuilderOptions{})
require.NoError(t, err)
require.NotNil(t, b.CommonBuildOpts)
b.CommonBuildOpts = nil
builderContainerID := b.ContainerID
err = b.Save()
require.NoError(t, err)
b, err = OpenBuilder(store, builderContainerID)
require.NoError(t, err)
require.NotNil(t, b.CommonBuildOpts)
builders, err := OpenAllBuilders(store)
require.NoError(t, err)
for _, b := range builders {
require.NotNil(t, b.CommonBuildOpts)
}
imageID, _, _, err := b.Commit(ctx, nil, CommitOptions{})
require.NoError(t, err)
b, err = ImportBuilderFromImage(ctx, store, ImportFromImageOptions{
Image: imageID,
})
require.NoError(t, err)
require.NotNil(t, b.CommonBuildOpts)
container, err := store.CreateContainer("", nil, imageID, "", "", &storage.ContainerOptions{})
require.NoError(t, err)
require.NotNil(t, container)
b, err = ImportBuilder(ctx, store, ImportOptions{
Container: container.ID,
})
require.NoError(t, err)
require.NotNil(t, b.CommonBuildOpts)
}