Skip to content

Commit

Permalink
Omit empty stack from builder inspect
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
  • Loading branch information
jkutner committed Apr 12, 2023
1 parent 9dc7cba commit fe1db21
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/builder/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (i *Inspector) Inspect(name string, daemon bool, orderDetectionDepth int) (

stackID, err := labelManager.StackID()
if err != nil {
return Info{}, fmt.Errorf("reading image stack id: %w", err)
// TODO log warn
}

mixins, err := labelManager.Mixins()
Expand Down
4 changes: 2 additions & 2 deletions internal/builder/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func testInspect(t *testing.T, when spec.G, it spec.S) {
})
})

when("label manager returns an error for `StackID`", func() {
when("label manager does not return an error for `StackID`", func() {
it("returns the wrapped error", func() {
expectedBaseError := errors.New("label not found")

Expand All @@ -314,7 +314,7 @@ func testInspect(t *testing.T, when spec.G, it spec.S) {
)
_, err := inspector.Inspect(testBuilderName, true, pubbldr.OrderDetectionNone)

assert.ErrorWithMessage(err, "reading image stack id: label not found")
assert.Nil(err)
})
})

Expand Down
4 changes: 2 additions & 2 deletions internal/builder/writer/human_readable.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ Created By:
{{ end -}}
Trusted: {{.Trusted}}
{{ if ne .Info.Stack "" -}}
Stack:
ID: {{ .Info.Stack }}
ID: {{ .Info.Stack }}{{ end -}}
{{- if .Verbose}}
{{- if ne (len .Info.Mixins) 0 }}
Mixins:
Expand Down
12 changes: 9 additions & 3 deletions internal/builder/writer/structured_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Stack struct {
type BuilderInfo struct {
Description string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"`
CreatedBy builder.CreatorMetadata `json:"created_by" yaml:"created_by" toml:"created_by"`
Stack Stack `json:"stack" yaml:"stack" toml:"stack"`
Stack *Stack `json:"stack,omitempty" yaml:"stack,omitempty" toml:"stack,omitempty"`
Lifecycle Lifecycle `json:"lifecycle" yaml:"lifecycle" toml:"lifecycle"`
RunImages []RunImage `json:"run_images" yaml:"run_images" toml:"run_images"`
Buildpacks []dist.ModuleInfo `json:"buildpacks" yaml:"buildpacks" toml:"buildpacks"`
Expand Down Expand Up @@ -69,7 +69,10 @@ func (w *StructuredFormat) Print(
outputInfo := InspectOutput{SharedBuilderInfo: builderInfo}

if local != nil {
stack := Stack{ID: local.Stack}
var stack *Stack
if local.Stack != "" {
stack = &Stack{ID: local.Stack}
}

if logger.IsVerbose() {
stack.Mixins = local.Mixins
Expand All @@ -93,7 +96,10 @@ func (w *StructuredFormat) Print(
}

if remote != nil {
stack := Stack{ID: remote.Stack}
var stack *Stack
if remote.Stack != "" {
stack = &Stack{ID: remote.Stack}
}

if logger.IsVerbose() {
stack.Mixins = remote.Mixins
Expand Down

0 comments on commit fe1db21

Please sign in to comment.