@@ -5,8 +5,12 @@ import (
55 "fmt"
66 "os"
77 "testing"
8+ "time"
89
10+ "github.com/deislabs/cnab-go/bundle"
11+ "github.com/deislabs/cnab-go/claim"
912 "github.com/docker/app/internal"
13+ "github.com/docker/app/internal/store"
1014 "github.com/docker/app/types"
1115 "gotest.tools/assert"
1216 "gotest.tools/fs"
@@ -22,7 +26,7 @@ type inspectTestCase struct {
2226 args map [string ]string
2327}
2428
25- func TestInspect (t * testing.T ) {
29+ func TestImageInspect (t * testing.T ) {
2630 dir := fs .NewDir (t , "inspect" ,
2731 fs .WithDir ("no-maintainers" ,
2832 fs .WithFile (internal .ComposeFileName , composeYAML ),
@@ -121,14 +125,14 @@ text: hello`),
121125 {name : "full" },
122126 } {
123127 os .Setenv (internal .DockerInspectFormatEnvVar , "pretty" )
124- testInspect (t , dir , testcase , "" )
128+ testImageInspect (t , dir , testcase , "" )
125129 os .Setenv (internal .DockerInspectFormatEnvVar , "json" )
126- testInspect (t , dir , testcase , "-json" )
130+ testImageInspect (t , dir , testcase , "-json" )
127131 }
128132 })
129133}
130134
131- func testInspect (t * testing.T , dir * fs.Dir , testcase inspectTestCase , suffix string ) {
135+ func testImageInspect (t * testing.T , dir * fs.Dir , testcase inspectTestCase , suffix string ) {
132136 app , err := types .NewAppFromDefaultFiles (dir .Join (testcase .name ))
133137 assert .NilError (t , err )
134138 // Inspect twice to ensure output is stable (e.g. sorting of maps)
@@ -141,3 +145,66 @@ func testInspect(t *testing.T, dir *fs.Dir, testcase inspectTestCase, suffix str
141145 })
142146 }
143147}
148+
149+ func getInstallation () store.Installation {
150+ created := time .Now ().Add (time .Hour * - 24 )
151+ modified := time .Now ().Add (time .Hour * - 17 )
152+ b := bundle.Bundle {
153+ SchemaVersion : "1.0.0" ,
154+ Name : "hello-world" ,
155+ Version : "0.1.0" ,
156+ Description : "Hello, World!" ,
157+ }
158+ i := store.Installation {
159+ Claim : claim.Claim {
160+ Name : "hello-world" ,
161+ Revision : "01DS2ZW4QKPXHTZXZ8YAP6S9W2" ,
162+ Created : created ,
163+ Modified : modified ,
164+ Bundle : & b ,
165+ Result : claim.Result {
166+ Action : "upgrade" ,
167+ Status : "success" ,
168+ },
169+ Parameters : map [string ]interface {}{
170+ "com.docker.app.args" : "{}" ,
171+ "com.docker.app.inspect-format" : "json" ,
172+ "com.docker.app.kubernetes-namespace" : "default" ,
173+ "com.docker.app.orchestrator" : "" ,
174+ "com.docker.app.render-format" : "yaml" ,
175+ "com.docker.app.share-registry-creds" : false ,
176+ "port" : "8080" ,
177+ "text" : "Hello, World!" ,
178+ },
179+ },
180+ Reference : "docker.io/sirot/hello-world:0.1.0" ,
181+ }
182+ return i
183+ }
184+
185+ func TestInspect (t * testing.T ) {
186+ i := getInstallation ()
187+
188+ testCases := []struct {
189+ name string
190+ format string
191+ }{
192+ {
193+ name : "pretty" ,
194+ format : "pretty" ,
195+ },
196+ {
197+ name : "json" ,
198+ format : "json" ,
199+ },
200+ }
201+
202+ for _ , testCase := range testCases {
203+ t .Run (testCase .name , func (t * testing.T ) {
204+ var out bytes.Buffer
205+ err := Inspect (& out , & i , testCase .format , "swarm" )
206+ assert .NilError (t , err )
207+ golden .Assert (t , out .String (), fmt .Sprintf ("inspect-app-%s.golden" , testCase .name ))
208+ })
209+ }
210+ }
0 commit comments