Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit cb55dae

Browse files
Simplify and fix CNAB bundle generation test, using a golden file instead.
Signed-off-by: Silvin Lubecki <[email protected]>
1 parent d59eaa9 commit cb55dae

File tree

3 files changed

+133
-134
lines changed

3 files changed

+133
-134
lines changed

e2e/testdata/simple-bundle.json.golden

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,60 @@
55
"maintainers": [
66
{
77
"name": "John Developer",
8-
"email": "[email protected]",
9-
"url": ""
8+
"email": "[email protected]"
109
},
1110
{
1211
"name": "Jane Developer",
13-
"email": "[email protected]",
14-
"url": ""
12+
"email": "[email protected]"
1513
}
1614
],
1715
"invocationImages": [
1816
{
1917
"imageType": "docker",
20-
"image": "simple:1.1.0-beta1-invoc",
21-
"platform": {}
18+
"image": "simple:1.1.0-beta1-invoc"
2219
}
2320
],
2421
"images": {
2522
"api": {
2623
"imageType": "docker",
2724
"image": "python:3.6",
28-
"platform": {},
29-
"description": "python:3.6",
30-
"refs": null
25+
"description": "python:3.6"
3126
},
3227
"db": {
3328
"imageType": "docker",
3429
"image": "postgres:9.3",
35-
"platform": {},
36-
"description": "postgres:9.3",
37-
"refs": null
30+
"description": "postgres:9.3"
3831
},
3932
"web": {
4033
"imageType": "docker",
4134
"image": "nginx:latest",
42-
"platform": {},
43-
"description": "nginx:latest",
44-
"refs": null
35+
"description": "nginx:latest"
4536
}
4637
},
4738
"actions": {
4839
"com.docker.app.inspect": {
49-
"modifies": false,
5040
"stateless": true
5141
},
5242
"com.docker.app.render": {
53-
"modifies": false,
5443
"stateless": true
5544
},
56-
"com.docker.app.status": {
57-
"modifies": false
58-
}
45+
"com.docker.app.status": {}
5946
},
6047
"parameters": {
6148
"api_host": {
6249
"type": "string",
6350
"defaultValue": "coolapp.com",
64-
"required": false,
65-
"metadata": {},
6651
"destination": {
67-
"path": "",
6852
"env": "docker_param1"
6953
}
7054
},
7155
"com.docker.app.kubernetes-namespace": {
7256
"type": "string",
7357
"defaultValue": "",
74-
"required": false,
7558
"metadata": {
7659
"description": "Namespace in which to deploy"
7760
},
7861
"destination": {
79-
"path": "",
8062
"env": "DOCKER_KUBERNETES_NAMESPACE"
8163
},
8264
"apply-to": [
@@ -94,12 +76,10 @@
9476
"swarm",
9577
"kubernetes"
9678
],
97-
"required": false,
9879
"metadata": {
9980
"description": "Orchestrator on which to deploy"
10081
},
10182
"destination": {
102-
"path": "",
10383
"env": "DOCKER_STACK_ORCHESTRATOR"
10484
},
10585
"apply-to": [
@@ -116,12 +96,10 @@
11696
"yaml",
11797
"json"
11898
],
119-
"required": false,
12099
"metadata": {
121100
"description": "Output format for the render command"
122101
},
123102
"destination": {
124-
"path": "",
125103
"env": "DOCKER_RENDER_FORMAT"
126104
},
127105
"apply-to": [
@@ -131,28 +109,21 @@
131109
"static_subdir": {
132110
"type": "string",
133111
"defaultValue": "data/static",
134-
"required": false,
135-
"metadata": {},
136112
"destination": {
137-
"path": "",
138113
"env": "docker_param2"
139114
}
140115
},
141116
"web_port": {
142117
"type": "string",
143118
"defaultValue": "8082",
144-
"required": false,
145-
"metadata": {},
146119
"destination": {
147-
"path": "",
148120
"env": "docker_param3"
149121
}
150122
}
151123
},
152124
"credentials": {
153125
"docker.context": {
154-
"path": "/cnab/app/context.dockercontext",
155-
"env": ""
126+
"path": "/cnab/app/context.dockercontext"
156127
}
157128
}
158129
}

internal/packager/cnab_test.go

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package packager
22

33
import (
4+
"encoding/json"
45
"testing"
56

6-
"github.com/docker/app/internal"
7+
"gotest.tools/golden"
78

8-
"github.com/deislabs/duffle/pkg/bundle"
99
"github.com/docker/app/types"
1010
"gotest.tools/assert"
1111
)
@@ -15,99 +15,7 @@ func TestToCNAB(t *testing.T) {
1515
assert.NilError(t, err)
1616
actual, err := ToCNAB(app, "test-image")
1717
assert.NilError(t, err)
18-
expected := &bundle.Bundle{
19-
Description: "hello",
20-
Name: "packing",
21-
Maintainers: []bundle.Maintainer{
22-
{Name: "bearclaw", Email: "[email protected]"},
23-
{Name: "bob", Email: "[email protected]"},
24-
},
25-
Version: "0.1.0",
26-
InvocationImages: []bundle.InvocationImage{
27-
{
28-
BaseImage: bundle.BaseImage{
29-
Image: "test-image",
30-
ImageType: "docker",
31-
},
32-
},
33-
},
34-
Credentials: map[string]bundle.Location{
35-
"docker.context": {
36-
Path: "/cnab/app/context.dockercontext",
37-
},
38-
},
39-
Parameters: map[string]bundle.ParameterDefinition{
40-
"docker.orchestrator": {
41-
DataType: "string",
42-
AllowedValues: []interface{}{
43-
"",
44-
"swarm",
45-
"kubernetes",
46-
},
47-
Destination: &bundle.Location{
48-
EnvironmentVariable: "DOCKER_STACK_ORCHESTRATOR",
49-
},
50-
Metadata: bundle.ParameterMetadata{
51-
Description: "Orchestrator on which to deploy",
52-
},
53-
DefaultValue: "",
54-
},
55-
"docker.kubernetes-namespace": {
56-
DataType: "string",
57-
Destination: &bundle.Location{
58-
EnvironmentVariable: "DOCKER_KUBERNETES_NAMESPACE",
59-
},
60-
Metadata: bundle.ParameterMetadata{
61-
Description: "Namespace in which to deploy",
62-
},
63-
DefaultValue: "",
64-
},
65-
"watcher.cmd": {
66-
DataType: "string",
67-
Destination: &bundle.Location{
68-
EnvironmentVariable: "docker_param1",
69-
},
70-
DefaultValue: "foo",
71-
},
72-
},
73-
Actions: map[string]bundle.Action{
74-
internal.Namespace + "inspect": {
75-
Modifies: false,
76-
},
77-
internal.Namespace + "status": {
78-
Modifies: false,
79-
},
80-
},
81-
Images: map[string]bundle.Image{
82-
"front": {
83-
Description: "nginx",
84-
BaseImage: bundle.BaseImage{
85-
Image: "nginx",
86-
ImageType: "docker",
87-
},
88-
},
89-
"debug": {
90-
Description: "busybox:latest",
91-
BaseImage: bundle.BaseImage{
92-
Image: "busybox:latest",
93-
ImageType: "docker",
94-
},
95-
},
96-
"monitor": {
97-
Description: "busybox:latest",
98-
BaseImage: bundle.BaseImage{
99-
Image: "busybox:latest",
100-
ImageType: "docker",
101-
},
102-
},
103-
"app-watcher": {
104-
Description: "watcher",
105-
BaseImage: bundle.BaseImage{
106-
Image: "watcher",
107-
ImageType: "docker",
108-
},
109-
},
110-
},
111-
}
112-
assert.DeepEqual(t, actual, expected)
18+
actualJSON, err := json.MarshalIndent(actual, "", " ")
19+
assert.NilError(t, err)
20+
golden.Assert(t, string(actualJSON), "bundle-json.golden")
11321
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"name": "packing",
3+
"version": "0.1.0",
4+
"description": "hello",
5+
"maintainers": [
6+
{
7+
"name": "bearclaw",
8+
"email": "[email protected]"
9+
},
10+
{
11+
"name": "bob",
12+
"email": "[email protected]"
13+
}
14+
],
15+
"invocationImages": [
16+
{
17+
"imageType": "docker",
18+
"image": "test-image"
19+
}
20+
],
21+
"images": {
22+
"app-watcher": {
23+
"imageType": "docker",
24+
"image": "watcher",
25+
"description": "watcher"
26+
},
27+
"debug": {
28+
"imageType": "docker",
29+
"image": "busybox:latest",
30+
"description": "busybox:latest"
31+
},
32+
"front": {
33+
"imageType": "docker",
34+
"image": "nginx",
35+
"description": "nginx"
36+
},
37+
"monitor": {
38+
"imageType": "docker",
39+
"image": "busybox:latest",
40+
"description": "busybox:latest"
41+
}
42+
},
43+
"actions": {
44+
"com.docker.app.inspect": {
45+
"stateless": true
46+
},
47+
"com.docker.app.render": {
48+
"stateless": true
49+
},
50+
"com.docker.app.status": {}
51+
},
52+
"parameters": {
53+
"com.docker.app.kubernetes-namespace": {
54+
"type": "string",
55+
"defaultValue": "",
56+
"metadata": {
57+
"description": "Namespace in which to deploy"
58+
},
59+
"destination": {
60+
"env": "DOCKER_KUBERNETES_NAMESPACE"
61+
},
62+
"apply-to": [
63+
"install",
64+
"upgrade",
65+
"uninstall",
66+
"com.docker.app.status"
67+
]
68+
},
69+
"com.docker.app.orchestrator": {
70+
"type": "string",
71+
"defaultValue": "",
72+
"allowedValues": [
73+
"",
74+
"swarm",
75+
"kubernetes"
76+
],
77+
"metadata": {
78+
"description": "Orchestrator on which to deploy"
79+
},
80+
"destination": {
81+
"env": "DOCKER_STACK_ORCHESTRATOR"
82+
},
83+
"apply-to": [
84+
"install",
85+
"upgrade",
86+
"uninstall",
87+
"com.docker.app.status"
88+
]
89+
},
90+
"com.docker.app.render-format": {
91+
"type": "string",
92+
"defaultValue": "yaml",
93+
"allowedValues": [
94+
"yaml",
95+
"json"
96+
],
97+
"metadata": {
98+
"description": "Output format for the render command"
99+
},
100+
"destination": {
101+
"env": "DOCKER_RENDER_FORMAT"
102+
},
103+
"apply-to": [
104+
"com.docker.app.render"
105+
]
106+
},
107+
"watcher.cmd": {
108+
"type": "string",
109+
"defaultValue": "foo",
110+
"destination": {
111+
"env": "docker_param1"
112+
}
113+
}
114+
},
115+
"credentials": {
116+
"docker.context": {
117+
"path": "/cnab/app/context.dockercontext"
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)