-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.go
40 lines (33 loc) · 1.08 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package end2end
import (
"fmt"
"github.com/strongo/validation"
"strings"
)
const (
TestEntitiesNamePrefix = "DalgoE2E_"
// E2ETestKind1 defines table or collection name for an entity to be stored in
E2ETestKind1 = TestEntitiesNamePrefix + "E2ETest1"
// E2ETestKind2 defines table or collection name for an entity to be stored in
E2ETestKind2 = TestEntitiesNamePrefix + "E2ETest2"
UserKind = TestEntitiesNamePrefix + "User"
)
type User struct {
Title string `json:"title,omitempty"`
Email string `json:"email,omitempty"`
}
// TestData describes a test entity to be stored in a DALgo database
type TestData struct {
StringProp string `json:"StringProp,omitempty" db:"StringProp"`
IntegerProp int `json:"IntegerProp" db:"IntegerProp"`
}
// Validate returns error if not valid
func (v TestData) Validate() error {
if strings.TrimSpace(v.StringProp) == "" {
return validation.NewErrRecordIsMissingRequiredField("StringProp")
}
if v.IntegerProp < 0 {
return validation.NewErrBadRecordFieldValue("IntegerProp", fmt.Sprintf("should be > 0, got: %v", v.IntegerProp))
}
return nil
}