-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathschema_test.go
More file actions
42 lines (35 loc) · 1.09 KB
/
schema_test.go
File metadata and controls
42 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package gotsrpc_test
import (
"encoding/json"
"errors"
"os"
"path"
"testing"
testingx "github.com/foomo/go/testing"
tagx "github.com/foomo/go/testing/tag"
"github.com/foomo/gotsrpc/v2/config"
"github.com/invopop/jsonschema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSchema(t *testing.T) {
t.Parallel()
testingx.Tags(t, tagx.Short)
cwd, err := os.Getwd()
require.NoError(t, err)
reflector := new(jsonschema.Reflector)
reflector.RequiredFromJSONSchemaTags = true
require.NoError(t, reflector.AddGoComments("github.com/foomo/gotsrpc/v2/config", "./"))
schema := reflector.Reflect(&config.Config{})
schema.ID = "https://raw.githubusercontent.com/foomo/gotsrpc/refs/heads/main/gotsrpc.schema.json"
actual, err := json.MarshalIndent(schema, "", " ")
require.NoError(t, err)
filename := path.Join(cwd, "gotsrpc.schema.json")
expected, err := os.ReadFile(filename)
if !errors.Is(err, os.ErrNotExist) {
require.NoError(t, err)
}
if !assert.Equal(t, string(expected), string(actual)) {
require.NoError(t, os.WriteFile(filename, actual, 0600))
}
}