MCPcopy
hub / github.com/daptin/daptin / GetResource

Function GetResource

server/resource_methods_test.go:36–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36func GetResource() (*InMemoryTestDatabase, *resource.DbResource) {
37 wrapper := GetInMemoryDbForTest()
38
39 configStore, _ := resource.NewConfigStore(wrapper)
40
41 initConfig, _ := LoadConfigFiles()
42
43 existingTables, _ := GetTablesFromWorld(wrapper)
44
45 allTables := MergeTables(existingTables, initConfig.Tables)
46
47 initConfig.Tables = allTables
48
49 cruds := make(map[string]*resource.DbResource)
50
51 olricDb1, _ := olric.New(olricConfig.New("local"))
52 olricDb := olricDb1.NewEmbeddedClient()
53
54 dtopicMap := make(map[string]*olric.PubSub)
55
56 store := ydb.NewDiskStore("/tmp")
57 ms := BuildMiddlewareSet(&initConfig, &cruds, store, &dtopicMap)
58 for _, table := range initConfig.Tables {
59 model := api2go.NewApi2GoModel(table.TableName, table.Columns, int64(table.DefaultPermission), table.Relations)
60 res, _ := resource.NewDbResource(model, wrapper, &ms, cruds, configStore, olricDb, table)
61 cruds[table.TableName] = res
62 }
63
64 for key := range cruds {
65 pubSub, err := olricDb.NewPubSub()
66 if err != nil {
67 resource.CheckErr(err, "Failed to create pubsub for table: %v", key)
68 continue
69 }
70 dtopicMap[key] = pubSub
71 }
72
73 resource.CheckRelations(&initConfig)
74 resource.CheckAuditTables(&initConfig)
75
76 tx, errb := wrapper.Beginx()
77 resource.CheckErr(errb, "Failed to begin transaction [76]")
78 resource.CheckAllTableStatus(&initConfig, wrapper)
79 errc := tx.Commit()
80 resource.CheckErr(errc, "Failed to commit transaction after creating tables")
81
82 tx, errb = wrapper.Beginx()
83 resource.CheckErr(errb, "Failed to begin transaction [82]")
84 resource.CreateRelations(&initConfig, wrapper)
85 errc = tx.Commit()
86 resource.CheckErr(errc, "Failed to commit transaction after creating relations")
87
88 tx, errb = wrapper.Beginx()
89 resource.CheckErr(errb, "Failed to begin transaction [88]")
90 resource.CreateUniqueConstraints(&initConfig, tx)
91 errc = tx.Commit()
92 resource.CheckErr(errc, "Failed to commit transaction after creating unique constrains")
93

Callers 4

TestUserGroupNameToIdFunction · 0.85
TestStoreTokenFunction · 0.85
TestGetActionsByTypeFunction · 0.85

Calls 15

NewConfigStoreFunction · 0.92
NewDbResourceFunction · 0.92
CheckErrFunction · 0.92
CheckRelationsFunction · 0.92
CheckAuditTablesFunction · 0.92
CheckAllTableStatusFunction · 0.92
CreateRelationsFunction · 0.92
CreateUniqueConstraintsFunction · 0.92
CreateIndexesFunction · 0.92
UpdateWorldTableFunction · 0.92
UpdateExchangesFunction · 0.92

Tested by

no test coverage detected