|
17 | 17 | package platforms |
18 | 18 |
|
19 | 19 | import ( |
| 20 | + "sort" |
20 | 21 | "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/assert" |
21 | 24 | ) |
22 | 25 |
|
23 | 26 | func TestOnly(t *testing.T) { |
@@ -434,3 +437,86 @@ func TestOnlyStrict(t *testing.T) { |
434 | 437 | }) |
435 | 438 | } |
436 | 439 | } |
| 440 | + |
| 441 | +func TestCompareOSFeatures(t *testing.T) { |
| 442 | + for _, tc := range []struct { |
| 443 | + platform string |
| 444 | + platforms []string |
| 445 | + expected []string |
| 446 | + }{ |
| 447 | + { |
| 448 | + "linux/amd64", |
| 449 | + []string{"windows/amd64", "linux/amd64", "linux(+other)/amd64", "linux/arm64"}, |
| 450 | + []string{"linux/amd64", "linux(+other)/amd64", "windows/amd64", "linux/arm64"}, |
| 451 | + }, |
| 452 | + { |
| 453 | + "linux(+none)/amd64", |
| 454 | + []string{"windows/amd64", "linux/amd64", "linux/arm64", "linux(+other)/amd64"}, |
| 455 | + []string{"linux/amd64", "linux(+other)/amd64", "windows/amd64", "linux/arm64"}, |
| 456 | + }, |
| 457 | + { |
| 458 | + "linux(+other)/amd64", |
| 459 | + []string{"windows/amd64", "linux/amd64", "linux/arm64", "linux(+other)/amd64"}, |
| 460 | + []string{"linux(+other)/amd64", "linux/amd64", "windows/amd64", "linux/arm64"}, |
| 461 | + }, |
| 462 | + { |
| 463 | + "linux(+af+other+zf)/amd64", |
| 464 | + []string{"windows/amd64", "linux/amd64", "linux/arm64", "linux(+other)/amd64"}, |
| 465 | + []string{"linux(+other)/amd64", "linux/amd64", "windows/amd64", "linux/arm64"}, |
| 466 | + }, |
| 467 | + { |
| 468 | + "linux(+f1+f2)/amd64", |
| 469 | + []string{"linux/amd64", "linux(+f2)/amd64", "linux(+f1)/amd64", "linux(+f1+f2)/amd64"}, |
| 470 | + []string{"linux(+f1+f2)/amd64", "linux(+f2)/amd64", "linux(+f1)/amd64", "linux/amd64"}, |
| 471 | + }, |
| 472 | + } { |
| 473 | + testcase := tc |
| 474 | + t.Run(testcase.platform, func(t *testing.T) { |
| 475 | + t.Parallel() |
| 476 | + p, err := Parse(testcase.platform) |
| 477 | + if err != nil { |
| 478 | + t.Fatal(err) |
| 479 | + } |
| 480 | + |
| 481 | + for _, stc := range []struct { |
| 482 | + name string |
| 483 | + mc MatchComparer |
| 484 | + }{ |
| 485 | + { |
| 486 | + name: "only", |
| 487 | + mc: Only(p), |
| 488 | + }, |
| 489 | + { |
| 490 | + name: "only strict", |
| 491 | + mc: OnlyStrict(p), |
| 492 | + }, |
| 493 | + { |
| 494 | + name: "ordered", |
| 495 | + mc: Ordered(p), |
| 496 | + }, |
| 497 | + { |
| 498 | + name: "any", |
| 499 | + mc: Any(p), |
| 500 | + }, |
| 501 | + } { |
| 502 | + mc := stc.mc |
| 503 | + testcase := testcase |
| 504 | + t.Run(stc.name, func(t *testing.T) { |
| 505 | + p, err := ParseAll(testcase.platforms) |
| 506 | + if err != nil { |
| 507 | + t.Fatal(err) |
| 508 | + } |
| 509 | + sort.Slice(p, func(i, j int) bool { |
| 510 | + return mc.Less(p[i], p[j]) |
| 511 | + }) |
| 512 | + actual := make([]string, len(p)) |
| 513 | + for i, ps := range p { |
| 514 | + actual[i] = FormatAll(ps) |
| 515 | + } |
| 516 | + |
| 517 | + assert.Equal(t, testcase.expected, actual) |
| 518 | + }) |
| 519 | + } |
| 520 | + }) |
| 521 | + } |
| 522 | +} |
0 commit comments