Skip to content

Commit

Permalink
Update tests to reflect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed May 23, 2024
1 parent 1012fb9 commit 85bcff7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 7 deletions.
71 changes: 65 additions & 6 deletions act/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,17 @@ func Test_Apply(t *testing.T) {
})
assert.NotNil(t, actRegistry)

outputs := actRegistry.Apply([]sdkAct.Signal{
*sdkAct.Passthrough(),
})
outputs := actRegistry.Apply(
[]sdkAct.Signal{
*sdkAct.Passthrough(),
},
sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
},
)
assert.NotNil(t, outputs)
assert.Len(t, outputs, 1)
assert.Equal(t, "passthrough", outputs[0].MatchedPolicy)
Expand All @@ -225,7 +233,15 @@ func Test_Apply_NoSignals(t *testing.T) {
})
assert.NotNil(t, actRegistry)

outputs := actRegistry.Apply([]sdkAct.Signal{})
outputs := actRegistry.Apply(
[]sdkAct.Signal{},
sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
},
)
assert.NotNil(t, outputs)
assert.Len(t, outputs, 1)
assert.Equal(t, "passthrough", outputs[0].MatchedPolicy)
Expand Down Expand Up @@ -272,7 +288,12 @@ func Test_Apply_ContradictorySignals(t *testing.T) {
assert.NotNil(t, actRegistry)

for _, s := range signals {
outputs := actRegistry.Apply(s)
outputs := actRegistry.Apply(s, sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
})
assert.NotNil(t, outputs)
assert.Len(t, outputs, 2)
assert.Equal(t, "terminate", outputs[0].MatchedPolicy)
Expand Down Expand Up @@ -318,6 +339,11 @@ func Test_Apply_ActionNotMatched(t *testing.T) {

outputs := actRegistry.Apply([]sdkAct.Signal{
{Name: "non-existent"},
}, sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
})
assert.NotNil(t, outputs)
assert.Len(t, outputs, 1)
Expand Down Expand Up @@ -351,6 +377,11 @@ func Test_Apply_PolicyNotMatched(t *testing.T) {

outputs := actRegistry.Apply([]sdkAct.Signal{
*sdkAct.Terminate(),
}, sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
})
assert.NotNil(t, outputs)
assert.Len(t, outputs, 1)
Expand Down Expand Up @@ -399,6 +430,11 @@ func Test_Apply_NonBoolPolicy(t *testing.T) {

outputs := actRegistry.Apply([]sdkAct.Signal{
*sdkAct.Passthrough(),
}, sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
})
assert.NotNil(t, outputs)
assert.Len(t, outputs, 1)
Expand Down Expand Up @@ -464,6 +500,11 @@ func Test_Run(t *testing.T) {

outputs := actRegistry.Apply([]sdkAct.Signal{
*sdkAct.Passthrough(),
}, sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
})
assert.NotNil(t, outputs)

Expand All @@ -489,6 +530,11 @@ func Test_Run_Terminate(t *testing.T) {

outputs := actRegistry.Apply([]sdkAct.Signal{
*sdkAct.Terminate(),
}, sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
})
assert.NotNil(t, outputs)
assert.Equal(t, "terminate", outputs[0].MatchedPolicy)
Expand Down Expand Up @@ -522,6 +568,11 @@ func Test_Run_Async(t *testing.T) {

outputs := actRegistry.Apply([]sdkAct.Signal{
*sdkAct.Log("info", "test", map[string]any{"async": true}),
}, sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
})
assert.NotNil(t, outputs)
assert.Equal(t, "log", outputs[0].MatchedPolicy)
Expand Down Expand Up @@ -647,7 +698,15 @@ func Test_Run_Timeout(t *testing.T) {
})
assert.NotNil(t, actRegistry)

outputs := actRegistry.Apply([]sdkAct.Signal{*signals[name]})
outputs := actRegistry.Apply(
[]sdkAct.Signal{*signals[name]},
sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
},
)
assert.NotNil(t, outputs)
assert.Equal(t, name, outputs[0].MatchedPolicy)
assert.Equal(t,
Expand Down
11 changes: 10 additions & 1 deletion plugin/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ func Test_applyPolicies(t *testing.T) {
})

output := applyPolicies(
"onTrafficFromClient", []sdkAct.Signal{*sdkAct.Passthrough()}, logger, actRegistry)
sdkAct.Hook{
Name: "HOOK_NAME_ON_TRAFFIC_FROM_CLIENT",
Priority: 1000,
Params: map[string]any{},
Result: map[string]any{},
},
[]sdkAct.Signal{*sdkAct.Passthrough()},
logger,
actRegistry,
)
assert.Len(t, output, 1)
assert.Equal(t, "passthrough", output[0].MatchedPolicy)
assert.Nil(t, output[0].Metadata)
Expand Down

0 comments on commit 85bcff7

Please sign in to comment.