(t *testing.T)
| 1551 | } |
| 1552 | |
| 1553 | func TestFeatureValidate(t *testing.T) { |
| 1554 | tests := []struct { |
| 1555 | name string |
| 1556 | f *Feature |
| 1557 | want error |
| 1558 | }{ |
| 1559 | { |
| 1560 | name: "nil feature", |
| 1561 | f: nil, |
| 1562 | want: errors.New("invalid feature: nil"), |
| 1563 | }, |
| 1564 | { |
| 1565 | name: "empty feature", |
| 1566 | f: NewFeature("", true), |
| 1567 | want: errors.New("missing name"), |
| 1568 | }, |
| 1569 | } |
| 1570 | |
| 1571 | for _, tst := range tests { |
| 1572 | tc := tst |
| 1573 | t.Run(tc.name, func(t *testing.T) { |
| 1574 | err := tc.f.Validate() |
| 1575 | if err == nil && tc.want == nil { |
| 1576 | return |
| 1577 | } |
| 1578 | if err == nil && tc.want != nil { |
| 1579 | t.Fatalf("f.Validate() got valid, wanted error %v", tc.want) |
| 1580 | } |
| 1581 | if err != nil && tc.want == nil { |
| 1582 | t.Fatalf("f.Validate() got error %v, wanted nil error", err) |
| 1583 | } |
| 1584 | if !strings.Contains(err.Error(), tc.want.Error()) { |
| 1585 | t.Errorf("f.Validate() got error %v, wanted %v", err, tc.want) |
| 1586 | } |
| 1587 | }) |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | func mustNewFunction(t *testing.T, name string, opts ...decls.FunctionOpt) *decls.FunctionDecl { |
| 1592 | t.Helper() |
nothing calls this directly
no test coverage detected