-
Notifications
You must be signed in to change notification settings - Fork 657
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
Fix flytectlt tests #5325
Fix flytectlt tests #5325
Conversation
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
func SetupWithExt() (s TestStruct) { | ||
s.Ctx = context.Background() | ||
s.Reader, s.Writer, s.Err = os.Pipe() | ||
if s.Err != nil { | ||
panic(s.Err) | ||
} | ||
s.StdOut = os.Stdout | ||
s.Stderr = os.Stderr | ||
os.Stdout = s.Writer | ||
os.Stderr = s.Writer | ||
log.SetOutput(s.Writer) | ||
s.MockClient = admin.InitializeMockClientset() | ||
s.FetcherExt = new(extMocks.AdminFetcherExtInterface) | ||
s.UpdaterExt = new(extMocks.AdminUpdaterExtInterface) | ||
s.DeleterExt = new(extMocks.AdminDeleterExtInterface) | ||
s.FetcherExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) | ||
s.UpdaterExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) | ||
s.DeleterExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) | ||
s.MockAdminClient = s.MockClient.AdminClient().(*mocks.AdminServiceClient) | ||
s.MockOutStream = s.Writer | ||
s.CmdCtx = cmdCore.NewCommandContextWithExt(s.MockClient, s.FetcherExt, s.UpdaterExt, s.DeleterExt, s.MockOutStream) | ||
config.GetConfig().Project = projectValue | ||
config.GetConfig().Domain = domainValue | ||
config.GetConfig().Output = output | ||
|
||
return s |
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 function is an exact copy of Setup
, so I'm dropping it.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5325 +/- ##
==========================================
+ Coverage 60.20% 61.07% +0.86%
==========================================
Files 646 794 +148
Lines 45654 51203 +5549
==========================================
+ Hits 27487 31270 +3783
- Misses 15575 17050 +1475
- Partials 2592 2883 +291
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
nice find
@@ -48,6 +48,8 @@ func createExecutionUtilSetup() { | |||
|
|||
func TestCreateExecutionForRelaunch(t *testing.T) { | |||
s := setup() | |||
defer s.RestoreStandardFileDescriptors() |
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.
nit: maybe call this teardown()
to match with go test name conventions, so users don't have to think about whether or not to call this function (and potentially miss doing so?)
Signed-off-by: Eduardo Apolinario <[email protected]>
8fb8a99
* Add defer to compile_test Signed-off-by: Eduardo Apolinario <[email protected]> * Add the actual command Signed-off-by: Eduardo Apolinario <[email protected]> * Fix cmd/create tests Signed-off-by: Eduardo Apolinario <[email protected]> * Fix create tests Signed-off-by: Eduardo Apolinario <[email protected]> * Fix cmd/get tests Signed-off-by: Eduardo Apolinario <[email protected]> * Fix cmd/update tests Signed-off-by: Eduardo Apolinario <[email protected]> * Remove testutils.SetupWithExt Signed-off-by: Eduardo Apolinario <[email protected]> * Remove bespoke `test_unit` make target Signed-off-by: Eduardo Apolinario <[email protected]> * Fix other tests Signed-off-by: Eduardo Apolinario <[email protected]> * s/RestoreStandardFileDescriptors/TearDown/g Signed-off-by: Eduardo Apolinario <[email protected]> --------- Signed-off-by: Eduardo Apolinario <[email protected]> Co-authored-by: Eduardo Apolinario <[email protected]>
* Add defer to compile_test Signed-off-by: Eduardo Apolinario <[email protected]> * Add the actual command Signed-off-by: Eduardo Apolinario <[email protected]> * Fix cmd/create tests Signed-off-by: Eduardo Apolinario <[email protected]> * Fix create tests Signed-off-by: Eduardo Apolinario <[email protected]> * Fix cmd/get tests Signed-off-by: Eduardo Apolinario <[email protected]> * Fix cmd/update tests Signed-off-by: Eduardo Apolinario <[email protected]> * Remove testutils.SetupWithExt Signed-off-by: Eduardo Apolinario <[email protected]> * Remove bespoke `test_unit` make target Signed-off-by: Eduardo Apolinario <[email protected]> * Fix other tests Signed-off-by: Eduardo Apolinario <[email protected]> * s/RestoreStandardFileDescriptors/TearDown/g Signed-off-by: Eduardo Apolinario <[email protected]> --------- Signed-off-by: Eduardo Apolinario <[email protected]> Co-authored-by: Eduardo Apolinario <[email protected]>
Tracking issue
#5316
Why are the changes needed?
We fixed a few of the flytectl issues in #5309, but decided to merge that PR with a few unit tests failing. This PR fixes them.
What changes were proposed in this pull request?
We have a few flytectl unit tests that rely on a TestStruct to capture what's written to standard output and error, but if those file descriptors are not restored then the respective test suites would fail every now and then. In this PR we add a defer statement to ensure that the original file descriptors are restored to the os package.
How was this patch tested?
Unit tests running in a loop locally (e.g.
seq 100 | xargs -n1 make test_unit
).Setup process
Screenshots
Check all the applicable boxes
Related PRs
Docs link