forked from electricdusk/rushlink
39 lines
994 B
Go
39 lines
994 B
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|