11e229cc7f
Implement node events DB with Insert and GetLatestByEmailAndEvent. Get was changed to GetLatestByEmailAndEvent so we can verify items are being inserted into the table without needing the ID, which is not available to us in the tests. Change-Id: I4abe63631c44774cd7e795fbab0cbab4d801db4c
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
// Copyright (C) 2022 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package satellitedb_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"storj.io/common/testcontext"
|
|
"storj.io/storj/private/teststorj"
|
|
"storj.io/storj/satellite"
|
|
"storj.io/storj/satellite/nodeevents"
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
)
|
|
|
|
func TestNodeEvents(t *testing.T) {
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
testID := teststorj.NodeIDFromString("test")
|
|
testEmail := "test@storj.test"
|
|
eventType := nodeevents.Disqualified
|
|
|
|
neFromInsert, err := db.NodeEvents().Insert(ctx, testEmail, testID, eventType)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, neFromInsert.ID)
|
|
require.Equal(t, testID, neFromInsert.NodeID)
|
|
require.Equal(t, testEmail, neFromInsert.Email)
|
|
require.Equal(t, eventType, neFromInsert.Event)
|
|
require.NotNil(t, neFromInsert.CreatedAt)
|
|
require.Nil(t, neFromInsert.EmailSent)
|
|
|
|
neFromGet, err := db.NodeEvents().GetLatestByEmailAndEvent(ctx, neFromInsert.Email, neFromInsert.Event)
|
|
require.NoError(t, err)
|
|
require.Equal(t, neFromInsert, neFromGet)
|
|
})
|
|
}
|