| 325 | } |
| 326 | |
| 327 | func TestBranchRules(t *testing.T) { |
| 328 | t.Parallel() |
| 329 | tests := []struct { |
| 330 | name string |
| 331 | rules *BranchRules |
| 332 | json string |
| 333 | }{ |
| 334 | {"empty", &BranchRules{}, `[]`}, |
| 335 | { |
| 336 | "single_rule_type_single_rule_empty_params", |
| 337 | &BranchRules{ |
| 338 | Creation: []*BranchRuleMetadata{ |
| 339 | { |
| 340 | RulesetSourceType: RulesetSourceTypeRepository, |
| 341 | RulesetSource: "test/test", |
| 342 | RulesetID: 1, |
| 343 | }, |
| 344 | }, |
| 345 | }, |
| 346 | `[{"type":"creation","ruleset_source_type":"Repository","ruleset_source":"test/test","ruleset_id":1}]`, |
| 347 | }, |
| 348 | { |
| 349 | "single_rule_type_single_rule_with_params", |
| 350 | &BranchRules{ |
| 351 | Update: []*UpdateBranchRule{ |
| 352 | { |
| 353 | BranchRuleMetadata: BranchRuleMetadata{ |
| 354 | RulesetSourceType: RulesetSourceTypeRepository, |
| 355 | RulesetSource: "test/test", |
| 356 | RulesetID: 1, |
| 357 | }, |
| 358 | Parameters: UpdateRuleParameters{UpdateAllowsFetchAndMerge: true}, |
| 359 | }, |
| 360 | }, |
| 361 | }, |
| 362 | `[{"type":"update","ruleset_source_type":"Repository","ruleset_source":"test/test","ruleset_id":1,"parameters":{"update_allows_fetch_and_merge":true}}]`, |
| 363 | }, |
| 364 | { |
| 365 | "all_rule_types_with_all_parameters", |
| 366 | &BranchRules{ |
| 367 | Creation: []*BranchRuleMetadata{ |
| 368 | { |
| 369 | RulesetSourceType: RulesetSourceTypeRepository, |
| 370 | RulesetSource: "test/test", |
| 371 | RulesetID: 1, |
| 372 | }, |
| 373 | }, |
| 374 | Update: []*UpdateBranchRule{ |
| 375 | { |
| 376 | BranchRuleMetadata: BranchRuleMetadata{ |
| 377 | RulesetSourceType: RulesetSourceTypeRepository, |
| 378 | RulesetSource: "test/test", |
| 379 | RulesetID: 1, |
| 380 | }, |
| 381 | Parameters: UpdateRuleParameters{UpdateAllowsFetchAndMerge: true}, |
| 382 | }, |
| 383 | }, |
| 384 | Deletion: []*BranchRuleMetadata{ |