Skip to content

Commit

Permalink
.: Add test for commamap flag
Browse files Browse the repository at this point in the history
Copied from catalyst-api too
  • Loading branch information
victorges committed Jun 24, 2024
1 parent 3a7dbfc commit 545098e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions catalyst-uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/rand"
"encoding/json"
"flag"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -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{})
}

0 comments on commit 545098e

Please sign in to comment.