loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit 5824a99abca1e279fbb09f9767ca7c89061b16cf
parent 730d29537bc227232eb473b69c6f885988a6c58d
Author: Sebastian Mancke <s.mancke@tarent.de>
Date:   Fri, 18 Nov 2016 21:08:43 +0100

added config test

Diffstat:
Mlogin/config.go | 1+
Mlogin/config_test.go | 57++++++++++++++++++++++++++++++++++-----------------------
2 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/login/config.go b/login/config.go @@ -88,6 +88,7 @@ func parseBackendOptions(b string) (map[string]string, error) { } return opts, nil } + func randStringBytes(n int) string { b := make([]byte, n) for i := range b { diff --git a/login/config_test.go b/login/config_test.go @@ -6,53 +6,64 @@ import ( "testing" ) -func TestConfig_GetBackendOptions(t *testing.T) { +func TestConfig_ParseBackendOptions(t *testing.T) { testCases := []struct { - backends []string - parsedOptions BackendOptions - expectError bool + input []string + expected BackendOptions + expectError bool }{ { []string{}, - []map[string]string{}, + BackendOptions{}, false, }, { + []string{"name=p1,key1=value1,key2=value2"}, + BackendOptions{}, + true, // no provider name specified + }, + { []string{ - "name=p1,key1=value1,key2=value2", - "name=p2,key3=value3,key4=value4", + "provider=simple,name=p1,key1=value1,key2=value2", + "provider=simple,name=p2,key3=value3,key4=value4", }, - []map[string]string{ + BackendOptions{ map[string]string{ - "name": "p1", - "key1": "value1", - "key2": "value2", + "provider": "simple", + "name": "p1", + "key1": "value1", + "key2": "value2", }, map[string]string{ - "name": "p2", - "key3": "value3", - "key4": "value4", + "provider": "simple", + "name": "p2", + "key3": "value3", + "key4": "value4", }, }, false, }, { []string{"foo"}, - nil, + BackendOptions{}, true, }, } for i, test := range testCases { t.Run(fmt.Sprintf("test %v", i), func(t *testing.T) { - cfg := &Config{} - cfg.Backends = test.backends - opts, err := cfg.GetBackendOptions() - if test.expectError { - assert.Error(t, err) - } else { - assert.NoError(t, err) - assert.Equal(t, opts, test.parsedOptions) + options := &BackendOptions{} + for _, input := range test.input { + err := options.Set(input) + if test.expectError { + assert.Error(t, err) + } else { + if err != nil { + assert.NoError(t, err) + continue + } + } } + assert.Equal(t, test.expected, *options) }) } }