mirror of
https://github.com/foomo/squadron.git
synced 2025-10-16 12:35:42 +00:00
This commit is contained in:
parent
56c031a56c
commit
c5222e30a8
41
schema_test.go
Normal file
41
schema_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package squadron_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
testingx "github.com/foomo/go/testing"
|
||||||
|
tagx "github.com/foomo/go/testing/tag"
|
||||||
|
"github.com/foomo/squadron/internal/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)
|
||||||
|
require.NoError(t, reflector.AddGoComments("github.com/foomo/squadron", "./"))
|
||||||
|
schema := reflector.Reflect(&config.Config{})
|
||||||
|
schema.ID = "https://raw.githubusercontent.com/foomo/squadron/refs/heads/main/squadron.schema.json"
|
||||||
|
actual, err := json.MarshalIndent(schema, "", " ")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
filename := path.Join(cwd, "squadron.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))
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
"$id": "https://github.com/foomo/squadron/internal/config/config",
|
"$id": "https://raw.githubusercontent.com/foomo/squadron/refs/heads/main/squadron.schema.json",
|
||||||
"$ref": "#/$defs/Config",
|
"$ref": "#/$defs/Config",
|
||||||
"$defs": {
|
"$defs": {
|
||||||
"BakeTarget": {
|
"BakeTarget": {
|
||||||
|
|||||||
@ -1,48 +1,18 @@
|
|||||||
package squadron_test
|
package squadron_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
testingx "github.com/foomo/go/testing"
|
testingx "github.com/foomo/go/testing"
|
||||||
tagx "github.com/foomo/go/testing/tag"
|
tagx "github.com/foomo/go/testing/tag"
|
||||||
"github.com/foomo/squadron"
|
"github.com/foomo/squadron"
|
||||||
"github.com/foomo/squadron/internal/config"
|
|
||||||
"github.com/foomo/squadron/internal/testutils"
|
"github.com/foomo/squadron/internal/testutils"
|
||||||
"github.com/foomo/squadron/internal/util"
|
"github.com/foomo/squadron/internal/util"
|
||||||
"github.com/invopop/jsonschema"
|
|
||||||
"github.com/pterm/pterm"
|
"github.com/pterm/pterm"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfig(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
testingx.Tags(t, tagx.Short)
|
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
reflector := new(jsonschema.Reflector)
|
|
||||||
require.NoError(t, reflector.AddGoComments("github.com/foomo/squadron", "./"))
|
|
||||||
schema := reflector.Reflect(&config.Config{})
|
|
||||||
actual, err := json.MarshalIndent(schema, "", " ")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
filename := path.Join(cwd, "squadron.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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConfigSimpleSnapshot(t *testing.T) {
|
func TestConfigSimpleSnapshot(t *testing.T) {
|
||||||
testingx.Tags(t, tagx.Short)
|
testingx.Tags(t, tagx.Short)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user