mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-01 12:55:21 +01:00
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
|
package endpoint
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestParseJobAndGuidBookmarkName(t *testing.T) {
|
||
|
|
||
|
type Case struct {
|
||
|
input string
|
||
|
expectErr bool
|
||
|
|
||
|
guid uint64
|
||
|
jobid string
|
||
|
}
|
||
|
|
||
|
cases := []Case{
|
||
|
{
|
||
|
`p1/sync#zrepl_CURSOR_G_932f3a7089080ce2_J_push with legitimate name`,
|
||
|
false, 0x932f3a7089080ce2, "push with legitimate name",
|
||
|
},
|
||
|
{
|
||
|
input: `p1/sync#zrepl_CURSOR_G_932f3a7089_J_push with legitimate name`,
|
||
|
expectErr: true,
|
||
|
},
|
||
|
{
|
||
|
input: `p1/sync#zrepl_CURSOR_G_932f3a7089080ce2_J_push with il\tlegitimate name`,
|
||
|
expectErr: true,
|
||
|
},
|
||
|
{
|
||
|
input: `p1/sync#otherprefix_G_932f3a7089080ce2_J_push with legitimate name`,
|
||
|
expectErr: true,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for i := range cases {
|
||
|
t.Run(cases[i].input, func(t *testing.T) {
|
||
|
guid, jobid, err := parseJobAndGuidBookmarkName(cases[i].input, replicationCursorBookmarkNamePrefix)
|
||
|
if cases[i].expectErr {
|
||
|
assert.Error(t, err)
|
||
|
} else {
|
||
|
assert.NoError(t, err)
|
||
|
assert.Equal(t, cases[i].guid, guid)
|
||
|
assert.Equal(t, MustMakeJobID(cases[i].jobid), jobid)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
}
|