Skip to content

Commit

Permalink
Prints generated Dockerfile lines nicely (#178)
Browse files Browse the repository at this point in the history
* Prints generated Dockerfile lines nicely
* Use testhelper for getting porter output

Signed-off-by: Ryan Moran <rmoran@pivotal.io>
  • Loading branch information
Urvashi Reddy authored and carolynvs-msft committed Feb 22, 2019
1 parent 08cb21b commit 21a21f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/porter/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func (p *Porter) buildDockerFile() ([]string, error) {
lines = append(lines, p.buildPorterSection()...)
lines = append(lines, p.buildCMDSection())

fmt.Fprintln(p.Out, lines)
for _, line := range lines {
fmt.Fprintln(p.Out, line)
}

return lines, nil
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/porter/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ func TestPorter_buildDockerfile(t *testing.T) {
assert.Equal(t, wantlines, gotlines)
}

func TestPorter_buildDockerfile_output(t *testing.T) {
p := NewTestPorter(t)
p.TestConfig.SetupPorterHome()
configTpl, err := p.TestConfig.GetPorterConfigTemplate()
require.Nil(t, err)
p.TestConfig.TestContext.AddTestFileContents(configTpl, config.Name)

err = p.LoadManifest()
require.NoError(t, err)

// ignore mixins in the unit tests
p.Manifest.Mixins = []string{}

_, err = p.buildDockerFile()
require.NoError(t, err)

wantlines := `
Generating Dockerfile =======>
FROM quay.io/deis/lightweight-docker-go:v0.2.0
FROM debian:stretch
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY cnab/ /cnab/
COPY porter.yaml /cnab/app/porter.yaml
CMD ["/cnab/app/run"]
`
assert.Equal(t, wantlines, p.TestConfig.TestContext.GetOutput())
}

func TestPorter_generateDockerfile(t *testing.T) {
p := NewTestPorter(t)
p.TestConfig.SetupPorterHome()
Expand Down

0 comments on commit 21a21f8

Please sign in to comment.