MCPcopy Create free account
hub / github.com/goadesign/goa / TestAttributeExprAllRequired

Function TestAttributeExprAllRequired

expr/attribute_test.go:539–574  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

537}
538
539func TestAttributeExprAllRequired(t *testing.T) {
540 cases := map[string]struct {
541 typ DataType
542 expected []string
543 }{
544 "some required": {
545 typ: &UserTypeExpr{
546 AttributeExpr: &AttributeExpr{
547 Validation: &ValidationExpr{
548 Required: []string{"foo", "bar"},
549 },
550 },
551 },
552 expected: []string{"foo", "bar"},
553 },
554 "no required": {
555 typ: Boolean,
556 expected: nil,
557 },
558 }
559
560 for k, tc := range cases {
561 attribute := AttributeExpr{
562 Type: tc.typ,
563 }
564 if actual := attribute.AllRequired(); len(tc.expected) != len(actual) {
565 t.Errorf("%s: expected the number of all required values to match %d got %d ", k, len(tc.expected), len(actual))
566 } else {
567 for i, v := range actual {
568 if v != tc.expected[i] {
569 t.Errorf("%s: got %#v, expected %#v at index %d", k, v, tc.expected[i], i)
570 }
571 }
572 }
573 }
574}
575
576func TestAttributeExprIsRequired(t *testing.T) {
577 cases := map[string]struct {

Callers

nothing calls this directly

Calls 1

AllRequiredMethod · 0.95

Tested by

no test coverage detected