mirror of
https://github.com/lightninglabs/loop
synced 2024-11-09 19:10:47 +00:00
9678c7817d
This commits adds an optional label to our swaps, and writes it to disk under a separate key in our swap bucket. This approach is chosen rather than an on-the-fly addition to our existing swap contract field so that we do not need to deal with EOF checking in the future. To allow creation of unique internal labels, we add a reserved prefix which can be used by the daemon to set labels that are distinct from client set ones.
54 lines
909 B
Go
54 lines
909 B
Go
package labels
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestValidate tests validation of labels.
|
|
func TestValidate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
label string
|
|
err error
|
|
}{
|
|
{
|
|
name: "label ok",
|
|
label: "label",
|
|
err: nil,
|
|
},
|
|
{
|
|
name: "exceeds limit",
|
|
label: strings.Repeat(" ", MaxLength+1),
|
|
err: ErrLabelTooLong,
|
|
},
|
|
{
|
|
name: "exactly reserved prefix",
|
|
label: Reserved,
|
|
err: ErrReservedPrefix,
|
|
},
|
|
{
|
|
name: "starts with reserved prefix",
|
|
label: fmt.Sprintf("%v test", Reserved),
|
|
err: ErrReservedPrefix,
|
|
},
|
|
{
|
|
name: "ends with reserved prefix",
|
|
label: fmt.Sprintf("test %v", Reserved),
|
|
err: nil,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
test := test
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
require.Equal(t, test.err, Validate(test.label))
|
|
})
|
|
}
|
|
}
|