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

integration tests for our Dockerfile and ruleset #94

Merged
merged 5 commits into from
Apr 25, 2018

Conversation

phracek
Copy link
Member

@phracek phracek commented Apr 23, 2018

Signed-off-by: Petr "Stone" Hracek phracek@redhat.com

This Pull Request brings a Dockerfile with defined set of labels and two integration tests
for rulesets and labels.

It solves particularly #63 and #56.
If you want some other Dockerfiles, just let me know and I will add it.

@phracek phracek force-pushed the set_images_for_tests branch 6 times, most recently from 118b460 to 18182f7 Compare April 24, 2018 07:48
@phracek phracek requested review from jpopelka, kosciCZ and lachmanfrantisek and removed request for kosciCZ April 24, 2018 08:18
Makefile Outdated
clean:
git clean -dfx

install: clean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install requires clean and clean removes all untracked files, that's pretty bold

Makefile Outdated

build-test-container:
docker build --network host --tag=$(TEST_IMAGE_NAME) -f ./Dockerfile.tests .

build-labels-container:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a detail, but, you don't build container, you build image (or container image), so I'd rename:

  • build-test-container -> build-test-image
  • build-labels-container -> build-labels-image


LABEL maintainer="Petr Hracek <phracek@redhat.com>"

LABEL name="${NAME}" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that some practice to do these in two separate steps ? Or can they be merged into one ?


with open(temp_file_name, 'w') as outfile:
json.dump(colin_json, outfile, ensure_ascii=True)
return temp_file_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand.
So you create temp file, store its name and delete it.
Then open it again, dump a json inside, close and return its name.

Why do you delete and open it again ?
Why the dir='/tmp' - isn't it default?

What about:

tmpfile = tempfile.NamedTemporaryFile(mode='w', delete=False)
json.dump(colin_json, tmpfile, ensure_ascii=True)
tmpfile.close()
return tmpfile.name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to create a random name for later on usage.

import colin

def get_colin_image():
return colin.run("colin-labels", ruleset_name="fedora")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the function name I'd expect it'd get me some image, while it runs checks, doesn't it ?
The same applies to test_ruleset_file.py:get_colin_labels_image()

}


with open(generate_json_file(colin_json), "r") as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty stupid, colin should be able to accept that directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I wait for solving #98 ? WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, leave it as it is, we'll fix it later

@phracek
Copy link
Member Author

phracek commented Apr 24, 2018

I have added also tests for cli, especially Click.

Copy link
Member

@lachmanfrantisek lachmanfrantisek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only some notes for the future and one nit in the Makefile.


Error: Missing argument "target".
"""
assert result.exit_code == 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is the same exit code as on fail. We should change that. (in the code)

Makefile Outdated
build-labels-image:
cd tests/data && docker build --tag=$(TEST_IMAGE_LABELS_NAME) .

test-in-container: build-test-image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also build-test-image has to be added.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean build-labels-image, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes..;-)


def test_list_checks():
result = _call_colin(list_checks)
expected_output = """LABELS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output is something, that can be easily changed a bit in the future, but for now, it's ok.

from colin.cli.colin import check, list_checks, list_rulesets

def _call_colin(fnc):
runner = CliRunner()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot we can test click like this -- we can make more checks like this as a next step. (e.g. version would be good)

@lachmanfrantisek
Copy link
Member

@phracek Is this all for now? I think we can merge that and add more tests later.

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
@lachmanfrantisek lachmanfrantisek merged commit 0204104 into master Apr 25, 2018
@lachmanfrantisek lachmanfrantisek deleted the set_images_for_tests branch April 25, 2018 09:49
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.

4 participants