Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Add unit test for adding labels
Browse files Browse the repository at this point in the history
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
  • Loading branch information
rumpl committed Oct 31, 2019
1 parent 248d5ab commit 903f3c0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 0 additions & 1 deletion e2e/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ func TestRunWithLabels(t *testing.T) {
"myapp_db", "myapp_web", "myapp_api",
}
for _, service := range services {
fmt.Printf("%q", service)
cmd.Command = dockerCli.Command("inspect", service)
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 0,
Expand Down
41 changes: 41 additions & 0 deletions internal/commands/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package commands

import (
"bytes"
"encoding/json"
"fmt"
"strings"
"testing"

"github.com/deislabs/cnab-go/bundle"
"github.com/deislabs/cnab-go/bundle/definition"
"github.com/deislabs/cnab-go/claim"
"github.com/docker/app/internal"
"github.com/docker/app/internal/packager"
"github.com/docker/app/internal/store"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
Expand Down Expand Up @@ -264,3 +267,41 @@ func TestMergeBundleParameters(t *testing.T) {
assert.ErrorContains(t, err, "invalid value for parameter")
})
}

func TestLabels(t *testing.T) {
expected := packager.DockerAppArgs{
Labels: map[string]string{
"label": "value",
},
}
expectedStr, err := json.Marshal(expected)
assert.NilError(t, err)

labels := []string{
"label=value",
}
op := withLabels(labels)

config := &mergeBundleConfig{
bundle: &bundle.Bundle{
Parameters: map[string]bundle.Parameter{
internal.ParameterArgs: {},
},
},
params: map[string]string{},
}
err = op(config)
assert.NilError(t, err)
fmt.Println(config.params)
l := config.params[internal.ParameterArgs]
assert.Equal(t, l, string(expectedStr))
}

func TestInvalidLabels(t *testing.T) {
labels := []string{
"com.docker.app.label=value",
}
op := withLabels(labels)
err := op(&mergeBundleConfig{})
assert.ErrorContains(t, err, fmt.Sprintf("labels cannot start with %q", internal.Namespace))
}

0 comments on commit 903f3c0

Please sign in to comment.