diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 7f3a119..00057c6 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -34,3 +34,28 @@ jobs: file: docker/Dockerfile.test build-contexts: | base_img=docker-image://${{ env.BASE_TAG }} + + test-json: + name: Test JSON Conversion + runs-on: ubuntu-latest + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + + - uses: docker/setup-buildx-action@v2 + with: + driver: docker + + - name: Build Test Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: docker/Dockerfile.test + tags: user/xrootd-cmstfc:test + build-contexts: | + base_img=docker-image://${{ env.BASE_TAG }} + + - name: Unit test + run: | + docker run --rm user/xrootd-cmstfc:test python3 -m pytest -v + diff --git a/tests/test_json.py b/tests/test_json.py new file mode 100644 index 0000000..a2617d3 --- /dev/null +++ b/tests/test_json.py @@ -0,0 +1,23 @@ +import pytest +import subprocess + +json_file = "file:/xrootd/tests/storage.json?volume={}&protocol={}" +test_data =[ + ("/store/temp/test","TEST_JSON","root","/store/test"), + ("/store/temp/test","TEST_JSON","prefix","root://cern-vm//cms/store/temp/test"), + ("/test/mc/file0","CMSSST_TEST","root","root://host.domain/aaa/bbb//test/mc/file0"), + ("/other/mc/file1","CMSSST_TEST","root","root://host.domain/aaa/bbb//store/nomc/file1/trailer"), + ("/other/mc/file2","CMSSST_TEST","root","root://host.domain/aaa/bbb//store/nomc/file2/trailer"), + ("store/mc/file3","CMSSST_TEST","root","root://host.domain/aaa/bbb/never/first/xmc/file3/trailer"), + ("other/mc/file4","CMSSST_TEST","root","root://host.domain/aaa/bbb/other/xmc/file4"), + ("/store/data/file5","CMSSST_TEST","root","root://host.domain/aaa/bbb//store/first/data/file5/trailer") +] + +@pytest.mark.parametrize("lfn,volume,protocol,pfn", test_data) +def test_json(lfn,volume,protocol,pfn): + output = subprocess.check_output([ + "./build/test_json.o", lfn, json_file.format(volume,protocol)],encoding='utf-8') + + assert pfn == output.strip() + +