Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding JUnit formatter support #1304

Merged
merged 4 commits into from
Nov 25, 2016

Conversation

jkerry
Copy link
Contributor

@jkerry jkerry commented Nov 20, 2016

resolves #1301 by adding a simple empty shell class extension to the JUnit rspec formatter provided in the rspec_junit_formatter gem. A dependency to the latest version of this gem is also included.

Signed-off-by: jkerry john@kerryhouse.net

…tter and including it in the formatters list with key 'junit'

Signed-off-by: jkerry <john@kerryhouse.net>
@jkerry jkerry changed the title adding a shell extension class of the rspec_junit_formatter gem forma… Adding JUnit formatter support Nov 20, 2016
@chris-rock
Copy link
Contributor

@jkerry Awesome addition. To ensure a higher quality of our code, we require integration/functional tests. Could you add some functional tests? See https://github.com/chef/inspec/blob/master/test/functional/inspec_exec_json_test.rb as an example. Just create a inspec_exec_junit.rb and add the junit specific tests. Please parse the xml output and ensure the expected results are generated.

@jkerry
Copy link
Contributor Author

jkerry commented Nov 20, 2016

Will do. Its going to take me a few to wrap my head around mocking the rspec formatter components

@chris-rock
Copy link
Contributor

You do not need to mock them. Just use the functional tests and parse the xml output as we do with the functional test for json. This allows us to ensure the user facing behavior works all the time.

Something like:

it 'can execute the profile with the json formatter' do
    out = inspec('exec ' + example_profile + ' --format junit --no-create-lockfile')
    out.stderr.must_equal ''
    out.exit_status.must_equal 0
    # parse xml and ensure test-suites are available
  end

@jkerry
Copy link
Contributor Author

jkerry commented Nov 20, 2016

Nifty, thanks for the head start. I'll get the pr ammended tonight

@stevaaa
Copy link

stevaaa commented Nov 21, 2016

thanks @jkerry
Will the code be merged to the base soon?

@jkerry
Copy link
Contributor Author

jkerry commented Nov 21, 2016

Ran into an issue last night that's got me in slow'n'careful mode. The generated XML has a duplicate entry in one of the example runs and I need to make sure that's an intentional edge case

@stevaaa
Copy link

stevaaa commented Nov 21, 2016

Oh cool, thanks again @jkerry

@jkerry
Copy link
Contributor Author

jkerry commented Nov 21, 2016

@stevaaa if you want to test it I'd be appreciative. You can pull the branch down, build the gem, uninstall inspec and install the gem with the --local flag. ( Or I can cut a gem and put it in an web accessible place ). Ive confirmed that I can get Jenkins to load the file on a toy project but haven't tried anything at scale

… xml

Signed-off-by: jkerry <john@kerryhouse.net>
@jkerry
Copy link
Contributor Author

jkerry commented Nov 21, 2016

Pushing changes so I can continue on another rig. Not ready to merge

@stevaaa
Copy link

stevaaa commented Nov 21, 2016

@jkerry Okay, I will test it
I have pulled your branch.. will keep you posted.

btw, what is the flag should i use as the --formatter?

@jkerry
Copy link
Contributor Author

jkerry commented Nov 21, 2016

junit
If you're using test kitchen you can set your kitchen yml like so:
http://kerryhouse.net/chef/2016/11/18/kitchen-inspec-jenkins.html

@stevaaa
Copy link

stevaaa commented Nov 21, 2016

@jkerry I managed to build and use the junit formatter from your branch. It works!
I did checked with bamboo junit parser, It parses the xml as well, I see the xml has "tests="23" failures="17" errors="0"" but the test result in bamboo shows : 24 tests in total 17 tests failed
I had issues with jenkins to instll the junit plugin, will figure out tomorow and try to run over there as well.. thanks

@chris-rock
Copy link
Contributor

Let's also document how to use it. Referencing external tutorials is one great way. Another way would be to add core documentation for Jenkins+Inspec

@jkerry
Copy link
Contributor Author

jkerry commented Nov 21, 2016

I'm happy to write up a tutorial for Jenkins and pr into the docs. I'm concerned though since @stevaaa found a test count discrepancy. Any idea what the gap is yet?

@jkerry
Copy link
Contributor Author

jkerry commented Nov 21, 2016

Maybe it's counting the suite

@jkerry
Copy link
Contributor Author

jkerry commented Nov 22, 2016

verified that the generated xml matches up with the mini-json formatter so I'll finish the tests up and we're good to go

@stevaaa
Copy link

stevaaa commented Nov 22, 2016

@jkerry I found the problem, it was skipping identical tests. Now I changed my suite and now able to get the actual test results in xml and bamboo as well. tx
sorry for the inconvenience :(

@jkerry
Copy link
Contributor Author

jkerry commented Nov 22, 2016

Hey, thanks for the work testing it. I'll have the rest of the tests ready to rock in a few hours.

Signed-off-by: jkerry <john@kerryhouse.net>
@jkerry
Copy link
Contributor Author

jkerry commented Nov 22, 2016

yum install failed. doesn't seem right given the changes here. can you re-trigger the travis build @chris-rock ?

Signed-off-by: jkerry <john@kerryhouse.net>
@jkerry
Copy link
Contributor Author

jkerry commented Nov 22, 2016

nifty, pushed a new commit and the build passed. This is ready to rock @chris-rock @stevaaa

@stevaaa
Copy link

stevaaa commented Nov 23, 2016

thanks @jkerry 👍

@chris-rock
Copy link
Contributor

Awesome work @jkerry This will be included in our next release on Monday. Thank you @stevaaa for additional testing!

@chris-rock chris-rock merged commit ded7d4c into inspec:master Nov 25, 2016
@jkerry
Copy link
Contributor Author

jkerry commented Nov 25, 2016

thanks @chris-rock. I updated the blog post here to walk through the usage. I'll pull down the chef documentation repo soon and add something for the junit format flag.
http://kerryhouse.net/chef/2016/11/18/kitchen-inspec-jenkins.html

@jkerry jkerry deleted the AddJUnitFormatterSupport branch November 25, 2016 19:16
@chris-rock
Copy link
Contributor

chris-rock commented Nov 28, 2016

@jkerry InSpec 1.6.0 is released now

@jkerry
Copy link
Contributor Author

jkerry commented Nov 28, 2016

Post updated to reflect ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support JUnit format
3 participants