Skip to content

Commit

Permalink
label can be set with empty value
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Oct 27, 2023
1 parent 7bdb947 commit 317b7c4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
5 changes: 1 addition & 4 deletions types/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ func (l *Labels) DecodeMapstructure(value interface{}) error {
case []interface{}:
labels := make(map[string]string, len(v))
for _, s := range v {
k, e, ok := strings.Cut(fmt.Sprint(s), "=")
if !ok {
return fmt.Errorf("invalid label %q", v)
}
k, e, _ := strings.Cut(fmt.Sprint(s), "=")
labels[k] = labelValue(e)
}
*l = labels
Expand Down
34 changes: 34 additions & 0 deletions types/labels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2020 The Compose Specification Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package types

import (
"testing"

"gotest.tools/v3/assert"
)

func TestDecodeLabel(t *testing.T) {
l := Labels{}
err := l.DecodeMapstructure([]any{
"a=b",
"c",
})
assert.NilError(t, err)
assert.Equal(t, l["a"], "b")
assert.Equal(t, l["c"], "")
}

0 comments on commit 317b7c4

Please sign in to comment.