Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format kind JSON the same way the manifest is formatted. #486

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/grafana-app-sdk/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ func generateKindsCue(modFS fs.FS, cfg kindGenConfig, selectors ...string) (code
// CRD
var crdFiles codejen.Files
if cfg.CRDEncoding != "none" {
encFunc := json.Marshal
encFunc := func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}
if cfg.CRDEncoding == "yaml" {
encFunc = yaml.Marshal
}
Expand Down
6 changes: 5 additions & 1 deletion codegen/cuekind/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const (
ReferenceOutputDirectory = "../testing/golden_generated"
)

var jsonEncoder = func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}

func TestCRDGenerator(t *testing.T) {
// Ideally, we test only that this outputs the right jennies,
// but right now we just test the whole pipeline from thema -> written files
Expand All @@ -28,7 +32,7 @@ func TestCRDGenerator(t *testing.T) {
require.Nil(t, err)

t.Run("JSON", func(t *testing.T) {
files, err := CRDGenerator(json.Marshal, "json").Generate(kinds...)
files, err := CRDGenerator(jsonEncoder, "json").Generate(kinds...)
require.Nil(t, err)
// Check number of files generated
assert.Len(t, files, 2)
Expand Down
Loading
Loading