(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func TestGoTransformUnionError(t *testing.T) { |
| 47 | root := RunDSL(t, testdata.TestUnionDSL) |
| 48 | var ( |
| 49 | scope = NewNameScope() |
| 50 | |
| 51 | // types to test |
| 52 | unionString = root.UserType("Container").Attribute().Find("UnionString").Find("UnionString") |
| 53 | unionStringInt = root.UserType("Container").Attribute().Find("UnionStringInt").Find("UnionStringInt") |
| 54 | unionSomeType = root.UserType("Container").Attribute().Find("UnionSomeType").Find("UnionSomeType") |
| 55 | defaultCtx = NewAttributeContext(false, false, true, "", scope) |
| 56 | ) |
| 57 | tc := []struct { |
| 58 | Name string |
| 59 | Source *expr.AttributeExpr |
| 60 | Target *expr.AttributeExpr |
| 61 | Error string |
| 62 | }{ |
| 63 | {"UnionString to UnionStringInt", unionString, unionStringInt, "cannot transform union: number of union types differ (UnionString has 1, UnionStringInt has 2)"}, |
| 64 | {"UnionString to UnionSomeType", unionString, unionSomeType, "cannot transform union UnionString to UnionSomeType: type at index 0: source is a string but target type is object"}, |
| 65 | } |
| 66 | for _, c := range tc { |
| 67 | t.Run(c.Name, func(t *testing.T) { |
| 68 | _, _, err := GoTransform(c.Source, c.Target, "source", "target", defaultCtx, defaultCtx, "", true) |
| 69 | if err == nil { |
| 70 | t.Errorf("unexpected success") |
| 71 | return |
| 72 | } |
| 73 | if err.Error() != c.Error { |
| 74 | t.Errorf("unexpected error, got: %s, expected: %s", err, c.Error) |
| 75 | } |
| 76 | }) |
| 77 | } |
| 78 | } |
nothing calls this directly
no test coverage detected