mirror of https://github.com/databricks/cli.git
test: Checks missing descriptions in annotation files
This commit is contained in:
parent
12c43737a8
commit
049e11b139
|
@ -11,7 +11,7 @@
|
||||||
"required": ["go"],
|
"required": ["go"],
|
||||||
"post_generate": [
|
"post_generate": [
|
||||||
"go test -timeout 240s -run TestConsistentDatabricksSdkVersion github.com/databricks/cli/internal/build",
|
"go test -timeout 240s -run TestConsistentDatabricksSdkVersion github.com/databricks/cli/internal/build",
|
||||||
"go run ./bundle/internal/schema/*.go ./bundle/internal/schema ./bundle/schema/jsonschema.json",
|
"make schema",
|
||||||
"echo 'bundle/internal/tf/schema/\\*.go linguist-generated=true' >> ./.gitattributes",
|
"echo 'bundle/internal/tf/schema/\\*.go linguist-generated=true' >> ./.gitattributes",
|
||||||
"echo 'go.sum linguist-generated=true' >> ./.gitattributes",
|
"echo 'go.sum linguist-generated=true' >> ./.gitattributes",
|
||||||
"echo 'bundle/schema/jsonschema.json linguist-generated=true' >> ./.gitattributes"
|
"echo 'bundle/schema/jsonschema.json linguist-generated=true' >> ./.gitattributes"
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -38,3 +38,6 @@ vendor:
|
||||||
|
|
||||||
.PHONY: build vendor coverage test lint fmt
|
.PHONY: build vendor coverage test lint fmt
|
||||||
|
|
||||||
|
schema:
|
||||||
|
@echo "✓ Generating json-schema ..."
|
||||||
|
@go run $(shell find ./bundle/internal/schema -name "*.go" ! -name "*_test.go") ./bundle/internal/schema ./bundle/schema/jsonschema.json
|
||||||
|
|
|
@ -123,6 +123,10 @@ func main() {
|
||||||
// Output file, where the generated JSON schema will be written to.
|
// Output file, where the generated JSON schema will be written to.
|
||||||
outputFile := os.Args[2]
|
outputFile := os.Args[2]
|
||||||
|
|
||||||
|
generateSchema(workdir, outputFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateSchema(workdir, outputFile string) {
|
||||||
annotationsPath := path.Join(workdir, "annotations.yml")
|
annotationsPath := path.Join(workdir, "annotations.yml")
|
||||||
annotationsOpenApiPath := path.Join(workdir, "annotations_openapi.yml")
|
annotationsOpenApiPath := path.Join(workdir, "annotations_openapi.yml")
|
||||||
annotationsOpenApiOverridesPath := path.Join(workdir, "annotations_openapi_overrides.yml")
|
annotationsOpenApiOverridesPath := path.Join(workdir, "annotations_openapi_overrides.yml")
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func copyFile(src, dst string) error {
|
||||||
|
in, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer in.Close()
|
||||||
|
|
||||||
|
out, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(out, in)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks whether descriptions are added for new config fields in the annotations.yml file
|
||||||
|
// If this test fails either manually add descriptions to the `annotations.yml` or do the following:
|
||||||
|
// 1. run `make schema` from the repository root to add placeholder descriptions
|
||||||
|
// 2. replace all "PLACEHOLDER" values with the actual descriptions if possible
|
||||||
|
// 3. run `make schema` again to regenerate the schema with acutal descriptions
|
||||||
|
func TestRequiredAnnotationsForNewFields(t *testing.T) {
|
||||||
|
workdir := t.TempDir()
|
||||||
|
annotationsPath := path.Join(workdir, "annotations.yml")
|
||||||
|
annotationsOpenApiPath := path.Join(workdir, "annotations_openapi.yml")
|
||||||
|
annotationsOpenApiOverridesPath := path.Join(workdir, "annotations_openapi_overrides.yml")
|
||||||
|
|
||||||
|
// Copy existing annotation files from the same folder as this test
|
||||||
|
err := copyFile("annotations.yml", annotationsPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
err = copyFile("annotations_openapi.yml", annotationsOpenApiPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
err = copyFile("annotations_openapi_overrides.yml", annotationsOpenApiOverridesPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
generateSchema(workdir, path.Join(t.TempDir(), "schema.json"))
|
||||||
|
|
||||||
|
original, err := os.ReadFile("annotations.yml")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
copied, err := os.ReadFile(annotationsPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, string(original), string(copied), "Missing JSON-schema descriptions for new config fields in bundle/internal/schema/annotations.yml")
|
||||||
|
}
|
Loading…
Reference in New Issue