49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package testkit
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"galaxy/authsession/internal/domain/common"
|
|
"galaxy/authsession/internal/domain/gatewayprojection"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRecordingProjectionPublisherConsumesScriptedErrorsAndRecordsAttempts(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
publisher := &RecordingProjectionPublisher{
|
|
Errors: []error{errors.New("first publish failed"), nil},
|
|
}
|
|
snapshot := projectionSnapshotFixture()
|
|
|
|
err := publisher.PublishSession(context.Background(), snapshot)
|
|
require.Error(t, err)
|
|
|
|
err = publisher.PublishSession(context.Background(), snapshot)
|
|
require.NoError(t, err)
|
|
|
|
published := publisher.PublishedSnapshots()
|
|
require.Len(t, published, 2)
|
|
assert.Equal(t, snapshot.DeviceSessionID, published[0].DeviceSessionID)
|
|
assert.Equal(t, snapshot.DeviceSessionID, published[1].DeviceSessionID)
|
|
|
|
published[0].ClientPublicKey = "mutated"
|
|
|
|
stable := publisher.PublishedSnapshots()
|
|
require.Len(t, stable, 2)
|
|
assert.Equal(t, snapshot.ClientPublicKey, stable[0].ClientPublicKey)
|
|
}
|
|
|
|
func projectionSnapshotFixture() gatewayprojection.Snapshot {
|
|
return gatewayprojection.Snapshot{
|
|
DeviceSessionID: common.DeviceSessionID("device-session-1"),
|
|
UserID: common.UserID("user-1"),
|
|
ClientPublicKey: "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=",
|
|
Status: gatewayprojection.StatusActive,
|
|
}
|
|
}
|