From 2b13bdd12d1372ab2190e92f8aead737c03e1fba Mon Sep 17 00:00:00 2001 From: Daniel Dao Date: Fri, 27 Oct 2017 12:09:33 +0100 Subject: [PATCH] storage: fix list connector test The previous test doesnt actually testing ListConnectors code. For example the following pseudocode will pass the test: ``` ListConnectors() { return nil, nil } ``` Instead change to actually fetch and compare list of connectors, ordering by name --- storage/conformance/conformance.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/storage/conformance/conformance.go b/storage/conformance/conformance.go index 0bfc4745..eb038b14 100644 --- a/storage/conformance/conformance.go +++ b/storage/conformance/conformance.go @@ -628,9 +628,21 @@ func testConnectorCRUD(t *testing.T, s storage.Storage) { c1.Type = "oidc" getAndCompare(id1, c1) - if _, err := s.ListConnectors(); err != nil { - t.Fatalf("failed to list connectors: %v", err) + connectorList := []storage.Connector{c1, c2} + listAndCompare := func(want []storage.Connector) { + connectors, err := s.ListConnectors() + if err != nil { + t.Errorf("list connectors: %v", err) + return + } + sort.Slice(connectors, func(i, j int) bool { + return connectors[i].Name < connectors[j].Name + }) + if diff := pretty.Compare(want, connectors); diff != "" { + t.Errorf("password list retrieved from storage did not match: %s", diff) + } } + listAndCompare(connectorList) if err := s.DeleteConnector(c1.ID); err != nil { t.Fatalf("failed to delete connector: %v", err)