package oci import ( "strings" "testing" ) func TestRelayEventCondition(t *testing.T) { tests := []struct { name string events []string want string }{ {name: "单事件", events: []string{"LaunchInstance"}, want: "data.eventName='LaunchInstance'"}, { name: "多事件 or 连接", events: []string{"CreateUser", "DeleteUser"}, want: "data.eventName='CreateUser' or data.eventName='DeleteUser'", }, {name: "空清单", events: nil, want: ""}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := RelayEventCondition(tt.events); got != tt.want { t.Errorf("condition = %q, want %q", got, tt.want) } }) } } func TestRelayEventConditionQuoting(t *testing.T) { // 清单值来自代码内常量,不受外部输入;此处只固化引号格式防手滑 cond := RelayEventCondition([]string{"InstanceAction"}) if strings.Count(cond, "'") != 2 { t.Errorf("单引号数 = %d, want 2 (%s)", strings.Count(cond, "'"), cond) } }