Skip to content

Feature/deploy target config bug fix #139

Feature/deploy target config bug fix

Feature/deploy target config bug fix #139

GitHub Actions / ansible-test (3.9) results failed Mar 20, 2024 in 0s

20 tests run, 17 passed, 0 skipped, 3 failed.

Annotations

Check failure on line 76 in tests/unit/plugins/action/test_determine_updates_required.py

See this annotation in the file changed.

@github-actions github-actions / ansible-test (3.9) results

tests/unit/plugins/action/test_determine_updates_required.py.test_update_required_cluster

self = <ansible_collections.lagoon.api.tests.unit.plugins.action.test_determine_updates_required.DetermineUpdatesTester testMethod=test_update_required_cluster>

    def test_update_required_cluster(self):
        existing_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': {'id': 1, 'name': 'cluster.io'},
                'id': 1,
                'pullrequests': 'false',
                'weight': 1
            }
        ]
        desired_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': 2,
                'pullrequests': 'false',
                'weight': 1
            }
        ]
    
        addition_required, deletion_required = determine_required_updates(existing_configs, desired_configs)
    
        assert len(addition_required) == 1, "Expected one addition required due to deployTarget change"
        assert addition_required[0]['deployTarget'] == 2, "Expected deployTarget to be updated to 2"
>       assert len(deletion_required) == 0, "Expected no deletions required"
E       AssertionError: Expected no deletions required
E       assert 1 == 0
E        +  where 1 = len([1])

tests/unit/plugins/action/test_determine_updates_required.py:100: AssertionError
Raw output
self = <ansible_collections.lagoon.api.tests.unit.plugins.action.test_determine_updates_required.DetermineUpdatesTester testMethod=test_update_required_cluster>

    def test_update_required_cluster(self):
        existing_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': {'id': 1, 'name': 'cluster.io'},
                'id': 1,
                'pullrequests': 'false',
                'weight': 1
            }
        ]
        desired_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': 2,
                'pullrequests': 'false',
                'weight': 1
            }
        ]
    
        addition_required, deletion_required = determine_required_updates(existing_configs, desired_configs)
    
        assert len(addition_required) == 1, "Expected one addition required due to deployTarget change"
        assert addition_required[0]['deployTarget'] == 2, "Expected deployTarget to be updated to 2"
>       assert len(deletion_required) == 0, "Expected no deletions required"
E       AssertionError: Expected no deletions required
E       assert 1 == 0
E        +  where 1 = len([1])

tests/unit/plugins/action/test_determine_updates_required.py:100: AssertionError

Check failure on line 51 in tests/unit/plugins/action/test_determine_updates_required.py

See this annotation in the file changed.

@github-actions github-actions / ansible-test (3.9) results

tests/unit/plugins/action/test_determine_updates_required.py.test_update_required_weight

self = <ansible_collections.lagoon.api.tests.unit.plugins.action.test_determine_updates_required.DetermineUpdatesTester testMethod=test_update_required_weight>

    def test_update_required_weight(self):
        existing_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': {'id': 1, 'name': 'cluster.io'},
                'id': 1,
                'pullrequests': 'false',
                'weight': 1
            }
        ]
        desired_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': 1,
                'pullrequests': 'false',
                'weight': 2
            }
        ]
    
        addition_required, deletion_required = determine_required_updates(existing_configs, desired_configs)
    
        assert len(addition_required) == 1, "Expected one addition required due to weight change"
        assert addition_required[0]['weight'] == 2, "Expected weight to be updated to 2"
>       assert len(deletion_required) == 0, "Expected no deletions required"
E       AssertionError: Expected no deletions required
E       assert 1 == 0
E        +  where 1 = len([1])

tests/unit/plugins/action/test_determine_updates_required.py:75: AssertionError
Raw output
self = <ansible_collections.lagoon.api.tests.unit.plugins.action.test_determine_updates_required.DetermineUpdatesTester testMethod=test_update_required_weight>

    def test_update_required_weight(self):
        existing_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': {'id': 1, 'name': 'cluster.io'},
                'id': 1,
                'pullrequests': 'false',
                'weight': 1
            }
        ]
        desired_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': 1,
                'pullrequests': 'false',
                'weight': 2
            }
        ]
    
        addition_required, deletion_required = determine_required_updates(existing_configs, desired_configs)
    
        assert len(addition_required) == 1, "Expected one addition required due to weight change"
        assert addition_required[0]['weight'] == 2, "Expected weight to be updated to 2"
>       assert len(deletion_required) == 0, "Expected no deletions required"
E       AssertionError: Expected no deletions required
E       assert 1 == 0
E        +  where 1 = len([1])

tests/unit/plugins/action/test_determine_updates_required.py:75: AssertionError

Check failure on line 10 in tests/unit/plugins/action/test_determine_updates_required.py

See this annotation in the file changed.

@github-actions github-actions / ansible-test (3.9) results

tests/unit/plugins/action/test_determine_updates_required.py.test_update_required

self = <ansible_collections.lagoon.api.tests.unit.plugins.action.test_determine_updates_required.DetermineUpdatesTester testMethod=test_update_required>

    def test_update_required(self):
        existing_configs = []
        desired_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': 1,
                'pullrequests': 'false',
            }
        ]
    
>       addition_required, deletion_required = determine_required_updates(existing_configs, desired_configs)

tests/unit/plugins/action/test_determine_updates_required.py:21: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

existing_configs = []
desired_configs = [{'branches': '^(main)$', 'deployTarget': 1, 'pullrequests': 'false'}]

    def determine_required_updates(existing_configs, desired_configs):
        addition_required = []
        deletion_required = []
    
        # Step 1: Group existing configurations by key attributes
        grouped_configs = {}
        for config in existing_configs:
            key = (config['branches'], config['pullrequests'], str(config['deployTarget']['id']), str(config['weight']))
            if key not in grouped_configs:
                grouped_configs[key] = []
            grouped_configs[key].append(config)
        print("Grouped existing configurations by branches, pullrequests, deployTarget ID, and weight.")
    
        # Step 2: Identify duplicates and mark older ones for deletion
        for key, configs in grouped_configs.items():
            if len(configs) > 1:
                sorted_configs = sorted(configs, key=lambda x: x['id'], reverse=True)
                newest_config = sorted_configs[0]
                for config in sorted_configs[1:]:
                    deletion_required.append(config['id'])
                print(f"Marked older duplicate configurations for deletion based on key {key}, keeping newest configuration with ID {newest_config['id']}.")
                grouped_configs[key] = [newest_config]
    
        # Adjusted logic for handling additions and deletions
        for desired in desired_configs:
>           key = (desired['branches'], desired['pullrequests'], str(desired['deployTarget']), str(desired['weight']))
E           KeyError: 'weight'

plugins/action/deploy_target_config.py:117: KeyError
Raw output
self = <ansible_collections.lagoon.api.tests.unit.plugins.action.test_determine_updates_required.DetermineUpdatesTester testMethod=test_update_required>

    def test_update_required(self):
        existing_configs = []
        desired_configs = [
            {
                'branches': '^(main)$',
                'deployTarget': 1,
                'pullrequests': 'false',
            }
        ]
    
>       addition_required, deletion_required = determine_required_updates(existing_configs, desired_configs)

tests/unit/plugins/action/test_determine_updates_required.py:21: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

existing_configs = []
desired_configs = [{'branches': '^(main)$', 'deployTarget': 1, 'pullrequests': 'false'}]

    def determine_required_updates(existing_configs, desired_configs):
        addition_required = []
        deletion_required = []
    
        # Step 1: Group existing configurations by key attributes
        grouped_configs = {}
        for config in existing_configs:
            key = (config['branches'], config['pullrequests'], str(config['deployTarget']['id']), str(config['weight']))
            if key not in grouped_configs:
                grouped_configs[key] = []
            grouped_configs[key].append(config)
        print("Grouped existing configurations by branches, pullrequests, deployTarget ID, and weight.")
    
        # Step 2: Identify duplicates and mark older ones for deletion
        for key, configs in grouped_configs.items():
            if len(configs) > 1:
                sorted_configs = sorted(configs, key=lambda x: x['id'], reverse=True)
                newest_config = sorted_configs[0]
                for config in sorted_configs[1:]:
                    deletion_required.append(config['id'])
                print(f"Marked older duplicate configurations for deletion based on key {key}, keeping newest configuration with ID {newest_config['id']}.")
                grouped_configs[key] = [newest_config]
    
        # Adjusted logic for handling additions and deletions
        for desired in desired_configs:
>           key = (desired['branches'], desired['pullrequests'], str(desired['deployTarget']), str(desired['weight']))
E           KeyError: 'weight'

plugins/action/deploy_target_config.py:117: KeyError