github.com/msales/pkg/v3@v3.24.0/clix/stats_test.go (about) 1 package clix_test 2 3 import ( 4 "testing" 5 6 "github.com/msales/pkg/v3/clix" 7 "github.com/msales/pkg/v3/log" 8 "github.com/msales/pkg/v3/stats" 9 "github.com/stretchr/testify/assert" 10 "gopkg.in/urfave/cli.v1" 11 ) 12 13 func TestNewStats(t *testing.T) { 14 tests := []struct { 15 dsn string 16 prefix string 17 tags *cli.StringSlice 18 19 shouldErr bool 20 }{ 21 {"statsd://localhost:8125", "test", &cli.StringSlice{}, false}, 22 {"", "test", &cli.StringSlice{}, false}, 23 {"l2met://", "test", &cli.StringSlice{}, false}, 24 {"prometheus://", "test", &cli.StringSlice{}, false}, 25 {"prometheus://:51234", "test", &cli.StringSlice{}, false}, 26 {"l2met://", "", &cli.StringSlice{}, false}, 27 {"invalid-scheme", "", &cli.StringSlice{}, true}, 28 {"unknownscheme://", "", &cli.StringSlice{}, true}, 29 {":/", "", &cli.StringSlice{}, true}, 30 {"l2met://", "", &cli.StringSlice{"a"}, true}, 31 } 32 33 for _, tt := range tests { 34 c, fs := newTestContext() 35 fs.String(clix.FlagStatsDSN, tt.dsn, "doc") 36 fs.String(clix.FlagStatsPrefix, tt.prefix, "doc") 37 fs.Var(tt.tags, clix.FlagStatsTags, "doc") 38 39 s, err := clix.NewStats(c, log.Null) 40 41 if tt.shouldErr { 42 assert.Error(t, err) 43 } else { 44 assert.NoError(t, err) 45 assert.Implements(t, (*stats.Stats)(nil), s) 46 } 47 } 48 }