(t *testing.T)
| 1444 | } |
| 1445 | |
| 1446 | func TestFeatureValidate(t *testing.T) { |
| 1447 | tests := []struct { |
| 1448 | name string |
| 1449 | f *Feature |
| 1450 | want error |
| 1451 | }{ |
| 1452 | { |
| 1453 | name: "nil feature", |
| 1454 | f: nil, |
| 1455 | want: errors.New("invalid feature: nil"), |
| 1456 | }, |
| 1457 | { |
| 1458 | name: "empty feature", |
| 1459 | f: NewFeature("", true), |
| 1460 | want: errors.New("missing name"), |
| 1461 | }, |
| 1462 | } |
| 1463 | |
| 1464 | for _, tst := range tests { |
| 1465 | tc := tst |
| 1466 | t.Run(tc.name, func(t *testing.T) { |
| 1467 | err := tc.f.Validate() |
| 1468 | if err == nil && tc.want == nil { |
| 1469 | return |
| 1470 | } |
| 1471 | if err == nil && tc.want != nil { |
| 1472 | t.Fatalf("f.Validate() got valid, wanted error %v", tc.want) |
| 1473 | } |
| 1474 | if err != nil && tc.want == nil { |
| 1475 | t.Fatalf("f.Validate() got error %v, wanted nil error", err) |
| 1476 | } |
| 1477 | if !strings.Contains(err.Error(), tc.want.Error()) { |
| 1478 | t.Errorf("f.Validate() got error %v, wanted %v", err, tc.want) |
| 1479 | } |
| 1480 | }) |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | func mustNewFunction(t *testing.T, name string, opts ...decls.FunctionOpt) *decls.FunctionDecl { |
| 1485 | t.Helper() |
nothing calls this directly
no test coverage detected