-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
78 lines (71 loc) · 2.37 KB
/
helpers.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package tests
import (
"database/sql"
"github.com/saichler/my.security/go/sec"
"github.com/saichler/my.simple/go/common"
"github.com/saichler/my.simple/go/defaults"
model2 "github.com/saichler/my.simple/go/introspect/model"
"github.com/saichler/my.simple/go/security"
"github.com/saichler/my.simple/go/tests/model"
"os"
"strconv"
"strings"
"time"
)
func init() {
sec.SetProvider(security.NewShallowSecurityProvider("v7mdWmN7YtkK9o9RXVlezRd7j5Qntohg", "Top Secret"))
defaults.ApplyDefaults()
decorateModel()
}
func createTestModelInstance(index int) *model.MyTestModel {
tag := strconv.Itoa(index)
sub := &model.MyTestSubModelSingle{
MyString: "string-sub-" + tag,
MyInt64: time.Now().Unix(),
}
sub1 := &model.MyTestSubModelSingle{
MyString: "string-sub-1-" + tag,
MyInt64: time.Now().Unix(),
}
sub2 := &model.MyTestSubModelSingle{
MyString: "string-sub-2-" + tag,
MyInt64: time.Now().Unix(),
}
i := &model.MyTestModel{
MyString: "string-" + tag,
MyFloat64: 123456.123456,
MyBool: true,
MyFloat32: 123.123,
MyInt32: int32(index),
MyInt64: int64(index * 10),
MyInt32Slice: []int32{1, 2, 3, int32(index)},
MyStringSlice: []string{"a", "b", "c", "d", tag},
MyInt32ToInt64Map: map[int32]int64{1: 11, 2: 22, 3: 33, 4: 44, int32(index): int64(index * 10)},
MyString2StringMap: map[string]string{"a": "aa", "b": "bb", "c": "cc", tag: tag + tag},
MySingle: sub,
MyModelSlice: []*model.MyTestSubModelSingle{sub1, sub2},
MyString2ModelMap: map[string]*model.MyTestSubModelSingle{sub1.MyString: sub1, sub2.MyString: sub2},
}
return i
}
func extractKeyValue(key string) string {
index1 := strings.LastIndex(key, "<")
index2 := strings.LastIndex(key, ">")
return key[index1+1 : index2]
}
func newPostgresConnection(decorator common.DataStoreDecorator) *sql.DB {
db := decorator.Connect("127.0.0.1", "5432", "postgres", "admin", "test", "disable")
return db.(*sql.DB)
}
func newSqliteConnection(decorator common.DataStoreDecorator) *sql.DB {
os.Remove("/tmp/sqlite.db")
file, _ := os.Create("/tmp/sqlite.db")
file.Close()
db := decorator.Connect("/tmp/sqlite.db")
return db.(*sql.DB)
}
func decorateModel() {
m := &model.MyTestModel{}
node, _ := common.Introspect.Inspect(m)
common.Introspect.AddDecorator(model2.DecoratorType_Primary, []string{"MyString"}, node)
}