Skip to content

Commit 45b7f09

Browse files
committed
Added unit-test for ConvertTagsToMap in util/util_test.go
1 parent cd10164 commit 45b7f09

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Diff for: pkg/blob/blob_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,15 @@ func TestGetContainerReference(t *testing.T) {
774774
"accountName": fakeAccountName,
775775
}),
776776
},
777+
{
778+
name: "failed to obtain client",
779+
containerName: fakeContainerName,
780+
secrets: map[string]string{
781+
"accountName": fakeAccountName,
782+
"accountKey": fakeAccountKey,
783+
},
784+
expectedError: fmt.Errorf("azure: base storage service url required"),
785+
},
777786
/*{
778787
name: "container reference is nil",
779788
containerName: fakeContainerName,

Diff for: pkg/util/util_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package util
1818

1919
import (
20+
"fmt"
2021
"os"
2122
"testing"
2223
"time"
@@ -166,3 +167,37 @@ func TestMakeDir(t *testing.T) {
166167
err = os.RemoveAll(targetTest)
167168
assert.NoError(t, err)
168169
}
170+
171+
func TestConvertTagsToMap(t *testing.T) {
172+
tests := []struct {
173+
desc string
174+
tags string
175+
expectedOut map[string]string
176+
expectedErr error
177+
}{
178+
{
179+
desc: "Improper KeyValuePair",
180+
tags: "foo=bar=gar,lorem=ipsum",
181+
expectedOut: nil,
182+
expectedErr: fmt.Errorf("Tags '%s' are invalid, the format should like: 'key1=value1,key2=value2'", "foo=bar=gar,lorem=ipsum"),
183+
},
184+
{
185+
desc: "Missing Key",
186+
tags: "=bar,lorem=ipsum",
187+
expectedOut: nil,
188+
expectedErr: fmt.Errorf("Tags '%s' are invalid, the format should like: 'key1=value1,key2=value2'", "=bar,lorem=ipsum"),
189+
},
190+
{
191+
desc: "Successful Input/Output",
192+
tags: "foo=bar,lorem=ipsum",
193+
expectedOut: map[string]string{"foo": "bar", "lorem": "ipsum"},
194+
expectedErr: nil,
195+
},
196+
}
197+
198+
for _, test := range tests {
199+
output, err := ConvertTagsToMap(test.tags)
200+
assert.Equal(t, test.expectedOut, output, test.desc)
201+
assert.Equal(t, test.expectedErr, err, test.desc)
202+
}
203+
}

0 commit comments

Comments
 (0)