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>
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package bsr_test
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/bsr"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMagic(t *testing.T) {
|
|
assert.Equal(t, string(bsr.Magic), "\x89BSR\r\n\x1a\n")
|
|
assert.Equal(t, bsr.Magic.Bytes(), []byte("\x89BSR\r\n\x1a\n"))
|
|
}
|
|
|
|
func TestReadMagic(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
r io.Reader
|
|
want error
|
|
}{
|
|
{
|
|
"valid",
|
|
bytes.NewBuffer([]byte(bsr.Magic)),
|
|
nil,
|
|
},
|
|
{
|
|
"nil-reader",
|
|
nil,
|
|
errors.New("bsr.ReadMagic: reader is nil: invalid parameter"),
|
|
},
|
|
{
|
|
"not-enough-chars",
|
|
bytes.NewBuffer([]byte(bsr.Magic)[:len(bsr.Magic)-1]),
|
|
errors.New("bsr.ReadMagic: unexpected EOF"),
|
|
},
|
|
{
|
|
"not-magic",
|
|
bytes.NewBuffer([]byte("notthemagic")),
|
|
errors.New("bsr.ReadMagic: invalid magic string"),
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := bsr.ReadMagic(tc.r)
|
|
if tc.want == nil {
|
|
assert.NoError(t, got)
|
|
return
|
|
}
|
|
assert.EqualError(t, got, tc.want.Error())
|
|
})
|
|
}
|
|
}
|