From 545098e685c76b038a7a847b3f51a4783ff9c3b3 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Mon, 24 Jun 2024 19:42:15 +0100 Subject: [PATCH] .: Add test for commamap flag Copied from catalyst-api too --- catalyst-uploader_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/catalyst-uploader_test.go b/catalyst-uploader_test.go index 52b7367..07df036 100644 --- a/catalyst-uploader_test.go +++ b/catalyst-uploader_test.go @@ -5,6 +5,7 @@ import ( "context" "crypto/rand" "encoding/json" + "flag" "fmt" "net/http" "net/url" @@ -166,3 +167,25 @@ func TestFormatsE2E(t *testing.T) { require.Equal(t, h.UriSchemes(), driverDescr.Drivers[i].UriSchemes) } } + +func TestCommaMap(t *testing.T) { + fs := flag.NewFlagSet("cli-test", flag.PanicOnError) + single := CommaMapFlag(fs, "single", "") + multi := CommaMapFlag(fs, "multi", "") + setEmpty := CommaMapFlag(fs, "empty", "") + err := fs.Parse([]string{ + "-single=one=uno", + "-multi=one=uno,two=dos,three=tres", + "-empty=", + }) + require.NoError(t, err) + require.Equal(t, *single, map[string]string{"one": "uno"}) + require.Equal(t, *multi, map[string]string{"one": "uno", "two": "dos", "three": "tres"}) + require.Equal(t, *setEmpty, map[string]string{}) + + fs2 := flag.NewFlagSet("cli-test", flag.ContinueOnError) + wrong := CommaMapFlag(fs2, "wrong", "") + err = fs2.Parse([]string{"-wrong=format"}) + require.Error(t, err) + require.Equal(t, *wrong, map[string]string{}) +}