amazon-ecs-agent icon indicating copy to clipboard operation
amazon-ecs-agent copied to clipboard

test: use `T.TempDir` to create temporary test directory

Open Juneezee opened this issue 3 years ago • 5 comments

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.TempDir with t.TempDir
  • Setup function such as newTestDataClient(t *testing.T) no longer returns a cleanup func(). It now uses t.Cleanup to 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.

Juneezee avatar Mar 27 '22 06:03 Juneezee

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 avatar May 03 '22 17:05 singholt

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.

Juneezee avatar May 03 '22 17:05 Juneezee

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.

fierlion avatar Aug 23 '22 22:08 fierlion

Hi @fierlion, thanks for looking into this PR. I've rebased onto dev.

Juneezee avatar Aug 24 '22 01:08 Juneezee

Rebased onto dev and resolved conflicts.

Juneezee avatar Sep 30 '22 16:09 Juneezee

closed by https://github.com/aws/amazon-ecs-agent/pull/3560, thank you for the contribution @Juneezee !!

sparrc avatar Feb 11 '23 03:02 sparrc