Skip to content

Commit 18dcd82

Browse files
authored
Merge pull request #1710 from itsdarshankumar/inspect-builder
show extensions only if they are present for all output format in inspect builder
2 parents 8a8b544 + 9f6b412 commit 18dcd82

8 files changed

Lines changed: 141 additions & 64 deletions

acceptance/testdata/pack_fixtures/inspect_builder_nested_depth_2_output.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ Detection Order:
4646
│ └ simple/nested-level-2@nested-l2-version
4747
└ read/env@read-env-version (optional)
4848

49-
Extensions:
50-
(none)
51-
52-
Detection Order (Extensions):
53-
(none)
54-
5549
LOCAL:
5650

5751
Created By:
@@ -97,9 +91,3 @@ Detection Order:
9791
│ └ Group #1:
9892
│ └ simple/nested-level-2@nested-l2-version
9993
└ read/env@read-env-version (optional)
100-
101-
Extensions:
102-
(none)
103-
104-
Detection Order (Extensions):
105-
(none)

acceptance/testdata/pack_fixtures/inspect_builder_nested_output.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ Detection Order:
4848
│ └ simple/layers@simple-layers-version
4949
└ read/env@read-env-version (optional)
5050

51-
Extensions:
52-
(none)
53-
54-
Detection Order (Extensions):
55-
(none)
56-
5751
LOCAL:
5852

5953
Created By:
@@ -101,9 +95,3 @@ Detection Order:
10195
│ └ Group #1:
10296
│ └ simple/layers@simple-layers-version
10397
└ read/env@read-env-version (optional)
104-
105-
Extensions:
106-
(none)
107-
108-
Detection Order (Extensions):
109-
(none)

acceptance/testdata/pack_fixtures/inspect_builder_nested_output_json.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@
9797
}
9898
]
9999
}
100-
],
101-
"extensions": null,
102-
"order_extensions": null
100+
]
103101
},
104102
"local_info": {
105103
"created_by": {
@@ -196,8 +194,6 @@
196194
}
197195
]
198196
}
199-
],
200-
"extensions": null,
201-
"order_extensions": null
197+
]
202198
}
203199
}

acceptance/testdata/pack_fixtures/inspect_builder_nested_output_yaml.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ remote_info:
5858
- id: read/env
5959
version: read-env-version
6060
optional: true
61-
extensions: []
62-
order_extensions: []
6361
local_info:
6462
created_by:
6563
name: Pack CLI
@@ -116,5 +114,3 @@ local_info:
116114
- id: read/env
117115
version: read-env-version
118116
optional: true
119-
extensions: []
120-
order_extensions: []

acceptance/testdata/pack_fixtures/inspect_builder_output.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ Detection Order:
4242
├ simple/layers
4343
└ read/env@read-env-version (optional)
4444

45-
Extensions:
46-
(none)
47-
48-
Detection Order (Extensions):
49-
(none)
50-
5145
LOCAL:
5246

5347
Created By:
@@ -89,9 +83,3 @@ Detection Order:
8983
└ Group #1:
9084
├ simple/layers
9185
└ read/env@read-env-version (optional)
92-
93-
Extensions:
94-
(none)
95-
96-
Detection Order (Extensions):
97-
(none)

internal/builder/writer/human_readable.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ Stack:
6161
{{ .RunImages }}
6262
{{ .Buildpacks }}
6363
{{ .Order }}
64+
{{- if ne .Extensions "" }}
6465
{{ .Extensions }}
65-
{{ .OrderExtensions}}`
66+
{{- end }}
67+
{{- if ne .OrderExtensions "" }}
68+
{{ .OrderExtensions }}
69+
{{- end }}`
6670
)
6771

6872
type HumanReadable struct{}
@@ -129,29 +133,42 @@ func writeBuilderInfo(
129133
if err != nil {
130134
return fmt.Errorf("compiling detection order output: %w", err)
131135
}
132-
orderExtString, orderExtWarnings, err := detectionOrderExtOutput(info.OrderExtensions, sharedInfo.Name)
133-
if err != nil {
134-
return fmt.Errorf("compiling detection order extensions output: %w", err)
136+
137+
var orderExtString string
138+
var orderExtWarnings []string
139+
140+
if info.Extensions != nil {
141+
orderExtString, orderExtWarnings, err = detectionOrderExtOutput(info.OrderExtensions, sharedInfo.Name)
142+
if err != nil {
143+
return fmt.Errorf("compiling detection order extensions output: %w", err)
144+
}
135145
}
136146
buildpacksString, buildpacksWarnings, err := buildpacksOutput(info.Buildpacks, sharedInfo.Name)
137147
if err != nil {
138148
return fmt.Errorf("compiling buildpacks output: %w", err)
139149
}
140150
lifecycleString, lifecycleWarnings := lifecycleOutput(info.Lifecycle, sharedInfo.Name)
141151

142-
extensionsString, extensionsWarnings, err := extensionsOutput(info.Extensions, sharedInfo.Name)
143-
if err != nil {
144-
return fmt.Errorf("compiling extensions output: %w", err)
152+
var extensionsString string
153+
var extensionsWarnings []string
154+
155+
if info.Extensions != nil {
156+
extensionsString, extensionsWarnings, err = extensionsOutput(info.Extensions, sharedInfo.Name)
157+
if err != nil {
158+
return fmt.Errorf("compiling extensions output: %w", err)
159+
}
145160
}
146161

147162
warnings = append(warnings, runImagesWarnings...)
148163
warnings = append(warnings, orderWarnings...)
149164
warnings = append(warnings, buildpacksWarnings...)
150165
warnings = append(warnings, lifecycleWarnings...)
151-
warnings = append(warnings, extensionsWarnings...)
152-
warnings = append(warnings, orderExtWarnings...)
153-
166+
if info.Extensions != nil {
167+
warnings = append(warnings, extensionsWarnings...)
168+
warnings = append(warnings, orderExtWarnings...)
169+
}
154170
outputTemplate, _ := template.New("").Parse(outputTemplate)
171+
155172
err = outputTemplate.Execute(
156173
logger.Writer(),
157174
&struct {

internal/builder/writer/human_readable_test.go

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,58 @@ Detection Order (Extensions):
9999
├ test.bp.two@test.bp.two.version (optional)
100100
└ test.bp.three@test.bp.three.version
101101
`
102+
expectedRemoteOutputWithoutExtensions = `
103+
REMOTE:
104+
105+
Description: Some remote description
106+
107+
Created By:
108+
Name: Pack CLI
109+
Version: 1.2.3
110+
111+
Trusted: No
112+
113+
Stack:
114+
ID: test.stack.id
115+
116+
Lifecycle:
117+
Version: 6.7.8
118+
Buildpack APIs:
119+
Deprecated: (none)
120+
Supported: 1.2, 2.3
121+
Platform APIs:
122+
Deprecated: 0.1, 1.2
123+
Supported: 4.5
124+
125+
Run Images:
126+
first/local (user-configured)
127+
second/local (user-configured)
128+
some/run-image
129+
first/default
130+
second/default
131+
132+
Buildpacks:
133+
ID NAME VERSION HOMEPAGE
134+
test.top.nested - test.top.nested.version -
135+
test.nested - http://geocities.com/top-bp
136+
test.bp.one - test.bp.one.version http://geocities.com/cool-bp
137+
test.bp.two - test.bp.two.version -
138+
test.bp.three - test.bp.three.version -
139+
140+
Detection Order:
141+
├ Group #1:
142+
│ ├ test.top.nested@test.top.nested.version
143+
│ │ └ Group #1:
144+
│ │ ├ test.nested
145+
│ │ │ └ Group #1:
146+
│ │ │ └ test.bp.one@test.bp.one.version (optional)
147+
│ │ ├ test.bp.three@test.bp.three.version (optional)
148+
│ │ └ test.nested.two@test.nested.two.version
149+
│ │ └ Group #2:
150+
│ │ └ test.bp.one@test.bp.one.version (optional)[cyclic]
151+
│ └ test.bp.two@test.bp.two.version (optional)
152+
└ test.bp.three@test.bp.three.version
153+
`
102154

103155
expectedLocalOutput = `
104156
LOCAL:
@@ -164,6 +216,60 @@ Detection Order (Extensions):
164216
├ test.bp.two@test.bp.two.version (optional)
165217
└ test.bp.three@test.bp.three.version
166218
`
219+
220+
expectedLocalOutputWithoutExtensions = `
221+
LOCAL:
222+
223+
Description: Some local description
224+
225+
Created By:
226+
Name: Pack CLI
227+
Version: 4.5.6
228+
229+
Trusted: No
230+
231+
Stack:
232+
ID: test.stack.id
233+
234+
Lifecycle:
235+
Version: 4.5.6
236+
Buildpack APIs:
237+
Deprecated: 4.5, 6.7
238+
Supported: 8.9, 10.11
239+
Platform APIs:
240+
Deprecated: (none)
241+
Supported: 7.8
242+
243+
Run Images:
244+
first/local (user-configured)
245+
second/local (user-configured)
246+
some/run-image
247+
first/local-default
248+
second/local-default
249+
250+
Buildpacks:
251+
ID NAME VERSION HOMEPAGE
252+
test.top.nested - test.top.nested.version -
253+
test.nested - http://geocities.com/top-bp
254+
test.bp.one - test.bp.one.version http://geocities.com/cool-bp
255+
test.bp.two - test.bp.two.version -
256+
test.bp.three - test.bp.three.version -
257+
258+
Detection Order:
259+
├ Group #1:
260+
│ ├ test.top.nested@test.top.nested.version
261+
│ │ └ Group #1:
262+
│ │ ├ test.nested
263+
│ │ │ └ Group #1:
264+
│ │ │ └ test.bp.one@test.bp.one.version (optional)
265+
│ │ ├ test.bp.three@test.bp.three.version (optional)
266+
│ │ └ test.nested.two@test.nested.two.version
267+
│ │ └ Group #2:
268+
│ │ └ test.bp.one@test.bp.one.version (optional)[cyclic]
269+
│ └ test.bp.two@test.bp.two.version (optional)
270+
└ test.bp.three@test.bp.three.version
271+
`
272+
167273
expectedVerboseStack = `
168274
Stack:
169275
ID: test.stack.id
@@ -184,10 +290,6 @@ Run Images:
184290
expectedEmptyBuildpacks = `
185291
Buildpacks:
186292
(none)
187-
`
188-
expectedEmptyExtensions = `
189-
Extensions:
190-
(none)
191293
`
192294
expectedEmptyOrder = `
193295
Detection Order:
@@ -508,7 +610,7 @@ REMOTE:
508610
})
509611

510612
when("no extensions are specified", func() {
511-
it("displays extensions as (none)", func() {
613+
it("displays no extensions as (none)", func() {
512614
localInfo.Extensions = []dist.ModuleInfo{}
513615
remoteInfo.Extensions = []dist.ModuleInfo{}
514616

@@ -518,7 +620,9 @@ REMOTE:
518620
err := humanReadableWriter.Print(logger, localRunImages, localInfo, remoteInfo, nil, nil, sharedBuilderInfo)
519621
assert.Nil(err)
520622

521-
assert.Contains(outBuf.String(), expectedEmptyExtensions)
623+
assert.Contains(outBuf.String(), "Inspecting builder: 'test-builder'")
624+
assert.Contains(outBuf.String(), expectedRemoteOutputWithoutExtensions)
625+
assert.Contains(outBuf.String(), expectedLocalOutputWithoutExtensions)
522626
})
523627
})
524628

internal/builder/writer/structured_format.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ type BuilderInfo struct {
4343
RunImages []RunImage `json:"run_images" yaml:"run_images" toml:"run_images"`
4444
Buildpacks []dist.ModuleInfo `json:"buildpacks" yaml:"buildpacks" toml:"buildpacks"`
4545
pubbldr.DetectionOrder `json:"detection_order" yaml:"detection_order" toml:"detection_order"`
46-
Extensions []dist.ModuleInfo `json:"extensions" yaml:"extensions" toml:"extensions"`
47-
OrderExtensions pubbldr.DetectionOrder `json:"order_extensions" yaml:"order_extensions" toml:"order_extensions"`
46+
Extensions []dist.ModuleInfo `json:"extensions,omitempty" yaml:"extensions,omitempty" toml:"extensions,omitempty"`
47+
OrderExtensions pubbldr.DetectionOrder `json:"order_extensions,omitempty" yaml:"order_extensions,omitempty" toml:"order_extensions,omitempty"`
4848
}
4949

5050
type StructuredFormat struct {

0 commit comments

Comments
 (0)