Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/iam"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/kms"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestUpsertSessionInfo(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.Background()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
testKms := kms.TestKms(t, conn, wrapper)
|
|
testRepo, err := NewRepository(ctx, rw, rw, testKms)
|
|
require.NoError(t, err)
|
|
iamRepo := iam.TestRepo(t, conn, wrapper)
|
|
iam.TestScopes(t, iamRepo)
|
|
|
|
tests := []struct {
|
|
name string
|
|
workerId string
|
|
expectedErrMsg string
|
|
}{
|
|
{
|
|
name: "empty worker id",
|
|
expectedErrMsg: "missing worker id",
|
|
},
|
|
{
|
|
name: "worker does not exist",
|
|
workerId: "w_dne",
|
|
expectedErrMsg: "server.(Repository).UpsertSessionInfo: failed for w_dne: db.DoTx: db.Create: wt_public_id_check constraint failed: check constraint violated: integrity violation: error #1000",
|
|
},
|
|
{
|
|
name: "success",
|
|
workerId: func() string {
|
|
return TestPkiWorker(t, conn, wrapper).PublicId
|
|
}(),
|
|
},
|
|
{
|
|
name: "upsert on conflict",
|
|
workerId: func() string {
|
|
workerId := TestPkiWorker(t, conn, wrapper).PublicId
|
|
require.NoError(t, testRepo.UpsertSessionInfo(context.Background(), workerId))
|
|
return workerId
|
|
}(),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
err := testRepo.UpsertSessionInfo(context.Background(), tt.workerId)
|
|
if tt.expectedErrMsg != "" {
|
|
require.Error(err)
|
|
assert.ErrorContains(err, tt.expectedErrMsg)
|
|
return
|
|
}
|
|
require.NoError(err)
|
|
})
|
|
}
|
|
}
|