Uploaded image for project: 'Couchbase Gateway'
  1. Couchbase Gateway
  2. CBG-860

Use t.Cleanup for automatic SetUpTestLogging teardown

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • Helium
    • SyncGateway
    • Security Level: Public
    • None
    • CBG Sprint 97
    • 2

    Description

      SetUpTestLogging returns a teardown function that needs deferring for each test, which results in awkward test setup code, it can be easy to forget the last parentheses, or the defer:

      defer SetUpTestLogging(LevelDebug, KeyCRUD)()

      Go 1.14 added t.Cleanup(), which runs a function when the given test has finished.
      This has the advantage that setup functions can register their own teardowns by passing in t, and reducing test setup to:

      SetUpTestLogging(t, LevelDebug, KeyCRUD)

      It would be interesting to see if this method can be applied to RestTester/TestBuckets in the future, as it's also easy to forget to call Close().

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            ben.brooks Ben Brooks added a comment - - edited

            Tagging as lithium because of the Go 1.14 prerequisite and blocker via CBG-756

            ben.brooks Ben Brooks added a comment - - edited Tagging as lithium because of the Go 1.14 prerequisite and blocker via CBG-756

            Build sync_gateway-3.1.0-127 contains sync_gateway commit 62c6285 with commit message:
            CBG-860: Replace defer SetUpTestLogging() with tb.Cleanup() (#5518)

            build-team Couchbase Build Team added a comment - Build sync_gateway-3.1.0-127 contains sync_gateway commit 62c6285 with commit message: CBG-860 : Replace defer SetUpTestLogging() with tb.Cleanup() (#5518)

            People

              marks.polakovs Marks Polakovs
              ben.brooks Ben Brooks
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty