sharing.go
TLDR
The file sharing.go
in the storetests
package contains a test function called StoreTestSharingStore
. This function tests the UpsertSharing()
and GetSharing()
methods of the store.Store
interface. The test function creates and retrieves sharing objects using the store, and verifies the correctness of the operations.
Methods
StoreTestSharingStore
The StoreTestSharingStore
function is a test function that takes a testing object and a setup function as input. It runs sub-tests to test the UpsertSharing()
and GetSharing()
methods of the store. It creates and retrieves sharing objects using the store, and asserts the expected results.
testUpsertSharingAndGetSharing
The testUpsertSharingAndGetSharing
function is a helper function used by StoreTestSharingStore
. It performs sub-tests to test the UpsertSharing()
and GetSharing()
methods of the store. It creates and retrieves sharing objects using the store, and checks if the expected sharing object matches the retrieved sharing object.
package storetests
import (
"testing"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/store"
"github.com/stretchr/testify/require"
)
func StoreTestSharingStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
t.Run("UpsertSharingAndGetSharing", func(t *testing.T) {
store, tearDown := setup(t)
defer tearDown()
testUpsertSharingAndGetSharing(t, store)
})
}
func testUpsertSharingAndGetSharing(t *testing.T, store store.Store) {
t.Run("Insert first sharing and get it", func(t *testing.T) {
sharing := model.Sharing{
ID: "sharing-id",
Enabled: true,
Token: "token",
ModifiedBy: testUserID,
}
err := store.UpsertSharing(sharing)
require.NoError(t, err)
newSharing, err := store.GetSharing("sharing-id")
require.NoError(t, err)
newSharing.UpdateAt = 0
require.Equal(t, sharing, *newSharing)
})
t.Run("Upsert the inserted sharing and get it", func(t *testing.T) {
sharing := model.Sharing{
ID: "sharing-id",
Enabled: true,
Token: "token2",
ModifiedBy: "user-id2",
}
newSharing, err := store.GetSharing("sharing-id")
require.NoError(t, err)
newSharing.UpdateAt = 0
require.NotEqual(t, sharing, *newSharing)
err = store.UpsertSharing(sharing)
require.NoError(t, err)
newSharing, err = store.GetSharing("sharing-id")
require.NoError(t, err)
newSharing.UpdateAt = 0
require.Equal(t, sharing, *newSharing)
})
t.Run("Get not existing sharing", func(t *testing.T) {
_, err := store.GetSharing("not-existing")
require.Error(t, err)
require.True(t, model.IsErrNotFound(err))
})
}