(t *testing.T)
| 152 | } |
| 153 | |
| 154 | func TestStructPkgPath_UnionImportsJSON(t *testing.T) { |
| 155 | root := codegen.RunDSL(t, testdata.PkgPathUnionDSL) |
| 156 | services := NewServicesData(root) |
| 157 | require.Len(t, root.Services, 1) |
| 158 | |
| 159 | files := Files("goa.design/goa/example", root.Services[0], services, make(map[string][]string)) |
| 160 | require.GreaterOrEqual(t, len(files), 2, "expected at least service.go + one struct:pkg:path file") |
| 161 | |
| 162 | var typeFile *codegen.File |
| 163 | for _, f := range files { |
| 164 | if strings.HasSuffix(f.Path, filepath.Join("gen", "types", "type_with_union.go")) { |
| 165 | typeFile = f |
| 166 | break |
| 167 | } |
| 168 | } |
| 169 | require.NotNil(t, typeFile, "expected generated type file for struct:pkg:path type_with_union") |
| 170 | |
| 171 | buf := new(bytes.Buffer) |
| 172 | for _, s := range typeFile.SectionTemplates { |
| 173 | require.NoError(t, s.Write(buf)) |
| 174 | } |
| 175 | code := buf.String() |
| 176 | require.Contains(t, code, "\"encoding/json\"", "expected encoding/json import in generated file:\n%s", code) |
| 177 | } |
| 178 | |
| 179 | func TestStructPkgPath_UnionJSONFieldBranchesGenerateAliases(t *testing.T) { |
| 180 | root := codegen.RunDSL(t, testdata.PkgPathUnionJSONFieldDSL) |
nothing calls this directly
no test coverage detected