Skip to content

refactor(kclshim): decouple Synthesize from stdin/stdout I/O#575

Open
JinghanFu wants to merge 1 commit intomainfrom
jinghanfu/kclshim-decouple-io
Open

refactor(kclshim): decouple Synthesize from stdin/stdout I/O#575
JinghanFu wants to merge 1 commit intomainfrom
jinghanfu/kclshim-decouple-io

Conversation

@JinghanFu
Copy link

Accept structured input parameter and return []client.Object instead of reading from stdin and writing to stdout. Add comprehensive tests with fixture-based KCL synthesizer covering deployment and service account assertions, and error handling for bad synthesizer input.

Accept structured input parameter and return []client.Object instead of
reading from stdin and writing to stdout. Add comprehensive tests with
fixture-based KCL synthesizer covering deployment and service account
assertions, and error handling for bad synthesizer input.
return nil, fmt.Errorf("error unmarshaling output to ResourceList: %w", err)
}

var objects []client.Object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why you don't return krmv1.ResourceList directly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was doing that previously, but then I found function.Main expects SynthFunc to return ([]client.Object, error), so I added this one more step to convert krmv1.ResourceList to []client.Object

s = strings.ReplaceAll(s, whitespace, "")
}
return s
t.Run("successful synthesis", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should use https://go.dev/wiki/TableDrivenTests instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, Lei! I will update them to use table-driven tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Lei! When updating the test, I have 2 questions about when to use table-driven tests:

  1. Is it correct that we should use table-driven tests when testing the same logic across different scenarios (e.g., varying inputs, expected outputs, and error conditions)?
  2. As we can no longer compare the output as a single string, but we do need to validate individual fields (e.g., spec.containers[0].image , spec.containers[0].name ). For cases like this where there are only 2 fields to check, if I understood Table-Driven tests correctly, I felt the overhead of defining struct & writing loop is a bit heavier than just writing inline assertions? May I know would you recommend sticking with table-driven tests for these small cases, or is it better to use inline assertions when the number of items is very small?

Thank you very much, Lei!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants