Skip to content

Commit

Permalink
Fix aws credentials tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 6, 2024
1 parent 2c7dce9 commit 52d886c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 93 deletions.
173 changes: 85 additions & 88 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -332,107 +332,104 @@ defmodule IntegrationTest do
refute response.body.query_execution_id == query_execution_id
end

if Code.ensure_loaded?(:aws_credentials) do
describe "with aws_credentials" do
@path Path.expand("./config/") <> "/"

setup tags do
if env = tags[:aws_credentials] do
for {k, v} <- env do
Application.put_env(:aws_credentials, k, v)
end
end
describe "with aws_credentials" do
@path Path.expand("./config/") <> "/"

if envs = tags[:envs] do
for {k, v} <- envs do
System.put_env(k, v)
on_exit(fn -> System.delete_env(k) end)
end
setup tags do
if env = tags[:aws_credentials] do
for {k, v} <- env do
Application.put_env(:aws_credentials, k, v)
end

on_exit(fn -> Application.stop(:aws_credentials) end)

:ok
end

@tag capture_log: true,
aws_credentials: [
fail_if_unavailable: false,
credential_providers: [:aws_credentials_env]
]
test "get's from system env and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]

req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)

assert response.status == 200
if envs = tags[:envs] do
for {k, v} <- envs do
System.put_env(k, v)
on_exit(fn -> System.delete_env(k) end)
end
end

@tag capture_log: true,
envs: %{
"AWS_CONFIG_FILE" => @path <> "config",
"AWS_SHARED_CREDENTIALS_FILE" => @path <> "credentials"
},
aws_credentials: [
fail_if_unavailable: false,
credential_providers: [:aws_credentials_file],
provider_options: %{credential_path: to_charlist(Path.expand("./"))}
]
test "get's from the files from env and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]

req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)
on_exit(fn ->
Application.stop(:aws_credentials)
Application.start(:aws_credentials)
end)

assert response.status == 200
end
:ok
end

@tag capture_log: true,
envs: %{
"AWS_CONFIG_FILE" => @path <> "config",
"AWS_SHARED_CREDENTIALS_FILE" => @path <> "credentials_with_token"
},
aws_credentials: [
fail_if_unavailable: false,
credential_providers: [:aws_credentials_file],
provider_options: %{credential_path: to_charlist(Path.expand("./"))}
]
test "get's from the files from env with session token and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]
@tag capture_log: true,
aws_credentials: [
credential_providers: [:aws_credentials_env]
]
test "gets from system env and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]

req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)
req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)

assert response.status == 200
end
assert response.status == 200
end

@tag capture_log: true,
aws_credentials: [
fail_if_unavailable: false,
credential_providers: [:aws_credentials_file],
provider_options: %{credential_path: to_charlist(@path)}
]
test "get's from file system and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]
@tag capture_log: true,
envs: %{
"AWS_CONFIG_FILE" => @path <> "config",
"AWS_SHARED_CREDENTIALS_FILE" => @path <> "credentials"
},
aws_credentials: [
credential_providers: [:aws_credentials_file],
provider_options: %{credential_path: to_charlist(Path.expand("./"))}
]
test "gets from the files from env and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]

req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)

assert response.status == 200
end

req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)
@tag capture_log: true,
envs: %{
"AWS_CONFIG_FILE" => @path <> "config",
"AWS_SHARED_CREDENTIALS_FILE" => @path <> "credentials_with_token"
},
aws_credentials: [
credential_providers: [:aws_credentials_file],
provider_options: %{credential_path: to_charlist(Path.expand("./"))}
]
test "gets from the files from env with session token and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]

req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)

assert response.status == 200
end

assert response.status == 200
end
@tag capture_log: true,
aws_credentials: [
credential_providers: [:aws_credentials_file],
provider_options: %{credential_path: to_charlist(@path)}
]
test "gets from file system and create table" do
opts = [
database: "default",
output_location: System.fetch_env!("AWS_ATHENA_OUTPUT_LOCATION")
]

req = Req.new(http_errors: :raise) |> ReqAthena.attach(opts)
response = Req.post!(req, athena: @create_table)

assert response.status == 200
end
end
end
5 changes: 0 additions & 5 deletions test/req_athena_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ defmodule ReqAthenaTest do
use ExUnit.Case, async: true
@moduletag :capture_log

setup do
Application.put_env(:aws_credentials, :credential_providers, [])
:ok
end

test "executes a query string" do

Check failure on line 5 in test/req_athena_test.exs

View workflow job for this annotation

GitHub Actions / test (25.0, 1.14.2)

test executes a query string (ReqAthenaTest)
opts = [
access_key_id: "some key",
Expand Down

0 comments on commit 52d886c

Please sign in to comment.