test: use `T.TempDir` to create temporary test directory
Summary
A testing cleanup. We can use the T.TempDir function from the testing package to create temporary directory. The directory created by T.TempDir is automatically removed when the test and all its subtests complete.
This PR also refactor several cleanup logic by using t.Cleanup instead of defer.
Reference: https://pkg.go.dev/testing#T.TempDir Reference: https://pkg.go.dev/testing#T.Cleanup
Implementation details
- Replaces
ioutil.TempDirwitht.TempDir - Setup function such as
newTestDataClient(t *testing.T)no longer returns acleanup func(). It now usest.Cleanupto handle the cleanup when the test finishes.
Testing
make test and make run-integ-tests on Linux machine.
New tests cover the changes: yes
Description for the changelog
Enhancement - Use T.TempDir to create temporary test directory
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Hi @Juneezee, thanks a lot for submitting this change. I see that the target branch is "master", could you please open this PR against "dev"?
Hi @Juneezee, thanks a lot for submitting this change. I see that the target branch is "master", could you please open this PR against "dev"?
@singholt Oops sorry. I have changed it to dev.
Hi @Juneezee -- again sorry to have taken so long to get around to this. I see that the windows integration tests failed in the last test run. Unfortunately we'll need you to push an update to rebase against the latest dev to retrigger the tests. Would you be able to do this. If the tests continue to fail, I can share the failure logs with you and help in the debugging effort.
Hi @fierlion, thanks for looking into this PR. I've rebased onto dev.
Rebased onto dev and resolved conflicts.
closed by https://github.com/aws/amazon-ecs-agent/pull/3560, thank you for the contribution @Juneezee !!