Skip to content

Commit bed70ce

Browse files
authored
support autoApprovers services (#33)
1 parent 0940cdd commit bed70ce

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ func handleAutoApprovers() SectionHandler {
198198
objectFn := handleObject()
199199
objectFn("routes", parentPath, newObj, childPath, childRoutesProps)
200200

201+
childServicesProps := childSectionObj.FindKey(ast.TextEqual("services"))
202+
objectFn("services", parentPath, newObj, childPath, childServicesProps)
203+
201204
newObj.Sort()
202205
upsertMember(parent, sectionKey, newObj)
203206
}

main_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ func TestHandleAutoApprovers(t *testing.T) {
491491
"10.0.1.0/24": ["group:engineering", "[email protected]", "tag:foo"],
492492
},
493493
"exitNode": ["tag:foo"],
494+
"services": {
495+
"svc:web-server": ["tag:server"],
496+
"tag:prod-service": ["tag:prod-infra"],
497+
}
494498
},
495499
}`))
496500
if err != nil {
@@ -503,8 +507,8 @@ func TestHandleAutoApprovers(t *testing.T) {
503507
handlerFn("autoApprovers", parentDoc.Path, parentDoc.Object, "CHILD", childSection)
504508

505509
mergedValues := parentDoc.Object.Find("autoApprovers").Value
506-
if len(mergedValues.(*jwcc.Object).Members) != 2 {
507-
t.Fatalf("section [%v] should be [2], not [%v]", "autoApprovers", len(mergedValues.(*jwcc.Object).Members))
510+
if len(mergedValues.(*jwcc.Object).Members) != 3 {
511+
t.Fatalf("section [%v] should be [3], not [%v]", "autoApprovers", len(mergedValues.(*jwcc.Object).Members))
508512
}
509513

510514
routesValues := mergedValues.(*jwcc.Object).Find("routes").Value.(*jwcc.Object).Members
@@ -516,6 +520,11 @@ func TestHandleAutoApprovers(t *testing.T) {
516520
if len(exitNodeValues) != 2 {
517521
t.Fatalf("section [%v] should be [2], not [%v]", "exitNode", len(exitNodeValues))
518522
}
523+
524+
servicesValues := mergedValues.(*jwcc.Object).Find("services").Value.(*jwcc.Object).Members
525+
if len(servicesValues) != 2 {
526+
t.Fatalf("section [%v] should be [2], not [%v]", "services", len(servicesValues))
527+
}
519528
}
520529

521530
func TestEmptyParentObject(t *testing.T) {

0 commit comments

Comments
 (0)