forked from electricdusk/rushlink
db: Add a test for key validation; NFC
This commit is contained in:
parent
9d952edc67
commit
a8eba1b0df
38
internal/db/paste_test.go
Normal file
38
internal/db/paste_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package db
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValidatePasteKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
key string
|
||||
wantErr bool
|
||||
errKind error
|
||||
}{
|
||||
{"xd42__", false, nil},
|
||||
{"xd42_*", true, ErrKeyInvalidChar},
|
||||
{"xd42_/", true, ErrKeyInvalidChar},
|
||||
{"xd42_=", true, ErrKeyInvalidChar},
|
||||
{"xd42_", true, ErrKeyInvalidLength},
|
||||
{"xd42", true, ErrKeyInvalidLength},
|
||||
{"xd4", true, ErrKeyInvalidLength},
|
||||
{"xd", true, ErrKeyInvalidLength},
|
||||
{"x", true, ErrKeyInvalidLength},
|
||||
{"", true, ErrKeyInvalidLength},
|
||||
|
||||
{"KoJ5", false, nil},
|
||||
|
||||
{"__dGSJIIbBpr-SD0", false, nil},
|
||||
{"__dGSJIIbBpr-SD", true, ErrKeyInvalidLength},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.key, func(t *testing.T) {
|
||||
err := ValidatePasteKey(tt.key)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ValidatePasteKey() got error = %v, want error %v", err != nil, tt.wantErr)
|
||||
}
|
||||
if (err != nil) && err != tt.errKind {
|
||||
t.Errorf("ValidatePasteKey() error = %v, want errKind %v", err, tt.errKind)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user