From 62c57f756a465afd41ad8f9307202e6b118b60fa Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Tue, 5 Dec 2023 15:53:00 +0100 Subject: [PATCH] test fixes --- echo/echo_integration_test.go | 9 ++++++--- vdr/didweb/manager_test.go | 1 + vdr/didweb/store_test.go | 12 +++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/echo/echo_integration_test.go b/echo/echo_integration_test.go index bd086e3964..cc1e2c06e9 100644 --- a/echo/echo_integration_test.go +++ b/echo/echo_integration_test.go @@ -35,9 +35,6 @@ import ( // TestStatusCodes tests if the returned errors from the API implementations are correctly translated to status codes func TestStatusCodes(t *testing.T) { - hook := logTest.NewGlobal() - baseUrl, _ := node.StartServer(t) - type operation struct { module string operation string @@ -45,6 +42,9 @@ func TestStatusCodes(t *testing.T) { body interface{} } t.Run("404s", func(t *testing.T) { + hook := logTest.NewGlobal() + baseUrl, _ := node.StartServer(t) + testCases := []operation{ {module: "Auth", operation: "GetSignSessionStatus", url: "/internal/auth/v1/signature/session/1"}, {module: "Auth", operation: "GetContractByType", url: "/public/auth/v1/contract/1"}, @@ -66,6 +66,9 @@ func TestStatusCodes(t *testing.T) { } }) t.Run("400s", func(t *testing.T) { + hook := logTest.NewGlobal() + baseUrl, _ := node.StartServer(t) + testCases := []operation{ {module: "Crypto", operation: "SignJwt", url: "/internal/crypto/v1/sign_jwt", body: map[string]interface{}{"kid": "fpp", "claims": map[string]interface{}{"foo": "bar"}}}, {module: "Network", operation: "GetTransaction", url: "/internal/network/v1/transaction/invalidhash"}, diff --git a/vdr/didweb/manager_test.go b/vdr/didweb/manager_test.go index c25839a91a..09f1306bba 100644 --- a/vdr/didweb/manager_test.go +++ b/vdr/didweb/manager_test.go @@ -52,6 +52,7 @@ func TestManager_Create(t *testing.T) { require.NoError(t, keyAsJWK.Raw(&publicKey)) t.Run("ok", func(t *testing.T) { + resetStore(t, storageEngine.GetSQLDatabase()) ctrl := gomock.NewController(t) keyStore := nutsCrypto.NewMockKeyStore(ctrl) keyStore.EXPECT().New(gomock.Any(), gomock.Any()).Return(nutsCrypto.TestPublicKey{ diff --git a/vdr/didweb/store_test.go b/vdr/didweb/store_test.go index 8d01db49b5..d6742d69f6 100644 --- a/vdr/didweb/store_test.go +++ b/vdr/didweb/store_test.go @@ -94,11 +94,13 @@ func Test_sqlStore_get(t *testing.T) { } func resetStore(t *testing.T, db *gorm.DB) { - underlyingDB, err := db.DB() - require.NoError(t, err) - // related tables are emptied due to on-delete-cascade clause - _, err = underlyingDB.Exec("DELETE FROM vdr_didweb") - require.NoError(t, err) + t.Cleanup(func() { + underlyingDB, err := db.DB() + require.NoError(t, err) + // related tables are emptied due to on-delete-cascade clause + _, err = underlyingDB.Exec("DELETE FROM vdr_didweb") + require.NoError(t, err) + }) } func testVerificationMethod(t *testing.T, owner did.DID) did.VerificationMethod {