43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package apigen
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestI18nTranslationMetadataAndVersionBoundary(t *testing.T) {
|
|
spec, err := Parse(filepath.Join(frameworkRoot(t), "examples/contracts/i18n.api"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compiled, err := Compile(spec)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ref := compiled.Spec.Errors[0].Translation
|
|
if ref == nil || ref.Namespace != "limits" || ref.Key != "exceeded" {
|
|
t.Fatal(ref)
|
|
}
|
|
if err := checkI18nRuntime(spec, []byte("module example.com/test\ngo 1.22\nrequire "+frameworkModule+" v0.25.0-preview\n"), t.TempDir()); err == nil {
|
|
t.Fatal("old runtime accepted")
|
|
}
|
|
generated, _, err := renderProject(Options{Module: "example.com/test"}, compiled, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(generated["internal/apierrors/errorsGen.go"]), "translation") || !strings.Contains(string(generated["docs/openapi.json"]), "translation") {
|
|
t.Fatal("translation metadata lost")
|
|
}
|
|
bad := readFile(t, filepath.Join(frameworkRoot(t), "examples/contracts/i18n.api"))
|
|
bad = strings.Replace(bad, `"namespace":"limits"`, `"namespace":""`, 1)
|
|
parsed, err := parseText(t, bad)
|
|
if err == nil {
|
|
_, err = Compile(parsed)
|
|
}
|
|
if err == nil {
|
|
t.Fatal("invalid translation reference accepted")
|
|
}
|
|
}
|
|
func TestI18nGeneratedConsumer(t *testing.T) { testCatalogConsumer(t, "i18n.api", "i18n") }
|