本文整理汇总了Golang中github.com/almighty/almighty-core/resource.Require函数的典型用法代码示例。如果您正苦于以下问题:Golang Require函数的具体用法?Golang Require怎么用?Golang Require使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Require函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestListIterationBySpace
func (test *TestIterationRepository) TestListIterationBySpace() {
t := test.T()
resource.Require(t, resource.Database)
repo := iteration.NewIterationRepository(test.DB)
spaceID := uuid.NewV4()
for i := 0; i < 3; i++ {
start := time.Now()
end := start.Add(time.Hour * (24 * 8 * 3))
name := "Sprint #2" + strconv.Itoa(i)
i := iteration.Iteration{
Name: name,
SpaceID: spaceID,
StartAt: &start,
EndAt: &end,
}
repo.Create(context.Background(), &i)
}
repo.Create(context.Background(), &iteration.Iteration{
Name: "Other Spring #2",
SpaceID: uuid.NewV4(),
})
its, err := repo.List(context.Background(), spaceID)
assert.Nil(t, err)
assert.Len(t, its, 3)
}
示例2: TestConvertStringToKind
func TestConvertStringToKind(t *testing.T) {
t.Parallel()
resource.Require(t, resource.UnitTest)
_, err := convertStringToKind("DefinitivelyNotAKind")
assert.NotNil(t, err)
}
示例3: TestCreateIteration
func (test *TestIterationRepository) TestCreateIteration() {
t := test.T()
resource.Require(t, resource.Database)
repo := iteration.NewIterationRepository(test.DB)
start := time.Now()
end := start.Add(time.Hour * (24 * 8 * 3))
name := "Sprint #24"
i := iteration.Iteration{
Name: name,
SpaceID: uuid.NewV4(),
StartAt: &start,
EndAt: &end,
}
repo.Create(context.Background(), &i)
if i.ID == uuid.Nil {
t.Errorf("Iteration was not created, ID nil")
}
if i.CreatedAt.After(time.Now()) {
t.Errorf("Iteration was not created, CreatedAt after Now()?")
}
assert.Equal(t, start, *i.StartAt)
assert.Equal(t, end, *i.EndAt)
assert.Equal(t, name, i.Name)
}
示例4: TestDeleteComment
func (test *TestCommentRepository) TestDeleteComment() {
t := test.T()
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(test.DB)()
repo := comment.NewCommentRepository(test.DB)
parentID := "AA"
c := &comment.Comment{
ParentID: parentID,
Body: "Test AA",
CreatedBy: uuid.NewV4(),
ID: uuid.NewV4(),
}
repo.Create(context.Background(), c)
if c.ID == uuid.Nil {
t.Errorf("Comment was not created, ID nil")
}
c.Body = "Test AB"
err := repo.Delete(context.Background(), c.ID)
if err != nil {
t.Error("Failed to Delete", err.Error())
}
}
示例5: 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])
}
示例6: 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])
}
示例7: TestSuccessCreateIterationWithOptionalValues
func (rest *TestSpaceIterationREST) TestSuccessCreateIterationWithOptionalValues() {
t := rest.T()
resource.Require(t, resource.Database)
var p *space.Space
iterationName := "Sprint #22"
iterationDesc := "testing description"
ci := createSpaceIteration(iterationName, &iterationDesc)
application.Transactional(rest.db, func(app application.Application) error {
repo := app.Spaces()
testSpace := space.Space{
Name: "Test 1",
}
p, _ = repo.Create(context.Background(), &testSpace)
return nil
})
svc, ctrl := rest.SecuredController()
_, c := test.CreateSpaceIterationsCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
assert.NotNil(t, c.Data.ID)
assert.NotNil(t, c.Data.Relationships.Space)
assert.Equal(t, p.ID.String(), *c.Data.Relationships.Space.Data.ID)
assert.Equal(t, *c.Data.Attributes.Name, iterationName)
assert.Equal(t, *c.Data.Attributes.Description, iterationDesc)
// create another Iteration with nil description
iterationName2 := "Sprint #23"
ci = createSpaceIteration(iterationName2, nil)
_, c = test.CreateSpaceIterationsCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
assert.Equal(t, *c.Data.Attributes.Name, iterationName2)
assert.Nil(t, c.Data.Attributes.Description)
}
示例8: 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)
}
}
示例9: 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)
}
}
示例10: TestListType_Equal
func TestListType_Equal(t *testing.T) {
t.Parallel()
resource.Require(t, resource.UnitTest)
a := ListType{
SimpleType: SimpleType{Kind: KindList},
ComponentType: SimpleType{Kind: KindString},
}
// Test type incompatibility
assert.False(t, a.Equal(convert.DummyEqualer{}))
// Test simple type difference
b := ListType{
SimpleType: SimpleType{Kind: KindString},
ComponentType: SimpleType{Kind: KindString},
}
assert.False(t, a.Equal(b))
// Test component type difference
c := ListType{
SimpleType: SimpleType{Kind: KindList},
ComponentType: SimpleType{Kind: KindInteger},
}
assert.False(t, a.Equal(c))
// Test equality
d := ListType{
SimpleType: SimpleType{Kind: KindList},
ComponentType: SimpleType{Kind: KindString},
}
assert.True(t, d.Equal(a))
assert.True(t, a.Equal(d)) // test the inverse
}
示例11: TestCreateChildArea
func (test *TestAreaRepository) TestCreateChildArea() {
t := test.T()
resource.Require(t, resource.Database)
repo := area.NewAreaRepository(test.DB)
name := "Area #24"
name2 := "Area #24.1"
i := area.Area{
Name: name,
SpaceID: uuid.NewV4(),
}
err := repo.Create(context.Background(), &i)
assert.Nil(t, err)
// ltree field doesnt accept "-" , so we will save them as "_"
expectedPath := strings.Replace((i.ID).String(), "-", "_", -1)
area2 := area.Area{
Name: name2,
SpaceID: uuid.NewV4(),
Path: expectedPath,
}
err = repo.Create(context.Background(), &area2)
assert.Nil(t, err)
actualArea, err := repo.Load(context.Background(), area2.ID)
actualPath := actualArea.Path
require.Nil(t, err)
require.NotNil(t, actualArea)
assert.Equal(t, expectedPath, actualPath)
}
示例12: TestCreateArea
func (test *TestAreaRepository) TestCreateArea() {
t := test.T()
resource.Require(t, resource.Database)
repo := area.NewAreaRepository(test.DB)
name := "Area 21"
i := area.Area{
Name: name,
SpaceID: uuid.NewV4(),
}
repo.Create(context.Background(), &i)
if i.ID == uuid.Nil {
t.Errorf("Area was not created, ID nil")
}
if i.CreatedAt.After(time.Now()) {
t.Errorf("Area was not created, CreatedAt after Now()?")
}
assert.Equal(t, name, i.Name)
}
示例13: TestFlattenMap
func TestFlattenMap(t *testing.T) {
resource.Require(t, resource.UnitTest)
testString := []byte(`{"admins":[{"name":"aslak"}],"name":"shoubhik", "assignee":{"fixes": 2, "complete" : true,"foo":[ 1,2,3,4],"1":"sbose","2":"pranav","participants":{"4":"sbose56","5":"sbose78"}},"name":"shoubhik"}`)
var nestedMap map[string]interface{}
err := json.Unmarshal(testString, &nestedMap)
if err != nil {
t.Error("Incorrect dataset ", testString)
}
OneLevelMap := make(map[string]interface{})
flatten(OneLevelMap, nestedMap, nil)
// Test for string
assert.Equal(t, OneLevelMap["assignee.participants.4"], "sbose56", "Incorrect mapping found for assignee.participants.4")
// test for int
assert.Equal(t, int(OneLevelMap["assignee.fixes"].(float64)), 2)
// test for array
assert.Equal(t, OneLevelMap["assignee.foo.0"], float64(1))
// test for boolean
assert.Equal(t, OneLevelMap["assignee.complete"], true)
// test for array of object(s)
assert.Equal(t, OneLevelMap["admins.0.name"], "aslak")
}
示例14: TestEnumType_Equal
func TestEnumType_Equal(t *testing.T) {
t.Parallel()
resource.Require(t, resource.UnitTest)
stEnum := workitem.SimpleType{Kind: workitem.KindEnum}
a := workitem.EnumType{
BaseType: stEnum,
Values: []interface{}{"foo", "bar"},
}
// Test type inequality
assert.False(t, a.Equal(convert.DummyEqualer{}))
// Test simple type difference
stInteger := workitem.SimpleType{Kind: workitem.KindInteger}
b := workitem.EnumType{
SimpleType: workitem.SimpleType{Kind: workitem.KindInteger},
BaseType: stInteger,
}
assert.False(t, a.Equal(b))
// Test base type difference
c := workitem.EnumType{
BaseType: stInteger,
}
assert.False(t, a.Equal(c))
// Test values difference
d := workitem.EnumType{
BaseType: stEnum,
Values: []interface{}{"foo1", "bar2"},
}
assert.False(t, a.Equal(d))
}
示例15: TestConvertAnyToKind
func TestConvertAnyToKind(t *testing.T) {
t.Parallel()
resource.Require(t, resource.UnitTest)
_, err := convertAnyToKind(1234)
assert.NotNil(t, err)
}