DocktorAnalyzer/tests/unit-tests/instruction_test.py

37 lines
1.1 KiB
Python
Raw Normal View History

# content of test_sample.py
from pathlib import Path
import re
import pytest
import docktoranalyzer
import docktoranalyzer.dockerfile
from docktoranalyzer.dockerfile.docker_constants import DockerConstants
from docktoranalyzer.dockerfile.dockerfile_parser import DockerFileParser
# TODO: use a glob to take files and rege
@pytest.fixture
def docker_file_arrays():
# I need to count one stage over to account for instructions
# the first FROM
return [
{"path": "./assets/dockerfiles/binary.dockerfile", "stages": 2},
{"path": "./assets/dockerfiles/crypto.dockerfile", "stages": 2},
{"path": "./assets/dockerfiles/web.dockerfile", "stages": 3},
{"path": "./assets/dockerfiles/with-chunks.dockerfile", "stages": 3},
]
# TODO: Make tests for regex
def test_dockerfile_parser(docker_file_arrays):
for docker_file_info in docker_file_arrays:
docker_path = docker_file_info["path"]
actual_stages = docker_file_info["stages"]
docker = DockerFileParser.dockerfile_factory(Path(docker_path))
assert len(docker.stages) == actual_stages