From c09fdd0d9523657073dd0f71fd7c349dbeae1b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Fri, 28 Oct 2022 15:50:39 +0200 Subject: [PATCH] tests: Adjust tests for new set-env syntax --- main_tests.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/main_tests.py b/main_tests.py index dffe9ec..27e0258 100644 --- a/main_tests.py +++ b/main_tests.py @@ -1,4 +1,6 @@ import asyncio +import os +import tempfile from asyncio import Semaphore from copy import deepcopy from datetime import datetime, timedelta, timezone @@ -37,6 +39,16 @@ mock_http_client.delete.return_value = mock_response +@pytest.fixture(autouse=True) +def github_env(): + """ + Create a GITHUB_ENV env value to mock the Github actions equivalent. + """ + with tempfile.NamedTemporaryFile() as temp: + os.environ['GITHUB_ENV'] = temp.name + yield + + @pytest.mark.asyncio async def test_list_org_package_version(): await list_org_package_versions(org_name='test', image_name=ImageName('test', 'test'), http_client=mock_http_client) @@ -540,7 +552,7 @@ def json(self): @pytest.mark.asyncio -async def test_outputs_are_set(mocker, capsys): +async def test_outputs_are_set(mocker): mock_list_response = Mock() mock_list_response.is_error = True mock_list_response.status_code = 200 @@ -572,11 +584,12 @@ async def test_outputs_are_set(mocker, capsys): 'token': 'test', } ) - captured = capsys.readouterr() - out = captured.out + with open(os.environ['GITHUB_ENV']) as f: + env_vars = f.readlines()[0] + for i in [ - '::set-output name=needs-github-assistance::', - '::set-output name=deleted::', - '::set-output name=failed::', + 'needs-github-assistance=', + 'deleted=', + 'failed=', ]: - assert i in out + assert i in env_vars