-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add unit test for generating data source #5439
base: main
Are you sure you want to change the base?
Add unit test for generating data source #5439
Conversation
…c#5283) - Implement unit tests to validate datasource definition generation from Swagger files. - Ensure hardcoded OpenAPI v2 docs produce expected datasource definitions. - Maintain robustness of generation command to prevent accidental breaks. Signed-off-by: Kugamoorthy Gajananan <[email protected]>
…c#5283) - Implement unit tests to validate datasource definition generation from Swagger files. - Ensure hardcoded OpenAPI v2 docs produce expected datasource definitions. - Maintain robustness of generation command to prevent accidental breaks. - Renamed generate_test to main_test.go and moved it to cmd/dev/ Signed-off-by: Kugamoorthy Gajananan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! This looks fairly good, but a couple questions about the implementation.
I also noticed a data race warning; you might want to try running with -race -count 20
to see if you can shake it out.
|
||
// Handle the case for missing OpenAPI file | ||
if tt.name == "missing OpenAPI file" { | ||
mu.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a mutex around this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This segment of code should not be there, the mutex. should not be.
if tt.name == "missing OpenAPI file" { | ||
mu.Lock() | ||
assert.FileExists(t, tt.openAPIFile, "OpenAPI file should not exist") | ||
mu.Unlock() | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever get here, given that tt.expectedError == true
for the "missing OpenAPI file" case, and that exits on line 109?
(This will allow you to simplify the test code, which is another win)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. it won't reach there.
// Add a slight delay to ensure the output is captured correctly | ||
time.Sleep(100 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a "Sleep" after we've read and compared all the content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the following code to capture output from Command execution, at times the output was not captured properly, I tried few option to see, it is one of them. I agree it does not make sense when I look at it.
// Create a pipe to capture the output,
r, w, _ := os.Pipe()
os.Stdout = w
// Redirect the output to the buffer in a separate goroutine
outC := make(chan string)
go func() {
var buf bytes.Buffer
_, err = io.Copy(&buf, r)
assert.NoError(t, err, "Buffer copy should not produce an error")
outC <- buf.String()
}()
Summary
Add unit tests for Swagger datasource definition generation (#5283)
Ref #(5300)
Change Type
Mark the type of change your PR introduces:
Testing
Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.
Review Checklist: