本文整理汇总了Golang中github.com/almighty/almighty-core/gormapplication.NewGormDB函数的典型用法代码示例。如果您正苦于以下问题:Golang NewGormDB函数的具体用法?Golang NewGormDB怎么用?Golang NewGormDB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewGormDB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetupSuite
// The SetupSuite method will run before the tests in the suite are run.
// It sets up a database connection for all the tests in this suite without polluting global space.
func (s *workItemLinkTypeSuite) SetupSuite() {
var err error
if err = configuration.Setup(""); err != nil {
panic(fmt.Errorf("Failed to setup the configuration: %s", err.Error()))
}
s.db, err = gorm.Open("postgres", configuration.GetPostgresConfigString())
if err != nil {
panic("Failed to connect database: " + err.Error())
}
// Make sure the database is populated with the correct types (e.g. bug etc.)
if err := models.Transactional(DB, func(tx *gorm.DB) error {
return migration.PopulateCommonTypes(context.Background(), tx, workitem.NewWorkItemTypeRepository(tx))
}); err != nil {
panic(err.Error())
}
svc := goa.New("workItemLinkTypeSuite-Service")
require.NotNil(s.T(), svc)
s.linkTypeCtrl = NewWorkItemLinkTypeController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.linkTypeCtrl)
s.linkCatCtrl = NewWorkItemLinkCategoryController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.linkCatCtrl)
// s.typeCtrl = NewWorkitemtypeController(svc, gormapplication.NewGormDB(DB))
// require.NotNil(s.T(), s.typeCtrl)
}
示例2: TestTrackerQueryListItemsNotNil
// This test ensures that List does not return NIL items.
func TestTrackerQueryListItemsNotNil(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
controller := TrackerController{Controller: nil, db: gormapplication.NewGormDB(DB), scheduler: RwiScheduler}
payload := app.CreateTrackerAlternatePayload{
URL: "http://api.github.com",
Type: "github",
}
_, result := test.CreateTrackerCreated(t, nil, nil, &controller, &payload)
t.Log(result.ID)
tqController := TrackerqueryController{Controller: nil, db: gormapplication.NewGormDB(DB), scheduler: RwiScheduler}
tqpayload := app.CreateTrackerQueryAlternatePayload{
Query: "is:open is:issue user:arquillian author:aslakknutsen",
Schedule: "15 * * * * *",
TrackerID: result.ID,
}
test.CreateTrackerqueryCreated(t, nil, nil, &tqController, &tqpayload)
test.CreateTrackerqueryCreated(t, nil, nil, &tqController, &tqpayload)
_, list := test.ListTrackerqueryOK(t, nil, nil, &tqController)
for _, tq := range list {
if tq == nil {
t.Error("Returned Tracker Query found nil")
}
}
}
示例3: TestGetTrackerQuery
func TestGetTrackerQuery(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
controller := TrackerController{Controller: nil, db: gormapplication.NewGormDB(DB), scheduler: RwiScheduler}
payload := app.CreateTrackerAlternatePayload{
URL: "http://api.github.com",
Type: "github",
}
_, result := test.CreateTrackerCreated(t, nil, nil, &controller, &payload)
tqController := TrackerqueryController{Controller: nil, db: gormapplication.NewGormDB(DB), scheduler: RwiScheduler}
tqpayload := app.CreateTrackerQueryAlternatePayload{
Query: "is:open is:issue user:arquillian author:aslakknutsen",
Schedule: "15 * * * * *",
TrackerID: result.ID,
}
fmt.Printf("tq payload %#v", tqpayload)
_, tqresult := test.CreateTrackerqueryCreated(t, nil, nil, &tqController, &tqpayload)
test.ShowTrackerqueryOK(t, nil, nil, &tqController, tqresult.ID)
_, tqr := test.ShowTrackerqueryOK(t, nil, nil, &tqController, tqresult.ID)
if tqr == nil {
t.Fatalf("Tracker Query '%s' not present", tqresult.ID)
}
if tqr.ID != tqresult.ID {
t.Errorf("Id should be %s, but is %s", tqresult.ID, tqr.ID)
}
}
示例4: SetupTest
// The SetupTest method will be run before every test in the suite.
func (s *workItemTypeSuite) SetupTest() {
svc := goa.New("workItemTypeSuite-Service")
assert.NotNil(s.T(), svc)
s.typeCtrl = NewWorkitemtypeController(svc, gormapplication.NewGormDB(s.DB))
assert.NotNil(s.T(), s.typeCtrl)
s.linkTypeCtrl = NewWorkItemLinkTypeController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.linkTypeCtrl)
s.linkCatCtrl = NewWorkItemLinkCategoryController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.linkCatCtrl)
}
示例5: SetupSuite
// The SetupSuite method will run before the tests in the suite are run.
// It sets up a database connection for all the tests in this suite without polluting global space.
func (s *workItemLinkSuite) SetupSuite() {
var err error
if err = configuration.Setup(""); err != nil {
panic(fmt.Errorf("Failed to setup the configuration: %s", err.Error()))
}
s.db, err = gorm.Open("postgres", configuration.GetPostgresConfigString())
if err != nil {
panic("Failed to connect database: " + err.Error())
}
// Make sure the database is populated with the correct types (e.g. bug etc.)
if err := models.Transactional(DB, func(tx *gorm.DB) error {
return migration.PopulateCommonTypes(context.Background(), tx, workitem.NewWorkItemTypeRepository(tx))
}); err != nil {
panic(err.Error())
}
require.Nil(s.T(), err)
priv, err := almtoken.ParsePrivateKey([]byte(almtoken.RSAPrivateKey))
require.Nil(s.T(), err)
svc := goa.New("TestWorkItemLinkType-Service")
require.NotNil(s.T(), svc)
s.workItemLinkTypeCtrl = NewWorkItemLinkTypeController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.workItemLinkTypeCtrl)
svc = goa.New("TestWorkItemLinkCategory-Service")
require.NotNil(s.T(), svc)
s.workItemLinkCategoryCtrl = NewWorkItemLinkCategoryController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.workItemLinkCategoryCtrl)
svc = goa.New("TestWorkItemLink-Service")
require.NotNil(s.T(), svc)
s.workItemLinkCtrl = NewWorkItemLinkController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.workItemLinkCtrl)
svc = goa.New("TestWorkItemRelationshipsLinks-Service")
require.NotNil(s.T(), svc)
s.workItemRelsLinksCtrl = NewWorkItemRelationshipsLinksController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.workItemRelsLinksCtrl)
s.workItemSvc = testsupport.ServiceAsUser("TestWorkItem-Service", almtoken.NewManagerWithPrivateKey(priv), testsupport.TestIdentity)
require.NotNil(s.T(), s.workItemSvc)
s.workItemCtrl = NewWorkitemController(svc, gormapplication.NewGormDB(DB))
require.NotNil(s.T(), s.workItemCtrl)
}
示例6: TestSpacesSearchOK
func TestSpacesSearchOK(t *testing.T) {
resource.Require(t, resource.Database)
tester := TestSearchSpaces{}
tester.db = gormapplication.NewGormDB(DB)
tester.clean = cleaner.DeleteCreatedEntities(DB)
idents, err := tester.createTestData()
if err != nil {
t.Fatal(err)
}
defer tester.cleanTestData()
tests := []okScenario{
{"With uppercase fullname query", args{offset("0"), limit(10), "TEST_AB"}, expects{totalCount(1)}},
{"With lowercase fullname query", args{offset("0"), limit(10), "TEST_AB"}, expects{totalCount(1)}},
{"With uppercase description query", args{offset("0"), limit(10), "DESCRIPTION FOR TEST_AB"}, expects{totalCount(1)}},
{"With lowercase description query", args{offset("0"), limit(10), "description for test_ab"}, expects{totalCount(1)}},
{"with special chars", args{offset("0"), limit(10), "&:\n!#%?*"}, expects{totalCount(0)}},
{"with * to list all", args{offset("0"), limit(10), "*"}, expects{totalCountAtLeast(len(idents))}},
{"with multi page", args{offset("0"), limit(10), "TEST"}, expects{hasLinks("Next")}},
{"with last page", args{offset(strconv.Itoa(len(idents) - 1)), limit(10), "TEST"}, expects{hasNoLinks("Next"), hasLinks("Prev")}},
{"with different values", args{offset("0"), limit(10), "TEST"}, expects{differentValues()}},
}
service := goa.New("TestSpacesSearch-Service")
controller := NewSearchController(service, tester.db)
for _, tt := range tests {
_, result := test.SpacesSearchOK(t, context.Background(), service, controller, tt.args.pageLimit, tt.args.pageOffset, tt.args.q)
for _, expect := range tt.expects {
expect(t, tt, result)
}
}
}
示例7: TestSearchPagination
func TestSearchPagination(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
service := getServiceAsUser()
wiRepo := workitem.NewWorkItemRepository(DB)
_, err := wiRepo.Create(
context.Background(),
workitem.SystemBug,
map[string]interface{}{
workitem.SystemTitle: "specialwordforsearch2",
workitem.SystemDescription: nil,
workitem.SystemCreator: "baijum",
workitem.SystemState: workitem.SystemStateClosed,
},
"")
require.Nil(t, err)
controller := NewSearchController(service, gormapplication.NewGormDB(DB))
q := "specialwordforsearch2"
_, sr := test.ShowSearchOK(t, nil, nil, controller, nil, nil, q)
// defaults in paging.go is 'pageSizeDefault = 20'
assert.Equal(t, "http:///api/search?page[offset]=0&page[limit]=20&q=specialwordforsearch2", *sr.Links.First)
assert.Equal(t, "http:///api/search?page[offset]=0&page[limit]=20&q=specialwordforsearch2", *sr.Links.Last)
require.NotEmpty(t, sr.Data)
r := sr.Data[0]
assert.Equal(t, "specialwordforsearch2", r.Attributes[workitem.SystemTitle])
}
示例8: TestUnregisteredURLWithPort
func TestUnregisteredURLWithPort(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
service := getServiceAsUser()
wiRepo := workitem.NewWorkItemRepository(DB)
description := "Related to http://some-other-domain:8080/different-path/154687364529310/ok issue"
expectedDescription := rendering.NewMarkupContentFromLegacy(description)
_, err := wiRepo.Create(
context.Background(),
workitem.SystemBug,
map[string]interface{}{
workitem.SystemTitle: "specialwordforsearch_new",
workitem.SystemDescription: expectedDescription,
workitem.SystemCreator: "baijum",
workitem.SystemState: workitem.SystemStateClosed,
},
"")
require.Nil(t, err)
controller := NewSearchController(service, gormapplication.NewGormDB(DB))
q := `http://some-other-domain:8080/different-path/`
_, sr := test.ShowSearchOK(t, nil, nil, controller, nil, nil, q)
require.NotEmpty(t, sr.Data)
r := sr.Data[0]
assert.Equal(t, description, r.Attributes[workitem.SystemDescription])
}
示例9: createControler
func createControler(t *testing.T) (*UsersController, application.DB) {
svc := goa.New("test")
app := gormapplication.NewGormDB(DB)
controller := NewUsersController(svc, app)
assert.NotNil(t, controller)
return controller, app
}
示例10: TestSearchURLWithoutPort
func TestSearchURLWithoutPort(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
service := getServiceAsUser()
wiRepo := workitem.NewWorkItemRepository(DB)
description := "This issue is related to http://localhost/detail/876394"
expectedDescription := rendering.NewMarkupContentFromLegacy(description)
_, err := wiRepo.Create(
context.Background(),
workitem.SystemBug,
map[string]interface{}{
workitem.SystemTitle: "specialwordforsearch_without_port",
workitem.SystemDescription: expectedDescription,
workitem.SystemCreator: "baijum",
workitem.SystemState: workitem.SystemStateClosed,
},
"")
require.Nil(t, err)
controller := NewSearchController(service, gormapplication.NewGormDB(DB))
q := `"http://localhost/detail/876394"`
_, sr := test.ShowSearchOK(t, nil, nil, controller, nil, nil, q)
require.NotEmpty(t, sr.Data)
r := sr.Data[0]
assert.Equal(t, description, r.Attributes[workitem.SystemDescription])
}
示例11: TestUnwantedCharactersRelatedToSearchLogic
func TestUnwantedCharactersRelatedToSearchLogic(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
service := getServiceAsUser()
wiRepo := workitem.NewWorkItemRepository(DB)
expectedDescription := rendering.NewMarkupContentFromLegacy("Related to http://example-domain:8080/different-path/ok issue")
_, err := wiRepo.Create(
context.Background(),
workitem.SystemBug,
map[string]interface{}{
workitem.SystemTitle: "specialwordforsearch_new",
workitem.SystemDescription: expectedDescription,
workitem.SystemCreator: "baijum",
workitem.SystemState: workitem.SystemStateClosed,
},
"")
require.Nil(t, err)
controller := NewSearchController(service, gormapplication.NewGormDB(DB))
// add url: in the query, that is not expected by the code hence need to make sure it gives expected result.
q := `http://url:some-random-other-domain:8080/different-path/`
_, sr := test.ShowSearchOK(t, nil, nil, controller, nil, nil, q)
require.NotNil(t, sr.Data)
assert.Empty(t, sr.Data)
}
示例12: TestGetTracker
func TestGetTracker(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
controller := TrackerController{Controller: nil, db: gormapplication.NewGormDB(DB), scheduler: RwiScheduler}
payload := app.CreateTrackerAlternatePayload{
URL: "http://issues.jboss.com",
Type: "jira",
}
_, result := test.CreateTrackerCreated(t, nil, nil, &controller, &payload)
test.ShowTrackerOK(t, nil, nil, &controller, result.ID)
_, tr := test.ShowTrackerOK(t, nil, nil, &controller, result.ID)
if tr == nil {
t.Fatalf("Tracker '%s' not present", result.ID)
}
if tr.ID != result.ID {
t.Errorf("Id should be %s, but is %s", result.ID, tr.ID)
}
payload2 := app.UpdateTrackerAlternatePayload{
URL: tr.URL,
Type: tr.Type,
}
_, updated := test.UpdateTrackerOK(t, nil, nil, &controller, tr.ID, &payload2)
if updated.ID != result.ID {
t.Errorf("Id has changed from %s to %s", result.ID, updated.ID)
}
if updated.URL != result.URL {
t.Errorf("URL has changed from %s to %s", result.URL, updated.URL)
}
if updated.Type != result.Type {
t.Errorf("Type has changed has from %s to %s", result.Type, updated.Type)
}
}
示例13: TestSearch
func TestSearch(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
service := getServiceAsUser()
wiRepo := workitem.NewWorkItemRepository(DB)
_, err := wiRepo.Create(
context.Background(),
workitem.SystemBug,
map[string]interface{}{
workitem.SystemTitle: "specialwordforsearch",
workitem.SystemDescription: nil,
workitem.SystemCreator: "baijum",
workitem.SystemState: workitem.SystemStateClosed,
},
"")
require.Nil(t, err)
controller := NewSearchController(service, gormapplication.NewGormDB(DB))
q := "specialwordforsearch"
_, sr := test.ShowSearchOK(t, nil, nil, controller, nil, nil, q)
require.NotEmpty(t, sr.Data)
r := sr.Data[0]
assert.Equal(t, "specialwordforsearch", r.Attributes[workitem.SystemTitle])
}
示例14: TestUnauthorizeWorkItemLinkCUD
// This test case will check authorized access to Create/Update/Delete APIs
func (s *workItemLinkSuite) TestUnauthorizeWorkItemLinkCUD() {
UnauthorizeCreateUpdateDeleteTest(s.T(), getWorkItemLinkTestData, func() *goa.Service {
return goa.New("TestUnauthorizedCreateWorkItemLink-Service")
}, func(service *goa.Service) error {
controller := NewWorkItemLinkController(service, gormapplication.NewGormDB(DB))
app.MountWorkItemLinkController(service, controller)
return nil
})
}
示例15: TestUnauthorizeWorkItemTypeCreate
// This test case will check authorized access to Create/Update/Delete APIs
func TestUnauthorizeWorkItemTypeCreate(t *testing.T) {
UnauthorizeCreateUpdateDeleteTest(t, getWorkItemTypeTestData, func() *goa.Service {
return goa.New("TestUnauthorizedCreateWIT-Service")
}, func(service *goa.Service) error {
controller := NewWorkitemtypeController(service, gormapplication.NewGormDB(DB))
app.MountWorkitemtypeController(service, controller)
return nil
})
}