Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manifest.go): fix Name property, add Description, add test #104

Merged
merged 3 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/config/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type Manifest struct {
path string
outputs map[string]string

Name string `yaml:"image,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like image is no longer being populated anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, if there was an image field in the example porter.yaml at one point, it is no longer there. I've assumed this should point to the name field, which is populated.

Name string `yaml:"name,omitempty"`
Description string `yaml:"description,omitempty"`
Version string `yaml:"version,omitempty"`
Image string `yaml:"invocationImage,omitempty"`
Mixins []string `yaml:"mixins,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/porter/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ func (p *Porter) rewriteImageWithDigest(InvocationImage string, digest string) (
func (p *Porter) buildBundle(invocationImage string, digest string) error {
fmt.Printf("\nGenerating Bundle File with Invocation Image %s =======> \n", invocationImage)
bundle := Bundle{
Name: p.Config.Manifest.Name,
Version: p.Config.Manifest.Version,
Name: p.Config.Manifest.Name,
Description: p.Config.Manifest.Description,
Version: p.Config.Manifest.Version,
}
image := InvocationImage{
Image: invocationImage,
Expand All @@ -285,7 +286,6 @@ func (p *Porter) buildBundle(invocationImage string, digest string) error {
bundle.Parameters = p.generateBundleParameters()
bundle.Credentials = p.generateBundleCredentials()
return p.WriteFile(bundle, 0644)

}

func (p *Porter) generateBundleParameters() map[string]ParameterDefinition {
Expand Down
34 changes: 34 additions & 0 deletions pkg/porter/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package porter
import (
"testing"

"encoding/json"

"github.com/deislabs/porter/pkg/config"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -80,3 +82,35 @@ func TestPorter_prepareDockerFilesystem(t *testing.T) {
require.NoError(t, err)
assert.True(t, execMixinExists, "The exec-runtime mixin wasn't copied into %s", wantExecMixin)
}

func TestPorter_buildBundle(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever else happens, let's make sure to keep a new test. 👍

p := NewTestPorter(t)
p.TestConfig.SetupPorterHome()

p.TestConfig.TestContext.AddTestFile("../../templates/porter.yaml", config.Name)
err := p.LoadManifest()
require.NoError(t, err)

err = p.buildBundle("foo", "digest")
require.NoError(t, err)

bundleJSONExists, err := p.FileSystem.Exists("bundle.json")
require.NoError(t, err)
require.True(t, bundleJSONExists, "bundle.json wasn't written")

f, _ := p.FileSystem.Stat("bundle.json")
if f.Size() == 0 {
t.Fatalf("bundle.json is empty")
}

bundleBytes, err := p.FileSystem.ReadFile("bundle.json")
require.NoError(t, err)

var bundle Bundle
err = json.Unmarshal(bundleBytes, &bundle)
require.NoError(t, err)

require.Equal(t, bundle.Name, "HELLO")
require.Equal(t, bundle.Version, "0.1.0")
require.Equal(t, bundle.Description, "An example Porter configuration")
}
1 change: 1 addition & 0 deletions templates/porter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mixins:

name: HELLO
version: 0.1.0
description: "An example Porter configuration"
invocationImage: porter-hello:latest

install:
Expand Down