2015-12-08 06:49:55 +05:30
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/coreos/dex/connector"
|
|
|
|
"github.com/coreos/dex/db"
|
|
|
|
)
|
|
|
|
|
2016-02-09 05:31:44 +05:30
|
|
|
func newConnectorConfigRepo(t *testing.T, configs []connector.ConnectorConfig) connector.ConnectorConfigRepo {
|
|
|
|
if os.Getenv("DEX_TEST_DSN") == "" {
|
|
|
|
return connector.NewConnectorConfigRepoFromConfigs(configs)
|
2015-12-08 06:49:55 +05:30
|
|
|
}
|
2016-02-09 05:31:44 +05:30
|
|
|
dbMap := connect(t)
|
|
|
|
repo := db.NewConnectorConfigRepo(dbMap)
|
|
|
|
if err := repo.Set(configs); err != nil {
|
|
|
|
t.Fatalf("Unable to set connector configs: %v", err)
|
2015-12-08 06:49:55 +05:30
|
|
|
}
|
2016-02-09 05:31:44 +05:30
|
|
|
return repo
|
2015-12-08 06:49:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestConnectorConfigRepoGetByID(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
cfgs []connector.ConnectorConfig
|
|
|
|
id string
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
cfgs: []connector.ConnectorConfig{
|
|
|
|
&connector.LocalConnectorConfig{ID: "local"},
|
|
|
|
},
|
|
|
|
id: "local",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cfgs: []connector.ConnectorConfig{
|
|
|
|
&connector.LocalConnectorConfig{ID: "local1"},
|
|
|
|
&connector.LocalConnectorConfig{ID: "local2"},
|
|
|
|
},
|
|
|
|
id: "local2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cfgs: []connector.ConnectorConfig{
|
|
|
|
&connector.LocalConnectorConfig{ID: "local1"},
|
|
|
|
&connector.LocalConnectorConfig{ID: "local2"},
|
|
|
|
},
|
|
|
|
id: "foo",
|
|
|
|
err: connector.ErrorNotFound,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
2016-02-09 05:31:44 +05:30
|
|
|
repo := newConnectorConfigRepo(t, tt.cfgs)
|
2015-12-08 06:49:55 +05:30
|
|
|
if _, err := repo.GetConnectorByID(nil, tt.id); err != tt.err {
|
|
|
|
t.Errorf("case %d: want=%v, got=%v", i, tt.err, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|