Skip to content

Commit 7f008c2

Browse files
committed
add dummy team and team component relationship and fixed test
1 parent 918bac4 commit 7f008c2

14 files changed

+167
-14
lines changed

fixtures/dummy/all.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ func PopulateDBWithDummyModels(gormDB *gorm.DB) error {
2828
return err
2929
}
3030
}
31+
for _, c := range AllDummyTeams {
32+
if err := gormDB.Create(&c).Error; err != nil {
33+
return err
34+
}
35+
}
36+
for _, c := range AllTeamComponents {
37+
if err := gormDB.Create(&c).Error; err != nil {
38+
return err
39+
}
40+
}
3141
for _, c := range AllDummyComponentRelationships {
3242
c.UpdatedAt = createTime
3343
err = gormDB.Create(&c).Error
@@ -155,6 +165,18 @@ func DeleteDummyModelsFromDB(gormDB *gorm.DB) error {
155165
return err
156166
}
157167
}
168+
for _, c := range AllTeamComponents {
169+
err = gormDB.Delete(&c).Error
170+
if err != nil {
171+
return err
172+
}
173+
}
174+
for _, c := range AllDummyTeams {
175+
err = gormDB.Delete(&c).Error
176+
if err != nil {
177+
return err
178+
}
179+
}
158180
for _, c := range AllDummyCheckComponentRelationships {
159181
err = gormDB.Where("component_id = ?", c.ComponentID).Delete(&c).Error
160182
if err != nil {

fixtures/dummy/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ var (
77

88
DummyYearOldDate = time.Now().AddDate(-1, 0, 0)
99
)
10+
11+
func ptr[T any](t T) *T {
12+
return &t
13+
}

fixtures/dummy/team_components.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dummy
2+
3+
import "github.com/flanksource/duty/models"
4+
5+
var LogisticBackendTeamComponent = models.TeamComponent{
6+
TeamID: Backend.ID,
7+
ComponentID: Logistics.ID,
8+
SelectorID: ptr("366d4ecb71d8ce12cf253e55d541f987"),
9+
}
10+
11+
var LogisticUIFrontendTeamComponent = models.TeamComponent{
12+
TeamID: Frontend.ID,
13+
ComponentID: LogisticsUI.ID,
14+
SelectorID: ptr("7fbaeebb537818e8b334fd336613f8d4 "),
15+
}
16+
17+
var AllTeamComponents = []models.TeamComponent{LogisticBackendTeamComponent, LogisticUIFrontendTeamComponent}

fixtures/dummy/teams.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dummy
2+
3+
import (
4+
"github.com/flanksource/duty/models"
5+
"github.com/google/uuid"
6+
)
7+
8+
var Backend = models.Team{
9+
ID: uuid.MustParse("3d3f49ba-93d6-4058-8acc-96233f7c5c80"),
10+
Name: "Backend",
11+
Spec: []byte(`{"components": [{ "name": "logistics" }]}`),
12+
CreatedBy: JohnDoe.ID,
13+
}
14+
15+
var Frontend = models.Team{
16+
ID: uuid.MustParse("72d965e2-b58b-4a23-ba73-2cae0daf5981"),
17+
Name: "Frontend",
18+
Spec: []byte(`{"components": [{ "name": "logistics-ui" }]}`),
19+
CreatedBy: JohnDoe.ID,
20+
}
21+
22+
var AllDummyTeams = []models.Team{Backend, Frontend}

fixtures/expectations/topology_depth_1_root_tree.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"healthy",
6868
"unhealthy"
6969
],
70-
"teams": [],
70+
"teams": ["Backend", "Frontend"],
7171
"tags": {
7272
"telemetry": [
7373
"enabled"

fixtures/expectations/topology_depth_2_root_tree.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,10 @@
153153
"updated_at": "2023-01-01T05:29:00+05:30"
154154
}
155155
],
156-
"healthStatuses": [
157-
"healthy",
158-
"unhealthy"
159-
],
160-
"teams": [],
156+
"healthStatuses": ["healthy", "unhealthy"],
157+
"teams": ["Backend", "Frontend"],
161158
"tags": {
162-
"telemetry": [
163-
"enabled"
164-
]
159+
"telemetry": ["enabled"]
165160
},
166161
"types": [
167162
"Application",

fixtures/expectations/topology_root_tree.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
"healthy",
363363
"unhealthy"
364364
],
365-
"teams": [],
365+
"teams": ["Backend", "Frontend"],
366366
"tags": {
367367
"telemetry": [
368368
"enabled"

fixtures/expectations/topology_tree_with_label_filter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"healthStatuses": [
4848
"healthy"
4949
],
50-
"teams": [],
50+
"teams": ["Backend"],
5151
"tags": {
5252
"telemetry": [
5353
"enabled"

fixtures/expectations/topology_tree_with_owner_filter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"healthStatuses": [
6565
"healthy"
6666
],
67-
"teams": [],
67+
"teams": ["Backend", "Frontend"],
6868
"tags": {
6969
"telemetry": [
7070
"enabled"

fixtures/expectations/topology_tree_with_status_filter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"healthy",
118118
"unhealthy"
119119
],
120-
"teams": [],
120+
"teams": ["Backend", "Frontend"],
121121
"tags": {
122122
"telemetry": [
123123
"enabled"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"components": [
3+
{
4+
"id": "018681fc-e54f-bd4f-42be-068a9a69eeb5",
5+
"agent_id": "00000000-0000-0000-0000-000000000000",
6+
"external_id": "dummy/logistics",
7+
"name": "logistics",
8+
"labels": {
9+
"telemetry": "enabled"
10+
},
11+
"status": "healthy",
12+
"type": "Entity",
13+
"owner": "logistics-team",
14+
"summary": {
15+
"healthy": 1
16+
},
17+
"is_leaf": false,
18+
"created_at": "2023-01-01T05:29:00+05:30",
19+
"updated_at": "2023-01-01T05:29:00+05:30",
20+
"components": [
21+
{
22+
"id": "018681fd-5770-336f-227c-259435d7fc6b",
23+
"agent_id": "00000000-0000-0000-0000-000000000000",
24+
"external_id": "dummy/logistics-api",
25+
"parent_id": "018681fc-e54f-bd4f-42be-068a9a69eeb5",
26+
"name": "logistics-api",
27+
"labels": {
28+
"telemetry": "enabled"
29+
},
30+
"status": "healthy",
31+
"type": "Application",
32+
"owner": "logistics-team",
33+
"path": "018681fc-e54f-bd4f-42be-068a9a69eeb5",
34+
"summary": {
35+
"healthy": 1
36+
},
37+
"is_leaf": false,
38+
"created_at": "2023-01-01T05:29:00+05:30",
39+
"updated_at": "2023-01-01T05:29:00+05:30",
40+
"checks": {
41+
"healthy": 2
42+
}
43+
}
44+
]
45+
}
46+
],
47+
"healthStatuses": [
48+
"healthy"
49+
],
50+
"teams": ["Backend"],
51+
"tags": {
52+
"telemetry": [
53+
"enabled"
54+
]
55+
},
56+
"types": [
57+
"Application",
58+
"Entity"
59+
]
60+
}

fixtures/expectations/topology_tree_with_type_filter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"healthy",
2424
"unhealthy"
2525
],
26-
"teams": [],
26+
"teams": ["Backend", "Frontend"],
2727
"tags": {
2828
"telemetry": [
2929
"enabled"

models/teams.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package models
2+
3+
import (
4+
"encoding/json"
5+
"time"
6+
7+
"github.com/google/uuid"
8+
)
9+
10+
type Team struct {
11+
ID uuid.UUID `json:"id" gorm:"primaryKey"`
12+
Name string `json:"name"`
13+
Icon string `json:"icon,omitempty"`
14+
Spec json.RawMessage `json:"spec,omitempty"`
15+
Source string `json:"source,omitempty"`
16+
CreatedBy uuid.UUID `json:"created_by"`
17+
CreatedAt time.Time `json:"created_at"`
18+
UpdatedAt time.Time `json:"updated_at"`
19+
DeletedAt *time.Time `json:"deleted_at,omitempty"`
20+
}
21+
22+
type TeamComponent struct {
23+
TeamID uuid.UUID `json:"team_id" gorm:"primaryKey"`
24+
ComponentID uuid.UUID `json:"component_id" gorm:"primaryKey"`
25+
Role *string `json:"role,omitempty"`
26+
SelectorID *string `json:"selector_id,omitempty"`
27+
}

topology_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/flanksource/duty/types"
1212
ginkgo "github.com/onsi/ginkgo/v2"
1313
. "github.com/onsi/gomega"
14+
"github.com/onsi/gomega/format"
1415
)
1516

1617
// For debugging
@@ -44,6 +45,7 @@ func testTopologyJSON(opts TopologyOptions, path string) {
4445
}
4546

4647
var _ = ginkgo.Describe("Topology behavior", func() {
48+
format.MaxLength = 0 // So the diff is not truncated.
4749

4850
ginkgo.It("Should create root tree", func() {
4951
testTopologyJSON(TopologyOptions{}, "fixtures/expectations/topology_root_tree.json")
@@ -103,4 +105,8 @@ var _ = ginkgo.Describe("Topology behavior", func() {
103105
ginkgo.It("Should test tree with agent ID filter", func() {
104106
testTopologyJSON(TopologyOptions{AgentID: dummy.GCPAgent.ID.String()}, "fixtures/expectations/topology_tree_with_agent_id.json")
105107
})
108+
109+
// ginkgo.It("Should test tree with team filter", func() {
110+
// testTopologyJSON(TopologyOptions{Team: dummy.Backend.Name}, "fixtures/expectations/topology_tree_with_team_filter.json")
111+
// })
106112
})

0 commit comments

Comments
 (0)