RexOps / RexOps/Rex

Feature 0.51 breaks custom cmdb paths in a Rex::Test::Base file

Open
#811 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Perl
Stars
737
Forks
214
PR merge metrics
No merged PRs in 30d

Description

For some reason activating the 0.51 feature set overrides or ignores the cmdb that you setup in your Rexfile inside project tests. This is best explained with, well, a test.
Consider the following example project:

$ find test-project/
test-project/
test-project/cmdb
test-project/cmdb/custom.yml


---
foo: mycustom

test-project/cmdb/default.yml


---
foo: mydefault

test-project/Rexfile

use Rex -base;
use Rex::Test;
use Rex::CMDB;

set cmdb => {
  type => "YAML",
  path => [ 'cmdb/custom.yml', 'cmdb/default.yml', ],
  merge_behavior => 'LEFT_PRECEDENT',
};

1;

test-project/t
test-project/t/foo.t

use Rex::Test::Base;
use Rex -base;
use Rex::CMDB;
use Test::More;

test {
  my $t = shift;
  $t->ok( cmdb("foo")->value eq "mycustom", "foo is mycustom" );
  $t->finish();
};

1;

test-project/t/foo-with-0.51-feature.t

use Rex::Test::Base;
use Rex -feature => ['0.51'];
use Rex::CMDB;
use Test::More;

test {
  my $t = shift;
  $t->ok( cmdb("foo")->value eq "mycustom", "foo is mycustom" );
  $t->finish();
};

1;

Here is the output of each test run individually:

$ rex Test:run --test=t/foo.t
[2015-10-25 13:08:10] INFO - Running task Test:run on <local>
[2015-10-25 13:08:10] INFO - Running integration tests...
[2015-10-25 13:08:10] INFO - Running test: t/foo.t.
ok 1 - foo is mycustom
1..1
PASS

$ rex Test:run --test=t/foo-with-0.51-feature.t
[2015-10-25 13:08:33] INFO - Running task Test:run on <local>
[2015-10-25 13:08:33] INFO - Running integration tests...
[2015-10-25 13:08:33] INFO - Running test: t/foo-with-0.51-feature.t.
not ok 1 - foo is mycustom
#   Failed test 'foo is mycustom'
#   at t/foo-with-0.51-feature.t line 8.
1..1
FAIL

What is happening is the 0.51 feature flag does a Rex::Commands::set( cmdb => {...} ) no matter what, even if the user has already setup a custom cmdb in their Rexfile. This works for the Rexfile, because the feature flag code gets run before the rest of your Rexfile. This isn't the case for other files though, like these tests. I think it should only set the cmdb configuration value if it is not already defined. What do you guys think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the mentioned test-project files, especially Rexfile, t/foo.t, and t/foo-with-0.51-feature.t. Start at the 0.51 feature handling and its Rex::Commands::set call, then verify that an existing custom CMDB remains effective by running both example tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
devops, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.