FAQ
I am writing some tests using the "go test" utility which access Redis,
making them not strict unit tests. I am doing this because there isn't much
Go code to test: there are Lua functions defined in my Go code which
execute in Redis, and it's the Lua code I really wish to test, so
communication with Redis is required.

Right now I plan to start Redis externally before running the tests, but it
got me thinking if it would even be possible to start it when the test
starts (in a package initializer, perhaps) and shutdown it down when the
tests complete. I haven't found any sort of hooks to enable the
stop-on-shutdown behavior. Did I overlook something?

Are there any other suggestions for ways to write such tests?

--

Search Discussions

  • Kyle Lemons at Dec 20, 2012 at 6:33 pm
    You could write a table-driven test and start it at the beginning of the
    test and defer the shutdown. No, there is no standard "on exit" behavior
    in go test. You could also write a shell script that starts it up, runs go
    test, and then stops it.

    On Thu, Dec 20, 2012 at 1:27 PM, Patrick Higgins wrote:

    I am writing some tests using the "go test" utility which access Redis,
    making them not strict unit tests. I am doing this because there isn't much
    Go code to test: there are Lua functions defined in my Go code which
    execute in Redis, and it's the Lua code I really wish to test, so
    communication with Redis is required.

    Right now I plan to start Redis externally before running the tests, but
    it got me thinking if it would even be possible to start it when the test
    starts (in a package initializer, perhaps) and shutdown it down when the
    tests complete. I haven't found any sort of hooks to enable the
    stop-on-shutdown behavior. Did I overlook something?

    Are there any other suggestions for ways to write such tests?

    --

    --
  • Patrick Higgins at Dec 20, 2012 at 6:52 pm
    Thanks, I think the shell script makes the most sense, so I can start Redis
    once and test several packages against it. It would be nice if I could
    write that sort of code in Go so as not to depend on a shell, but I don't
    have any requirements that make a shell dependency a problem.

    If I run "go test pkg1 pkg2 pkg3", does it compile and execute a separate
    binary for each package? If so, I suppose an external startup would be the
    only way to make separate packages share a single Redis process, anyway.

    On Thu, Dec 20, 2012 at 11:32 AM, Kyle Lemons wrote:

    You could write a table-driven test and start it at the beginning of the
    test and defer the shutdown. No, there is no standard "on exit" behavior
    in go test. You could also write a shell script that starts it up, runs go
    test, and then stops it.


    On Thu, Dec 20, 2012 at 1:27 PM, Patrick Higgins <
    patrick.allen.higgins@gmail.com> wrote:
    I am writing some tests using the "go test" utility which access Redis,
    making them not strict unit tests. I am doing this because there isn't much
    Go code to test: there are Lua functions defined in my Go code which
    execute in Redis, and it's the Lua code I really wish to test, so
    communication with Redis is required.

    Right now I plan to start Redis externally before running the tests, but
    it got me thinking if it would even be possible to start it when the test
    starts (in a package initializer, perhaps) and shutdown it down when the
    tests complete. I haven't found any sort of hooks to enable the
    stop-on-shutdown behavior. Did I overlook something?

    Are there any other suggestions for ways to write such tests?

    --

    --
  • Minux at Dec 20, 2012 at 7:12 pm

    On Fri, Dec 21, 2012 at 2:52 AM, Patrick Higgins wrote:

    If I run "go test pkg1 pkg2 pkg3", does it compile and execute a separate
    binary for each package? If so, I suppose an external startup would be the
    only way to make separate packages share a single Redis process, anyway.
    yes, it will compile and execute separate binaries for each package.
    (you can verify this by watching the output of 'go test -x pkg1 pkg2
    pkg3').

    --
  • Patrick Higgins at Dec 20, 2012 at 7:34 pm

    On Thu, Dec 20, 2012 at 12:12 PM, minux wrote:
    On Fri, Dec 21, 2012 at 2:52 AM, Patrick Higgins <
    patrick.allen.higgins@gmail.com> wrote:
    If I run "go test pkg1 pkg2 pkg3", does it compile and execute a separate
    binary for each package? If so, I suppose an external startup would be the
    only way to make separate packages share a single Redis process, anyway.
    yes, it will compile and execute separate binaries for each package.
    (you can verify this by watching the output of 'go test -x pkg1 pkg2
    pkg3').
    The testing docs at http://golang.org/cmd/go/ imply this behavior
    (particularly the -c flag docs imply the package name is part of the
    binary) but I didn't find anything explicit. Should the docs state this
    explicitly? Perhaps the behavior is intentionally undefined?

    --
  • Minux at Dec 20, 2012 at 7:43 pm

    On Fri, Dec 21, 2012 at 3:34 AM, Patrick Higgins wrote:
    On Thu, Dec 20, 2012 at 12:12 PM, minux wrote:


    On Fri, Dec 21, 2012 at 2:52 AM, Patrick Higgins <
    patrick.allen.higgins@gmail.com> wrote:
    If I run "go test pkg1 pkg2 pkg3", does it compile and execute a
    separate binary for each package? If so, I suppose an external startup
    would be the only way to make separate packages share a single Redis
    process, anyway.
    yes, it will compile and execute separate binaries for each package.
    (you can verify this by watching the output of 'go test -x pkg1 pkg2
    pkg3').
    The testing docs at http://golang.org/cmd/go/ imply this behavior
    (particularly the -c flag docs imply the package name is part of the
    binary) but I didn't find anything explicit. Should the docs state this
    explicitly? Perhaps the behavior is intentionally undefined?
    I'm not sure about this (but IMO, we should document them), I suggest you
    raise an issue about this and see what others say.
    golang.org/issue/new

    --
  • Patrick Higgins at Dec 20, 2012 at 7:53 pm
    I opened issue 4576 for this.

    On Thu, Dec 20, 2012 at 12:43 PM, minux wrote:


    On Fri, Dec 21, 2012 at 3:34 AM, Patrick Higgins <
    patrick.allen.higgins@gmail.com> wrote:
    On Thu, Dec 20, 2012 at 12:12 PM, minux wrote:


    On Fri, Dec 21, 2012 at 2:52 AM, Patrick Higgins <
    patrick.allen.higgins@gmail.com> wrote:
    If I run "go test pkg1 pkg2 pkg3", does it compile and execute a
    separate binary for each package? If so, I suppose an external startup
    would be the only way to make separate packages share a single Redis
    process, anyway.
    yes, it will compile and execute separate binaries for each package.
    (you can verify this by watching the output of 'go test -x pkg1 pkg2
    pkg3').
    The testing docs at http://golang.org/cmd/go/ imply this behavior
    (particularly the -c flag docs imply the package name is part of the
    binary) but I didn't find anything explicit. Should the docs state this
    explicitly? Perhaps the behavior is intentionally undefined?
    I'm not sure about this (but IMO, we should document them), I suggest you
    raise an issue about this and see what others say.
    golang.org/issue/new
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 20, '12 at 6:27p
activeDec 20, '12 at 7:53p
posts7
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase