TestBuildLabelCommandCondition verifies the condition builder for label-command triggers.
(t *testing.T)
| 127 | |
| 128 | // TestBuildLabelCommandCondition verifies the condition builder for label-command triggers. |
| 129 | func TestBuildLabelCommandCondition(t *testing.T) { |
| 130 | tests := []struct { |
| 131 | name string |
| 132 | labelNames []string |
| 133 | events []string |
| 134 | hasOtherEvents bool |
| 135 | wantErr bool |
| 136 | wantContains []string |
| 137 | wantNotContains []string |
| 138 | }{ |
| 139 | { |
| 140 | name: "single label all events no other events", |
| 141 | labelNames: []string{"deploy"}, |
| 142 | events: nil, |
| 143 | wantContains: []string{ |
| 144 | "github.event.label.name == 'deploy'", |
| 145 | "github.event_name == 'issues'", |
| 146 | "github.event_name == 'pull_request'", |
| 147 | "github.event_name == 'discussion'", |
| 148 | }, |
| 149 | }, |
| 150 | { |
| 151 | name: "multiple labels all events", |
| 152 | labelNames: []string{"deploy", "release"}, |
| 153 | events: nil, |
| 154 | wantContains: []string{ |
| 155 | "github.event.label.name == 'deploy'", |
| 156 | "github.event.label.name == 'release'", |
| 157 | }, |
| 158 | }, |
| 159 | { |
| 160 | name: "single label issues only", |
| 161 | labelNames: []string{"triage"}, |
| 162 | events: []string{"issues"}, |
| 163 | wantContains: []string{ |
| 164 | "github.event_name == 'issues'", |
| 165 | "github.event.label.name == 'triage'", |
| 166 | }, |
| 167 | wantNotContains: []string{ |
| 168 | "github.event_name == 'pull_request'", |
| 169 | "github.event_name == 'discussion'", |
| 170 | }, |
| 171 | }, |
| 172 | { |
| 173 | name: "no label names returns error", |
| 174 | labelNames: []string{}, |
| 175 | wantErr: true, |
| 176 | }, |
| 177 | } |
| 178 | |
| 179 | for _, tt := range tests { |
| 180 | t.Run(tt.name, func(t *testing.T) { |
| 181 | condition, err := buildLabelCommandCondition(tt.labelNames, tt.events, tt.hasOtherEvents) |
| 182 | if tt.wantErr { |
| 183 | assert.Error(t, err, "expected an error") |
| 184 | return |
| 185 | } |
| 186 |
nothing calls this directly
no test coverage detected