Skip to content

Commit

Permalink
Add test case for routing merging
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Dec 23, 2024
1 parent 4abc270 commit c3861d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions lib/uplink/clients/caddy/config/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ defmodule Uplink.Clients.Caddy.Config.Builder do
end

main_paths =
if main_routing do
if main_routing && main_routing.paths != [] do
main_routing.paths
else
["*"]
Expand Down Expand Up @@ -198,6 +198,7 @@ defmodule Uplink.Clients.Caddy.Config.Builder do
metadata.hosts
|> Enum.concat(main_routing_hosts)
|> Enum.uniq()
|> Enum.sort()

main_route = %{
group: main_group,
Expand Down Expand Up @@ -258,9 +259,10 @@ defmodule Uplink.Clients.Caddy.Config.Builder do
hosts
|> Enum.concat(routing_hosts)
|> Enum.uniq()
|> Enum.sort()

paths =
if routing do
if routing && routing.paths != [] do
routing.paths
else
["*"]
Expand Down
8 changes: 7 additions & 1 deletion test/scenarios/deployment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ defmodule Uplink.Scenarios.Deployment do
"target" => 4000,
"routing" => %{
"router_id" => 1,
"hosts" => ["another.com", "something.com"],
"paths" => ["/configure*"]
}
},
"ports" => [
%{
"slug" => "grpc",
"source" => 49153,
"target" => 6000
"target" => 6000,
"routing" => %{
"router_id" => 1,
"hosts" => ["another.com", "something.com"],
"paths" => ["/*"]
}
}
],
"hosts" => ["something.com"],
Expand Down
24 changes: 15 additions & 9 deletions test/uplink/clients/caddy/config/builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,38 @@ defmodule Uplink.Clients.Caddy.Config.BuilderTest do
"provider" => %{"api_token" => "something", "name" => "cloudflare"}
} = dns

assert %{routes: [first_route, second_route, third_route]} = server
assert %{routes: routes} = server

routes = Enum.sort(routes)

[first_route, second_route, third_route] = routes

assert %{handle: [handle], match: [match]} = first_route
assert %{handle: [second_handle], match: [second_match]} = second_route
assert %{handle: [third_handle], match: [third_match]} = third_route

assert match.host == ["another.com", "something.com"]
assert match.path == ["/configure*"]

assert third_match.path == ["*"]
assert second_match.path == ["/*"]

assert second_match.path == ["/how-to*"]
assert third_match.path == ["/how-to*"]

assert "grpc.something.com" in third_match.host
assert "grpc.something.com" in second_match.host
assert "grpc.another.com" in second_match.host

[third_upstream] = third_handle.upstreams
[second_upstream] = second_handle.upstreams

assert third_upstream.dial =~ "6000"
assert second_upstream.dial =~ "6000"

assert %{handler: "reverse_proxy"} = handle
assert %{host: _hosts} = match

[second_upstream] = second_handle.upstreams
[third_upstream] = third_handle.upstreams

assert %{protocol: "http", tls: %{}} = second_handle.transport
assert %{protocol: "http", tls: %{}} = third_handle.transport

assert second_upstream.dial == "proxy.webflow.com:80"
assert third_upstream.dial == "proxy.webflow.com:80"

assert %{identity: identity} = admin
assert %{identifiers: ["127.0.0.1"]} = identity
Expand Down

0 comments on commit c3861d1

Please sign in to comment.