2015-12-08 06:49:55 +05:30
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2016-02-10 05:14:38 +05:30
|
|
|
"github.com/go-gorp/gorp"
|
|
|
|
|
2015-12-08 06:49:55 +05:30
|
|
|
"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 {
|
2016-02-10 05:14:38 +05:30
|
|
|
var dbMap *gorp.DbMap
|
2016-02-09 05:31:44 +05:30
|
|
|
if os.Getenv("DEX_TEST_DSN") == "" {
|
2016-02-10 05:14:38 +05:30
|
|
|
dbMap = db.NewMemDB()
|
|
|
|
} else {
|
|
|
|
dbMap = connect(t)
|
2015-12-08 06:49:55 +05:30
|
|
|
}
|
2016-02-09 05:31:44 +05:30
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|