FAQ
I have a package that validates the presence of an environment variable in
it's init() function.
I do this in the init function to be absolutely sure the process is
configured correctly on launch time,
if it's not set the init() panics.

Now the problem is, I cannot really test the package since the required
environment flags are not
set when running the suite (and I cannot assume they're always set).

How would you tackle this problem?

--

Search Discussions

  • Kyle Lemons at Dec 11, 2012 at 4:08 am
    You have a few options, roughly in order of preference:

    1) Don't check it in init(), use a sync.Once in the client function(s)
    2) Have init() check a global, unexported variable that you set in your test
    3) Do a dance with a function that's called before init i.e. in a var decl.
    that sets the appropriate state.

    On Mon, Dec 10, 2012 at 8:45 PM, Erik Aigner wrote:

    I have a package that validates the presence of an environment variable in
    it's init() function.
    I do this in the init function to be absolutely sure the process is
    configured correctly on launch time,
    if it's not set the init() panics.

    Now the problem is, I cannot really test the package since the required
    environment flags are not
    set when running the suite (and I cannot assume they're always set).

    How would you tackle this problem?

    --

    --
  • Rémy Oudompheng at Dec 11, 2012 at 7:57 am

    On 2012/12/11 Erik Aigner wrote:
    I have a package that validates the presence of an environment variable in
    it's init() function.
    I do this in the init function to be absolutely sure the process is
    configured correctly on launch time,
    if it's not set the init() panics.
    Why do you need to have such a check?

    Rémy.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 11, '12 at 1:51a
activeDec 11, '12 at 7:57a
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase