forked from fabric8-services/fabric8-wit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkitem_test.go
98 lines (83 loc) · 2.5 KB
/
workitem_test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// +build integration
package main
import (
"fmt"
"os"
"testing"
"github.com/almighty/almighty-core/app"
"github.com/almighty/almighty-core/app/test"
"github.com/almighty/almighty-core/migration"
"github.com/almighty/almighty-core/models"
"github.com/jinzhu/gorm"
)
var db *gorm.DB
func TestMain(m *testing.M) {
dbhost := os.Getenv("ALMIGHTY_DB_HOST")
if "" == dbhost {
panic("The environment variable ALMIGHTY_DB_HOST is not specified or empty.")
}
var err error
db, err = gorm.Open("postgres", fmt.Sprintf("host=%s user=postgres password=mysecretpassword sslmode=disable", dbhost))
if err != nil {
panic("failed to connect database: " + err.Error())
}
defer db.Close()
// Migrate the schema
migration.Perform(db)
m.Run()
}
func TestGetWorkItem(t *testing.T) {
ts := models.NewGormTransactionSupport(db)
repo := models.NewWorkItemRepository(ts)
controller := WorkitemController{ts: ts, wiRepository: repo}
payload := app.CreateWorkitemPayload{
Name: "foobar",
Type: "1",
Fields: map[string]interface{}{
"system.owner": "aslak",
"system.state": "done"},
}
_, result := test.CreateWorkitemCreated(t, nil, nil, &controller, &payload)
_, wi := test.ShowWorkitemOK(t, nil, nil, &controller, result.ID)
if wi == nil {
t.Fatalf("Work Item '%s' not present", result.ID)
}
if wi.ID != result.ID {
t.Errorf("Id should be %s, but is %s", result.ID, wi.ID)
}
wi.Fields["system.owner"] = "thomas"
payload2 := app.UpdateWorkitemPayload{
Name: wi.Name,
Type: wi.Type,
Version: wi.Version,
Fields: wi.Fields,
}
_, updated := test.UpdateWorkitemOK(t, nil, nil, &controller, wi.ID, &payload2)
if updated.Version != result.Version+1 {
t.Errorf("expected version %d, but got %d", result.Version+1, updated.Version)
}
if updated.ID != result.ID {
t.Errorf("id has changed from %s to %s", result.ID, updated.ID)
}
if updated.Fields["system.owner"] != "thomas" {
t.Errorf("expected owner %s, but got %s", "thomas", updated.Fields["system.owner"])
}
test.DeleteWorkitemOK(t, nil, nil, &controller, result.ID)
}
func TestCreateWI(t *testing.T) {
ts := models.NewGormTransactionSupport(db)
repo := models.NewWorkItemRepository(ts)
controller := WorkitemController{ts: ts, wiRepository: repo}
payload := app.CreateWorkitemPayload{
Name: "some name",
Type: "1",
Fields: map[string]interface{}{
"system.owner": "tmaeder",
"system.state": "open",
},
}
_, created := test.CreateWorkitemCreated(t, nil, nil, &controller, &payload)
if created.ID == "" {
t.Error("no id")
}
}