Skip to content

Commit d559fd9

Browse files
committed
Add test for generated code with prefix headers
The shortest service definition which uses prefix headers is AWS DataExchange. It is several thousand lines of generated code, so we keep the expected generated output in a file.
1 parent 0cb962d commit d559fd9

3 files changed

Lines changed: 11245 additions & 3 deletions

File tree

test/aws_codegen_test.exs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ defmodule AWS.CodeGenTest do
1414
}
1515
}
1616

17+
@service_spec_custom_headers_file "test/fixtures/apis_specs/dataexchange.json"
18+
@service_spec_custom_headers_generated "test/fixtures/generated/data_exchange.ex"
19+
1720
setup do
1821
service_specs =
1922
@service_spec_file
@@ -24,7 +27,7 @@ defmodule AWS.CodeGenTest do
2427
end
2528

2629
describe "render/2" do
27-
defp setup_context(language, specs, docs \\ nil) do
30+
defp setup_context(language, specs, _docs \\ nil) do
2831
spec = %AWS.CodeGen.Spec{
2932
api: specs,
3033
module_name: "AWS.CloudTrailData",
@@ -37,6 +40,19 @@ defmodule AWS.CodeGenTest do
3740
RestService.load_context(language, spec, @endpoints_spec)
3841
end
3942

43+
defp setup_dataexchange_context(language, specs, _docs \\ nil) do
44+
spec = %AWS.CodeGen.Spec{
45+
api: specs,
46+
module_name: "AWS.DataExchange",
47+
filename: "data_exchange.ex",
48+
protocol: :rest_json,
49+
language: :elixir,
50+
shape_name: "com.amazonaws.dataexchange#DataExchange"
51+
}
52+
53+
RestService.load_context(language, spec, @endpoints_spec)
54+
end
55+
4056
test "renders the Elixir module with docs", %{specs: specs} do
4157
context = setup_context(:elixir, specs)
4258

@@ -238,6 +254,7 @@ defmodule AWS.CodeGenTest do
238254
def put_audit_events(%Client{} = client, input, options \\\\ []) do
239255
url_path = \"/PutAuditEvents\"
240256
headers = []
257+
custom_headers = []
241258
242259
{query_params, input} =
243260
[
@@ -254,7 +271,7 @@ defmodule AWS.CodeGenTest do
254271
:post,
255272
url_path,
256273
query_params,
257-
headers,
274+
custom_headers ++ headers,
258275
input,
259276
options,
260277
200
@@ -717,6 +734,7 @@ defmodule AWS.CodeGenTest do
717734
def put_audit_events(%Client{} = client, input, options \\\\ []) do
718735
url_path = \"/PutAuditEvents\"
719736
headers = []
737+
custom_headers = []
720738
721739
{query_params, input} =
722740
[
@@ -733,7 +751,7 @@ defmodule AWS.CodeGenTest do
733751
:post,
734752
url_path,
735753
query_params,
736-
headers,
754+
custom_headers ++ headers,
737755
input,
738756
options,
739757
200
@@ -742,5 +760,22 @@ defmodule AWS.CodeGenTest do
742760
end
743761
""")
744762
end
763+
764+
test "renders the Elixir module with custom headers" do
765+
specs_file =
766+
@service_spec_custom_headers_file
767+
|> File.read!()
768+
|> Poison.decode!()
769+
770+
context = setup_dataexchange_context(:elixir, specs_file)
771+
772+
result =
773+
context
774+
|> AWS.CodeGen.render("priv/rest.ex.eex")
775+
|> IO.iodata_to_binary()
776+
777+
generated = File.read!(@service_spec_custom_headers_generated)
778+
assert result == generated
779+
end
745780
end
746781
end

0 commit comments

Comments
 (0)