云端事件:修复实例通知并移出 LaunchInstance 回传
This commit is contained in:
@@ -3,6 +3,8 @@ package oci
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/oracle/oci-go-sdk/v65/sch"
|
||||
)
|
||||
|
||||
func TestRelayEventCondition(t *testing.T) {
|
||||
@@ -35,3 +37,31 @@ func TestRelayEventConditionQuoting(t *testing.T) {
|
||||
t.Errorf("单引号数 = %d, want 2 (%s)", strings.Count(cond, "'"), cond)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelayConditionDiffers(t *testing.T) {
|
||||
cond := "data.eventName='TerminateInstance'"
|
||||
rule := func(c string) sch.TaskDetailsResponse {
|
||||
return sch.LogRuleTaskDetailsResponse{Condition: &c}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
tasks []sch.TaskDetailsResponse
|
||||
want string
|
||||
diff bool
|
||||
}{
|
||||
{name: "条件一致不漂移", tasks: []sch.TaskDetailsResponse{rule(cond)}, want: cond, diff: false},
|
||||
{name: "条件文本不同漂移", tasks: []sch.TaskDetailsResponse{rule("data.eventName='LaunchInstance'")}, want: cond, diff: true},
|
||||
{name: "无任务但期望条件漂移", tasks: nil, want: cond, diff: true},
|
||||
{name: "多任务漂移", tasks: []sch.TaskDetailsResponse{rule(cond), rule(cond)}, want: cond, diff: true},
|
||||
{name: "期望空且无任务不漂移", tasks: nil, want: "", diff: false},
|
||||
{name: "期望空但有任务漂移", tasks: []sch.TaskDetailsResponse{rule(cond)}, want: "", diff: true},
|
||||
{name: "条件缺失漂移", tasks: []sch.TaskDetailsResponse{sch.LogRuleTaskDetailsResponse{}}, want: cond, diff: true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := relayConditionDiffers(tt.tasks, tt.want); got != tt.diff {
|
||||
t.Errorf("differs = %v, want %v", got, tt.diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user