Skip to content

Commit

Permalink
fix shell_lib regarding grouping (#665)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <[email protected]>
  • Loading branch information
miklezzzz authored Oct 11, 2024
1 parent f0f2a37 commit 6bb8aec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion frameworks/shell/hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function hook::_get_possible_handler_names() {
esac
;;
"Group")
echo __on_group::${BINDING_CONTEXT_CURRENT_BINDING}
BINDING_CONTEXT_GROUP_NAME=$(context::jq -er '.groupName')
echo __on_group::${BINDING_CONTEXT_GROUP_NAME}
;;
"Schedule")
echo __on_schedule::${BINDING_CONTEXT_CURRENT_BINDING}
Expand Down
1 change: 1 addition & 0 deletions pkg/hook/binding_context/binding_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (bc BindingContext) MapV1() map[string]interface{} {
// Group is always has "type: Group", even for Synchronization.
if bc.Metadata.Group != "" {
res["type"] = "Group"
res["groupName"] = bc.Metadata.Group
return res
}

Expand Down
13 changes: 8 additions & 5 deletions pkg/hook/binding_context/binding_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,19 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {
g.Expect(bcList[0]).Should(HaveKey("binding"))
g.Expect(bcList[0]).Should(HaveKey("snapshots"))
g.Expect(bcList[0]).Should(HaveKey("type"))
g.Expect(bcList[0]).Should(HaveKey("groupName"))
g.Expect(bcList[0]).ShouldNot(HaveKey("objects"))
},
[][]string{
{`. | length`, `2`},

// grouped binding context contains binding, type and snapshots
{`.[0] | length`, `3`}, // Only 3 fields
// grouped binding context contains binding, type, snapshots and groupName
{`.[0] | length`, `4`}, // Only 4 fields
{`.[0].snapshots | has("monitor_pods")`, `true`},
{`.[0].snapshots."monitor_pods" | length`, `1`},
{`.[0].binding`, `"monitor_pods"`},
{`.[0].type`, `"Group"`},
{`.[0].groupName`, `"pods"`},

// JSON dump should has only 4 fields: binding, type, watchEvent and object.
{`.[1] | length`, `4`},
Expand Down Expand Up @@ -309,11 +311,12 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {
func() {
g.Expect(bcList).Should(HaveLen(2))

g.Expect(bcList[0]).Should(HaveLen(3))
g.Expect(bcList[0]).Should(HaveLen(4))
g.Expect(bcList[0]).Should(HaveKey("binding"))
g.Expect(bcList[0]["binding"]).Should(Equal("monitor_config_maps"))
g.Expect(bcList[0]).Should(HaveKey("type"))
g.Expect(bcList[0]["type"]).Should(Equal("Group"))
g.Expect(bcList[0]["groupName"]).Should(Equal("pods"))
g.Expect(bcList[0]).Should(HaveKey("snapshots"))
g.Expect(bcList[0]["snapshots"]).Should(HaveLen(1))

Expand All @@ -327,8 +330,8 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {
[][]string{
{`. | length`, `2`},

// grouped binding context contains binding==group, type and snapshots
{`.[0] | length`, `3`}, // Only 3 fields
// grouped binding context contains binging, type, snapshots and groupName
{`.[0] | length`, `4`}, // Only 4 fields
{`.[0].binding`, `"monitor_config_maps"`},
{`.[0].type`, `"Group"`},
{`.[0].snapshots | has("monitor_config_maps")`, `true`},
Expand Down

0 comments on commit 6bb8aec

Please sign in to comment.