mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-11 01:42:15 +01:00
adding ROOT_PATH + tests
This commit is contained in:
@@ -2,6 +2,7 @@ package xassert
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||
)
|
||||
@@ -54,7 +55,67 @@ func StringOneOf(values []string) RuleString {
|
||||
}
|
||||
}
|
||||
|
||||
type ruleStringStartWith struct {
|
||||
*baseRuleString
|
||||
startWith string
|
||||
}
|
||||
|
||||
func (r ruleStringStartWith) validate() error {
|
||||
const op string = "xassert.ruleStringStartWith.validate"
|
||||
if strings.HasPrefix(r.value, r.startWith) {
|
||||
return nil
|
||||
}
|
||||
return xerror.Invalid(
|
||||
op,
|
||||
fmt.Sprintf("'%s' should start with '%s', got '%s'", r.key, r.startWith, r.value),
|
||||
nil,
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
StringStartWith returns a RuleString for
|
||||
validating that a string starts with
|
||||
given string.
|
||||
*/
|
||||
func StringStartWith(startWith string) RuleString {
|
||||
return ruleStringStartWith{
|
||||
&baseRuleString{},
|
||||
startWith,
|
||||
}
|
||||
}
|
||||
|
||||
type ruleStringEndWith struct {
|
||||
*baseRuleString
|
||||
endWith string
|
||||
}
|
||||
|
||||
func (r ruleStringEndWith) validate() error {
|
||||
const op string = "xassert.ruleStringEndWith.validate"
|
||||
if strings.HasSuffix(r.value, r.endWith) {
|
||||
return nil
|
||||
}
|
||||
return xerror.Invalid(
|
||||
op,
|
||||
fmt.Sprintf("'%s' should end with '%s', got '%s'", r.key, r.endWith, r.value),
|
||||
nil,
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
StringEndWith returns a RuleString for
|
||||
validating that a string ends with
|
||||
given string.
|
||||
*/
|
||||
func StringEndWith(endWith string) RuleString {
|
||||
return ruleStringEndWith{
|
||||
&baseRuleString{},
|
||||
endWith,
|
||||
}
|
||||
}
|
||||
|
||||
// Compile-time checks to ensure type implements desired interfaces.
|
||||
var (
|
||||
_ = RuleString(new(ruleStringOneOf))
|
||||
_ = RuleString(new(ruleStringStartWith))
|
||||
_ = RuleString(new(ruleStringEndWith))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user