Skip to content

Commit 3600d79

Browse files
committed
Fix tests
1 parent 38e4464 commit 3600d79

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

lib/shinkai/config.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ defmodule Shinkai.Config do
3030
doc: "http port"
3131
],
3232
certfile: [
33-
type: :string,
33+
type: {:or, [:string, nil]},
34+
default: nil,
3435
doc: "https certificate"
3536
],
3637
keyfile: [
37-
type: :string,
38+
type: {:or, [:string, nil]},
39+
default: nil,
3840
doc: "https private key certificate"
3941
]
4042
]
@@ -150,20 +152,20 @@ defmodule Shinkai.Config do
150152
parse_and_validate(rest, [{:rtmp, rtmp_config} | acc])
151153
end
152154

153-
defp do_parse_and_validate(config, schame) do
155+
defp do_parse_and_validate(config, schema) do
154156
config = config || []
155157

156158
cond do
157159
Keyword.keyword?(config) ->
158-
NimbleOptions.validate!(config, schame)
160+
NimbleOptions.validate!(config, schema)
159161

160162
is_map(config) ->
161163
config
162164
|> Keyword.new(fn {k, v} -> {String.to_existing_atom(k), v} end)
163-
|> NimbleOptions.validate!(schame)
165+
|> NimbleOptions.validate!(schema)
164166

165167
true ->
166-
raise "Expected a map or keyword list received: #{inspect(config)}"
168+
raise ArgumentError, "Expected a map or keyword list received: #{inspect(config)}"
167169
end
168170
end
169171

test/shinkai/config_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ defmodule Shinkai.ConfigTest do
2020
assert %{
2121
segment_type: :low_latency,
2222
segment_duration: 2000,
23-
part_duration: 500,
23+
part_duration: 300,
2424
max_segments: 10,
2525
storage_dir: "/var/shinkai/hls"
2626
} == Map.new(config[:hls])
2727

2828
assert %{
29-
enabled: false,
29+
enabled: true,
3030
port: 8888,
3131
certfile: nil,
3232
keyfile: nil
@@ -36,13 +36,13 @@ defmodule Shinkai.ConfigTest do
3636
test "raise on invalid values" do
3737
user_config = %{"hls" => %{"segment_type" => "unknown_type"}}
3838

39-
assert_raise ArgumentError, ~r/Invalid HLS configuration/, fn ->
39+
assert_raise NimbleOptions.ValidationError, ~r/invalid value for :segment_type/, fn ->
4040
Config.validate(user_config)
4141
end
4242

4343
user_config = %{"hls" => %{"unknown_key" => 1}}
4444

45-
assert_raise ArgumentError, ~r/Invalid HLS configuration/, fn ->
45+
assert_raise ArgumentError, ~r/not an already existing atom/, fn ->
4646
Config.validate(user_config)
4747
end
4848

@@ -54,7 +54,7 @@ defmodule Shinkai.ConfigTest do
5454

5555
user_config = %{"hls" => "not_a_map"}
5656

57-
assert_raise ArgumentError, ~r/Invalid HLS configuration format/, fn ->
57+
assert_raise ArgumentError, ~r/Expected a map or keyword list received/, fn ->
5858
Config.validate(user_config)
5959
end
6060
end

0 commit comments

Comments
 (0)