Files
threshold/internal/bsr/chunk_test.go
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

101 lines
2.3 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package bsr_test
import (
"context"
"errors"
"testing"
"time"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/bsr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewBaseChunk(t *testing.T) {
ctx := context.Background()
now := time.Now()
cases := []struct {
name string
p bsr.Protocol
d bsr.Direction
t *bsr.Timestamp
typ bsr.ChunkType
want *bsr.BaseChunk
wantErr error
}{
{
"valid",
bsr.Protocol("TEST"),
bsr.Inbound,
bsr.NewTimestamp(now),
bsr.ChunkType("TEST"),
&bsr.BaseChunk{
Protocol: bsr.Protocol("TEST"),
Direction: bsr.Inbound,
Timestamp: bsr.NewTimestamp(now),
Type: bsr.ChunkType("TEST"),
},
nil,
},
{
"invalid-protocol",
bsr.Protocol("TEST_INVALID"),
bsr.Inbound,
bsr.NewTimestamp(now),
bsr.ChunkType("TEST"),
nil,
errors.New("bsr.NewBaseChunk: protocol name cannot be greater than 4 characters: invalid parameter"),
},
{
"invalid-direction",
bsr.Protocol("TEST"),
bsr.UnknownDirection,
bsr.NewTimestamp(now),
bsr.ChunkType("TEST"),
nil,
errors.New("bsr.NewBaseChunk: invalid direction: invalid parameter"),
},
{
"invalid-timestamp",
bsr.Protocol("TEST"),
bsr.Inbound,
nil,
bsr.ChunkType("TEST"),
nil,
errors.New("bsr.NewBaseChunk: timestamp must not be nil: invalid parameter"),
},
{
"invalid-chunk-type",
bsr.Protocol("TEST"),
bsr.Inbound,
bsr.NewTimestamp(now),
bsr.ChunkType("TEST_INVALID"),
nil,
errors.New("bsr.NewBaseChunk: chunk type cannot be greater than 4 characters: invalid parameter"),
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := bsr.NewBaseChunk(ctx, tc.p, tc.d, tc.t, tc.typ)
if tc.wantErr != nil {
assert.EqualError(t, tc.wantErr, err.Error())
return
}
require.NoError(t, err)
assert.Equal(t, tc.want, got)
assert.Equal(t, tc.want.Protocol, got.GetProtocol())
assert.Equal(t, tc.want.Direction, got.GetDirection())
assert.Equal(t, tc.want.Timestamp, got.GetTimestamp())
assert.Equal(t, tc.want.Type, got.GetType())
assert.Equal(t, tc.want.GetLength(), got.GetLength())
})
}
}