Skip to content

Commit

Permalink
simple test function
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 11, 2023
1 parent f3b2f39 commit f7e5681
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/testcontainers_elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule TestcontainersElixir do
"""

def hello do
:hello.parse_docker_host(System.get_env("DOCKER_HOST", ""))
|> IO.inspect()
:hello.fetch_hello("world")
end
end
39 changes: 39 additions & 0 deletions src/hello.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
import gleam/hackney
import gleam/http/request
import gleam/uri
import gleam/option.{None, Option, Some, unwrap}

pub fn fetch_hello(name: String) -> String {
let assert Ok(request) =
Expand All @@ -12,3 +15,39 @@ pub fn fetch_hello(name: String) -> String {

response.body
}

pub type DockerHost {
DockerHost(
scheme: String,
socket_host: Option(String),
socket_port: Option(Int),
host: Option(String),
port: Option(Int),
)
}

// a function to parse DOCKER_HOST env var value
// will crash if provided with nil String for docker_host
pub fn parse_docker_host(docker_host: String) -> Option(DockerHost) {
let assert Ok(uri) = uri.parse(docker_host)
let assert scheme = unwrap(uri.scheme, "no scheme")
case scheme {
"tcp" | "http" ->
Some(DockerHost(
scheme: scheme,
socket_host: None,
socket_port: None,
host: uri.host,
port: uri.port,
))
"unix" | "npipe" ->
Some(DockerHost(
scheme: scheme,
socket_host: Some("localhost"),
socket_port: Some(2375),
host: uri.host,
port: uri.port,
))
_ -> None
}
}

0 comments on commit f7e5681

Please sign in to comment.