from unittest import mock

from foremast.plugin_manager import PluginManager

MANAGER = PluginManager('app', 'aws')
PLUGIN = MANAGER.load()


@mock.patch('foremast.app.aws.base.LINKS', new={'example1': 'https://example1.com'})
def test_default_instance_links():
    """Validate default instance_links are being populated properly."""
    pipeline_config = {
        "instance_links": {
            "example2": "https://example2.com",
        }
    }

    combined = {'example1': 'https://example1.com'}
    combined.update(pipeline_config['instance_links'])

    spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
    instance_links = spinnaker_app.retrieve_instance_links()

    assert instance_links == combined, "Instance Links are not being retrieved properly"

from unittest import mock

from foremast.plugin_manager import PluginManager

MANAGER = PluginManager('app', 'aws')
PLUGIN = MANAGER.load()


@mock.patch('foremast.app.aws.base.LINKS', new={'example1': 'https://example1.com'})
def test_default_instance_links():
    """Validate default instance_links are being populated properly."""
    pipeline_config = {
        "instance_links": {
            "example2": "https://example2.com",
        }
    }

    combined = {'example1': 'https://example1.com'}
    combined.update(pipeline_config['instance_links'])

    spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
    instance_links = spinnaker_app.retrieve_instance_links()

    assert instance_links == combined, "Instance Links are not being retrieved properly"


@mock.patch('foremast.app.aws.base.LINKS', new={'example': 'example1', 'example': 'example2'})
def test_duplicate_instance_links():
    """Validate behavior when two keys are identical."""

    pipeline_config = {
        "instance_links": {}
    }

    duplicate = {'example': 'example2'}
    spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
    instance_links = spinnaker_app.retrieve_instance_links()

    assert instance_links == duplicate, "Instance links handing duplicates are wrong."

Check handling duplicate key for instance links
test: Check handling duplicate key for instance links

  from unittest import mock
  
  from foremast.plugin_manager import PluginManager
  
  MANAGER = PluginManager('app', 'aws')
  PLUGIN = MANAGER.load()
  
  
  @mock.patch('foremast.app.aws.base.LINKS', new={'example1': 'https://example1.com'})
  def test_default_instance_links():
      """Validate default instance_links are being populated properly."""
      pipeline_config = {
          "instance_links": {
              "example2": "https://example2.com",
          }
      }
  
      combined = {'example1': 'https://example1.com'}
      combined.update(pipeline_config['instance_links'])
  
      spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
      instance_links = spinnaker_app.retrieve_instance_links()
  
      assert instance_links == combined, "Instance Links are not being retrieved properly"
  
+ 
+ @mock.patch('foremast.app.aws.base.LINKS', new={'example': 'example1', 'example': 'example2'})
+ def test_duplicate_instance_links():
+     """Validate behavior when two keys are identical."""
+ 
+     pipeline_config = {
+         "instance_links": {}
+     }
+ 
+     duplicate = {'example': 'example2'}
+     spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
+     instance_links = spinnaker_app.retrieve_instance_links()
+ 
+     assert instance_links == duplicate, "Instance links handing duplicates are wrong."
+ 
Check handling duplicate key for instance links
## Code Before:
from unittest import mock

from foremast.plugin_manager import PluginManager

MANAGER = PluginManager('app', 'aws')
PLUGIN = MANAGER.load()


@mock.patch('foremast.app.aws.base.LINKS', new={'example1': 'https://example1.com'})
def test_default_instance_links():
    """Validate default instance_links are being populated properly."""
    pipeline_config = {
        "instance_links": {
            "example2": "https://example2.com",
        }
    }

    combined = {'example1': 'https://example1.com'}
    combined.update(pipeline_config['instance_links'])

    spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
    instance_links = spinnaker_app.retrieve_instance_links()

    assert instance_links == combined, "Instance Links are not being retrieved properly"

## Instruction:
Check handling duplicate key for instance links
## Code After:
from unittest import mock

from foremast.plugin_manager import PluginManager

MANAGER = PluginManager('app', 'aws')
PLUGIN = MANAGER.load()


@mock.patch('foremast.app.aws.base.LINKS', new={'example1': 'https://example1.com'})
def test_default_instance_links():
    """Validate default instance_links are being populated properly."""
    pipeline_config = {
        "instance_links": {
            "example2": "https://example2.com",
        }
    }

    combined = {'example1': 'https://example1.com'}
    combined.update(pipeline_config['instance_links'])

    spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
    instance_links = spinnaker_app.retrieve_instance_links()

    assert instance_links == combined, "Instance Links are not being retrieved properly"


@mock.patch('foremast.app.aws.base.LINKS', new={'example': 'example1', 'example': 'example2'})
def test_duplicate_instance_links():
    """Validate behavior when two keys are identical."""

    pipeline_config = {
        "instance_links": {}
    }

    duplicate = {'example': 'example2'}
    spinnaker_app = PLUGIN.SpinnakerApp(pipeline_config=pipeline_config)
    instance_links = spinnaker_app.retrieve_instance_links()

    assert instance_links == duplicate, "Instance links handing duplicates are wrong."
