{
  "tests": [
    {
      "docs": "all fields unset, default endpoint",
      "env": {},
      "fs": {},
      "result": {
        "Ok": "http://169.254.169.254/latest/api/token"
      }
    },
    {
      "docs": "environment variable endpoint override",
      "env": {
        "AWS_EC2_METADATA_SERVICE_ENDPOINT": "http://override:456"
      },
      "fs": {},
      "result": {
        "Ok": "http://override:456/latest/api/token"
      }
    },
    {
      "docs": "profile endpoint override",
      "env": {
        "AWS_CONFIG_FILE": "config"
      },
      "fs": {
        "config": "[default]\nec2_metadata_service_endpoint = http://override:456"
      },
      "result": {
        "Ok": "http://override:456/latest/api/token"
      }
    },
    {
      "docs": "environment overrides profile",
      "env": {
        "AWS_CONFIG_FILE": "config",
        "AWS_EC2_METADATA_SERVICE_ENDPOINT": "http://override:456"
      },
      "fs": {
        "config": "[default]\nec2_metadata_service_endpoint = http://wrong:456"
      },
      "result": {
        "Ok": "http://override:456/latest/api/token"
      }
    },
    {
      "docs": "invalid endpoint mode override",
      "env": {
        "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE": "error"
      },
      "fs": {
      },
      "result": {
        "Err": "`error` is not a valid endpoint mode"
      }
    },
    {
      "docs": "ipv4 endpoint",
      "env": {
        "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE": "IPv4"
      },
      "fs": {
      },
      "result": {
        "Ok": "http://169.254.169.254/latest/api/token"
      }
    },
    {
      "docs": "ipv6 endpoint",
      "env": {
        "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE": "IPv6"
      },
      "fs": {
      },
      "result": {
        "Ok": "http://[fd00:ec2::254]/latest/api/token"
      }
    },
    {
      "docs": "case insensitive endpoint",
      "env": {
        "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE": "ipV6"
      },
      "fs": {
      },
      "result": {
        "Ok": "http://[fd00:ec2::254]/latest/api/token"
      }
    },
    {
      "docs": "ipv6 endpoint from config",
      "env": {
        "AWS_CONFIG_FILE": "config"
      },
      "fs": {
        "config": "[default]\nec2_metadata_service_endpoint_mode = IPv6"
      },
      "result": {
        "Ok": "http://[fd00:ec2::254]/latest/api/token"
      }
    },
    {
      "docs": "invalid config endpoint mode",
      "env": {
        "AWS_CONFIG_FILE": "config"
      },
      "fs": {
        "config": "[default]\nec2_metadata_service_endpoint_mode = IPv7"
      },
      "result": {
        "Err": "`IPv7` is not a valid endpoint mode"
      }
    },
    {
      "docs": "explicit endpoint override",
      "env": {
        "AWS_CONFIG_FILE": "config"
      },
      "fs": {
        "config": "[default]\nec2_metadata_service_endpoint_mode = IPv6"
      },
      "endpoint_override": "https://custom",
      "result": {
        "Ok": "https://custom/latest/api/token"
      }
    },
    {
      "docs": "explicit mode override",
      "env": {
        "AWS_CONFIG_FILE": "config"
      },
      "fs": {
        "config": "[default]\nec2_metadata_service_endpoint_mode = IPv4"
      },
      "mode_override": "IPv6",
      "result": {
        "Ok": "http://[fd00:ec2::254]/latest/api/token"
      }
    },
    {
      "docs": "invalid uri",
      "env": {
        "AWS_EC2_METADATA_SERVICE_ENDPOINT": "not a uri"
      },
      "fs": {},
      "result": {
        "Err": "invalid uri character"
      }
    },
    {
      "docs": "environment variable overrides endpoint mode override",
      "env": {
        "AWS_EC2_METADATA_SERVICE_ENDPOINT": "http://169.254.169.200"
      },
      "fs": {},
      "mode_override": "IPv6",
      "result": {
        "Ok": "http://169.254.169.200/latest/api/token"
      }
    }
  ]
}
