FAQ
Hi,

I am writing a few API implementations in Go that target various web
services. Most of these require some sort of API key or username + password
authentication.

Is there any easy/preferred way to write tests for these implementations in
Go?

I would like to provide tests that makes the packages testable when proper
authentication is supplied but so far I seem to be stuck at either
hard-coding credentials in the test or prompting for credentials when the
test is run. Hard-coding prevents me from distributing the tests and
prompting ruins the automated (Travis) "push, compile, test"-cycle.

--
Michael Banzon

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Péter Szilágyi at Feb 11, 2014 at 6:10 pm
    Hello,

       How about introducing a command line flag which would define whether to
    run only small tests or the full suite requiring authentication (actually
    you could even do it without the flag by auto detecting the environment)?
    Travis would run only the local tests, and you could manually run the live
    tests whenever you feel like so (or if in the appropriate environment).

       You could mock out most of the remote API and simulate it, being able to
    test almost everything. For live authenticated tests however, imho the only
    solution is a local run, if you want to keep your tokens safe :P

    Cheers,
       Peter

    On Tue, Feb 11, 2014 at 7:48 PM, Michael Banzon wrote:

    Hi,

    I am writing a few API implementations in Go that target various web
    services. Most of these require some sort of API key or username + password
    authentication.

    Is there any easy/preferred way to write tests for these implementations
    in Go?

    I would like to provide tests that makes the packages testable when proper
    authentication is supplied but so far I seem to be stuck at either
    hard-coding credentials in the test or prompting for credentials when the
    test is run. Hard-coding prevents me from distributing the tests and
    prompting ruins the automated (Travis) "push, compile, test"-cycle.

    --
    Michael Banzon

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Michael Banzon at Feb 12, 2014 at 9:09 am
    Thank you for the suggestions.

    I think I've decided to have the tests grab authentication from environment
    if present and only run a small subset if not.

    On Tue, Feb 11, 2014 at 7:10 PM, Péter Szilágyi wrote:

    Hello,

    How about introducing a command line flag which would define whether to
    run only small tests or the full suite requiring authentication (actually
    you could even do it without the flag by auto detecting the environment)?
    Travis would run only the local tests, and you could manually run the live
    tests whenever you feel like so (or if in the appropriate environment).

    You could mock out most of the remote API and simulate it, being able to
    test almost everything. For live authenticated tests however, imho the only
    solution is a local run, if you want to keep your tokens safe :P

    Cheers,
    Peter

    On Tue, Feb 11, 2014 at 7:48 PM, Michael Banzon wrote:

    Hi,

    I am writing a few API implementations in Go that target various web
    services. Most of these require some sort of API key or username + password
    authentication.

    Is there any easy/preferred way to write tests for these implementations
    in Go?

    I would like to provide tests that makes the packages testable when
    proper authentication is supplied but so far I seem to be stuck at either
    hard-coding credentials in the test or prompting for credentials when the
    test is run. Hard-coding prevents me from distributing the tests and
    prompting ruins the automated (Travis) "push, compile, test"-cycle.

    --
    Michael Banzon

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    Michael Banzon
    http://michaelbanzon.com/

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 11, '14 at 5:49p
activeFeb 12, '14 at 9:09a
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase