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

Function TestHashAttribute

http/codegen/openapi/v3/types_test.go:488–635  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

486}
487
488func TestHashAttribute(t *testing.T) {
489 type (
490 testAttr struct {
491 name string
492 att *expr.AttributeExpr
493 }
494
495 hashBehavior int
496
497 testGroup struct {
498 name string
499 attrs []testAttr
500 behavior hashBehavior
501 }
502 )
503
504 const (
505 uniqueHashes hashBehavior = iota
506 identicalHashes
507 )
508
509 var (
510 metaNotGenerate = expr.MetaExpr{"openapi:generate": []string{"false"}}
511 metaEmpty = expr.MetaExpr{}
512 )
513
514 cases := []testGroup{
515 {
516 name: "Primitive types",
517 behavior: uniqueHashes,
518 attrs: []testAttr{
519 {name: "bool", att: &expr.AttributeExpr{Type: expr.Boolean}},
520 {name: "int", att: &expr.AttributeExpr{Type: expr.Int}},
521 {name: "int32", att: &expr.AttributeExpr{Type: expr.Int32}},
522 {name: "int64", att: &expr.AttributeExpr{Type: expr.Int64}},
523 {name: "uint", att: &expr.AttributeExpr{Type: expr.UInt}},
524 {name: "uint32", att: &expr.AttributeExpr{Type: expr.UInt32}},
525 {name: "uint64", att: &expr.AttributeExpr{Type: expr.UInt64}},
526 {name: "float32", att: &expr.AttributeExpr{Type: expr.Float32}},
527 {name: "float64", att: &expr.AttributeExpr{Type: expr.Float64}},
528 {name: "string", att: &expr.AttributeExpr{Type: expr.String}},
529 {name: "bytes", att: &expr.AttributeExpr{Type: expr.Bytes}},
530 {name: "any", att: &expr.AttributeExpr{Type: expr.Any}},
531 },
532 }, {
533 name: "Collection types",
534 behavior: uniqueHashes,
535 attrs: []testAttr{
536 {name: "array-bool", att: &expr.AttributeExpr{Type: &expr.Array{ElemType: &expr.AttributeExpr{Type: expr.Boolean}}}},
537 {name: "array-int", att: &expr.AttributeExpr{Type: &expr.Array{ElemType: &expr.AttributeExpr{Type: expr.Int}}}},
538 {name: "map-str-int", att: &expr.AttributeExpr{Type: &expr.Map{KeyType: &expr.AttributeExpr{Type: expr.String}, ElemType: &expr.AttributeExpr{Type: expr.Int}}}},
539 {name: "map-str-str", att: &expr.AttributeExpr{Type: &expr.Map{KeyType: &expr.AttributeExpr{Type: expr.String}, ElemType: &expr.AttributeExpr{Type: expr.String}}}},
540 },
541 }, {
542 name: "Objects with validation rules",
543 behavior: uniqueHashes,
544 attrs: []testAttr{
545 {name: "no-validation", att: newObj("foo", false)},

Callers

nothing calls this directly

Calls 10

NewRandomFunction · 0.92
newObjFunction · 0.85
newRTFunction · 0.85
newRTWithViewFunction · 0.85
newObj2MetaFunction · 0.85
newUserTypeFunction · 0.85
newRecursiveTypeFunction · 0.85
newSchemafierFunction · 0.85
hashAttributeMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected