Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 903f3c0

Browse files
committed
Add unit test for adding labels
Signed-off-by: Djordje Lukic <[email protected]>
1 parent 248d5ab commit 903f3c0

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

e2e/commands_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ func TestRunWithLabels(t *testing.T) {
208208
"myapp_db", "myapp_web", "myapp_api",
209209
}
210210
for _, service := range services {
211-
fmt.Printf("%q", service)
212211
cmd.Command = dockerCli.Command("inspect", service)
213212
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
214213
ExitCode: 0,

internal/commands/parameters_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package commands
22

33
import (
44
"bytes"
5+
"encoding/json"
6+
"fmt"
57
"strings"
68
"testing"
79

810
"github.com/deislabs/cnab-go/bundle"
911
"github.com/deislabs/cnab-go/bundle/definition"
1012
"github.com/deislabs/cnab-go/claim"
1113
"github.com/docker/app/internal"
14+
"github.com/docker/app/internal/packager"
1215
"github.com/docker/app/internal/store"
1316
"gotest.tools/assert"
1417
"gotest.tools/assert/cmp"
@@ -264,3 +267,41 @@ func TestMergeBundleParameters(t *testing.T) {
264267
assert.ErrorContains(t, err, "invalid value for parameter")
265268
})
266269
}
270+
271+
func TestLabels(t *testing.T) {
272+
expected := packager.DockerAppArgs{
273+
Labels: map[string]string{
274+
"label": "value",
275+
},
276+
}
277+
expectedStr, err := json.Marshal(expected)
278+
assert.NilError(t, err)
279+
280+
labels := []string{
281+
"label=value",
282+
}
283+
op := withLabels(labels)
284+
285+
config := &mergeBundleConfig{
286+
bundle: &bundle.Bundle{
287+
Parameters: map[string]bundle.Parameter{
288+
internal.ParameterArgs: {},
289+
},
290+
},
291+
params: map[string]string{},
292+
}
293+
err = op(config)
294+
assert.NilError(t, err)
295+
fmt.Println(config.params)
296+
l := config.params[internal.ParameterArgs]
297+
assert.Equal(t, l, string(expectedStr))
298+
}
299+
300+
func TestInvalidLabels(t *testing.T) {
301+
labels := []string{
302+
"com.docker.app.label=value",
303+
}
304+
op := withLabels(labels)
305+
err := op(&mergeBundleConfig{})
306+
assert.ErrorContains(t, err, fmt.Sprintf("labels cannot start with %q", internal.Namespace))
307+
}

0 commit comments

Comments
 (0)