Files
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
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>
2026-10-12 10:33:41 -07:00

85 lines
2.2 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package auth
import (
"context"
"testing"
"time"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db/timestamp"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/pagination"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type fakeItem struct {
pagination.Item
publicId string
createTime time.Time
updateTime time.Time
}
func (p *fakeItem) GetPublicId() string {
return p.publicId
}
func (p *fakeItem) GetUpdateTime() *timestamp.Timestamp {
return timestamp.New(p.updateTime)
}
func (p *fakeItem) GetCreateTime() *timestamp.Timestamp {
return timestamp.New(p.createTime)
}
// Test_GetOpts provides unit tests for GetOpts and all the options
func Test_GetOpts(t *testing.T) {
t.Parallel()
t.Run("WithLimit", func(t *testing.T) {
ctx := context.Background()
opts, err := GetOpts()
require.NoError(t, err)
testOpts := getDefaultOptions()
testOpts.WithLimit = 0
assert.Equal(t, opts, testOpts)
opts, err = GetOpts(WithLimit(ctx, -1))
require.NoError(t, err)
testOpts = getDefaultOptions()
testOpts.WithLimit = -1
assert.Equal(t, opts, testOpts)
opts, err = GetOpts(WithLimit(ctx, 1))
require.NoError(t, err)
testOpts = getDefaultOptions()
testOpts.WithLimit = 1
assert.Equal(t, opts, testOpts)
})
t.Run("WithReaderWriter", func(t *testing.T) {
t.Parallel()
t.Run("success", func(t *testing.T) {
t.Parallel()
_, err := GetOpts()
require.NoError(t, err)
})
})
t.Run("WithStartPageAfterItem", func(t *testing.T) {
assert := assert.New(t)
updateTime := time.Now()
createTime := time.Now()
opts, err := GetOpts(WithStartPageAfterItem(context.Background(), &fakeItem{nil, "s_1", createTime, updateTime}))
require.NoError(t, err)
assert.Equal(opts.WithStartPageAfterItem.GetPublicId(), "s_1")
assert.Equal(opts.WithStartPageAfterItem.GetUpdateTime(), timestamp.New(updateTime))
assert.Equal(opts.WithStartPageAfterItem.GetCreateTime(), timestamp.New(createTime))
})
t.Run("WithUnauthenticatedUser", func(t *testing.T) {
t.Parallel()
ctx := context.Background()
opts, err := GetOpts(WithUnauthenticatedUser(ctx, true))
require.NoError(t, err)
assert.True(t, opts.WithUnauthenticatedUser)
})
}