1
1
package tests
2
2
3
3
import (
4
+ "bytes"
4
5
"encoding/json"
5
6
"fmt"
6
7
"os"
@@ -9,6 +10,7 @@ import (
9
10
"testing"
10
11
11
12
"github.com/containerd/continuity/fs/fstest"
13
+ "github.com/docker/buildx/bake"
12
14
"github.com/docker/buildx/util/gitutil"
13
15
"github.com/moby/buildkit/client"
14
16
"github.com/moby/buildkit/identity"
@@ -28,6 +30,7 @@ func bakeCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
28
30
}
29
31
30
32
var bakeTests = []func (t * testing.T , sb integration.Sandbox ){
33
+ testBakePrint ,
31
34
testBakeLocal ,
32
35
testBakeLocalMulti ,
33
36
testBakeRemote ,
@@ -55,6 +58,49 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){
55
58
testBakeCallCheckFlag ,
56
59
}
57
60
61
+ func testBakePrint (t * testing.T , sb integration.Sandbox ) {
62
+ dockerfile := []byte (`
63
+ FROM busybox
64
+ ARG HELLO
65
+ RUN echo "Hello ${HELLO}"
66
+ ` )
67
+ bakefile := []byte (`
68
+ target "build" {
69
+ args = {
70
+ HELLO = "foo"
71
+ }
72
+ }
73
+ ` )
74
+ dir := tmpdir (
75
+ t ,
76
+ fstest .CreateFile ("docker-bake.hcl" , bakefile , 0600 ),
77
+ fstest .CreateFile ("Dockerfile" , dockerfile , 0600 ),
78
+ )
79
+
80
+ cmd := buildxCmd (sb , withDir (dir ), withArgs ("bake" , "--print" , "build" ))
81
+ stdout := bytes.Buffer {}
82
+ stderr := bytes.Buffer {}
83
+ cmd .Stdout = & stdout
84
+ cmd .Stderr = & stderr
85
+ require .NoError (t , cmd .Run (), stdout .String (), stderr .String ())
86
+
87
+ var def struct {
88
+ Group map [string ]* bake.Group `json:"group,omitempty"`
89
+ Target map [string ]* bake.Target `json:"target"`
90
+ }
91
+ require .NoError (t , json .Unmarshal (stdout .Bytes (), & def ))
92
+
93
+ require .Len (t , def .Group , 1 )
94
+ require .Contains (t , def .Group , "default" )
95
+
96
+ require .Equal (t , []string {"build" }, def .Group ["default" ].Targets )
97
+ require .Len (t , def .Target , 1 )
98
+ require .Contains (t , def .Target , "build" )
99
+ require .Equal (t , "." , * def .Target ["build" ].Context )
100
+ require .Equal (t , "Dockerfile" , * def .Target ["build" ].Dockerfile )
101
+ require .Equal (t , map [string ]* string {"HELLO" : ptrstr ("foo" )}, def .Target ["build" ].Args )
102
+ }
103
+
58
104
func testBakeLocal (t * testing.T , sb integration.Sandbox ) {
59
105
dockerfile := []byte (`
60
106
FROM scratch
0 commit comments