(t *testing.T)
| 206 | } |
| 207 | |
| 208 | func TestNewFieldRemovalCodemod_TableDriven(t *testing.T) { |
| 209 | tests := []struct { |
| 210 | name string |
| 211 | content string |
| 212 | frontmatter map[string]any |
| 213 | wantApplied bool |
| 214 | wantContent string // expected substring in result when applied, or full match when not applied |
| 215 | }{ |
| 216 | { |
| 217 | name: "parent key absent", |
| 218 | content: "---\non: workflow_dispatch\n---\n\n# Test", |
| 219 | frontmatter: map[string]any{ |
| 220 | "on": "workflow_dispatch", |
| 221 | }, |
| 222 | wantApplied: false, |
| 223 | }, |
| 224 | { |
| 225 | name: "parent not a map", |
| 226 | content: "---\non: workflow_dispatch\nparent: scalar\n---\n\n# Test", |
| 227 | frontmatter: map[string]any{ |
| 228 | "on": "workflow_dispatch", |
| 229 | "parent": "scalar", |
| 230 | }, |
| 231 | wantApplied: false, |
| 232 | }, |
| 233 | { |
| 234 | name: "child field absent", |
| 235 | content: "---\non: workflow_dispatch\nparent:\n other: val\n---\n\n# Test", |
| 236 | frontmatter: map[string]any{ |
| 237 | "on": "workflow_dispatch", |
| 238 | "parent": map[string]any{"other": "val"}, |
| 239 | }, |
| 240 | wantApplied: false, |
| 241 | }, |
| 242 | { |
| 243 | name: "child field present", |
| 244 | content: "---\non: workflow_dispatch\nparent:\n child: yes\n other: val\n---\n\n# Test", |
| 245 | frontmatter: map[string]any{ |
| 246 | "on": "workflow_dispatch", |
| 247 | "parent": map[string]any{"child": true, "other": "val"}, |
| 248 | }, |
| 249 | wantApplied: true, |
| 250 | wantContent: "other: val", |
| 251 | }, |
| 252 | } |
| 253 | |
| 254 | for _, tt := range tests { |
| 255 | t.Run(tt.name, func(t *testing.T) { |
| 256 | codemod := newFieldRemovalCodemod(baseFieldRemovalConfig()) |
| 257 | |
| 258 | result, applied, err := codemod.Apply(tt.content, tt.frontmatter) |
| 259 | |
| 260 | require.NoError(t, err, "Apply should not return an error") |
| 261 | assert.Equal(t, tt.wantApplied, applied, "Applied flag should match expectation") |
| 262 | |
| 263 | if tt.wantApplied { |
| 264 | assert.Contains(t, result, tt.wantContent, "Result should contain expected content") |
| 265 | assert.NotContains(t, result, "child:", "Result should not contain removed field") |
nothing calls this directly
no test coverage detected