Esempio n. 1
0
    def test_http_get_instance_env_exception(self, mock_http_get_metadata):
        """
    Tests http_get_instance_env to see if it raises an exception by mocking the metadata to be invalid

    Args:
      mock_http_get_metadata: MagicMock, returns junk value

    Returns:
      None

    Raises:
      AssertionError if any of the assert checks fail
    """
        mock_http_get_metadata.return_value = "No data"
        with self.assertRaises(Exception) as exception:
            ef_utils.http_get_instance_env()
        self.assertIn("Error looking up metadata:iam/info",
                      str(exception.exception))
Esempio n. 2
0
    def test_http_get_instance_env(self, mock_http_get_metadata):
        """
    Tests http_get_instance_env to see if it returns 'alpha' by mocking the metadata with a valid IAM instance profile

    Args:
      mock_http_get_metadata: MagicMock, returns a valid JSON InstanceProfileArn

    Returns:
      None

    Raises:
      AssertionError if any of the assert checks fail
    """
        mock_http_get_metadata.return_value = "{\"InstanceProfileArn\": \"arn:aws:iam::1234:role/alpha-server\"}"
        env = ef_utils.http_get_instance_env()
        self.assertEquals(env, "alpha")