Skip to content

Commit

Permalink
remove connection_test.exs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyson committed Jan 19, 2025
1 parent a54d32d commit 870e8b8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 96 deletions.
91 changes: 91 additions & 0 deletions test/cluster_test.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
defmodule ClusterTest do
use ExUnit.Case, async: true

alias ExTypesense.TestSchema.Credential
alias OpenApiTypesense.ApiResponse
alias OpenApiTypesense.APIStatsResponse
alias OpenApiTypesense.Connection
alias OpenApiTypesense.HealthStatus
alias OpenApiTypesense.SuccessStatus

@rate_limit :timer.seconds(5)
@forbidden %ApiResponse{
message: "Forbidden - a valid `x-typesense-api-key` header must be sent."
}

setup_all do
conn = Connection.new()
Expand All @@ -15,6 +20,92 @@ defmodule ClusterTest do
%{conn: conn, map_conn: map_conn}
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "error: health check with empty credentials" do
conn = %{api_key: nil, host: nil, port: nil, scheme: nil}

assert_raise FunctionClauseError, fn ->
ExTypesense.health(conn)
end
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "new/1 with invalid data type raises ArgumentError" do
invalid_inputs = [
nil,
"string",
123,
[],
[host: "localhost"]
]

for input <- invalid_inputs do
error =
assert_raise ArgumentError, fn ->
Connection.new(input)
end

assert error.message === "Expected a map for connection options"
end
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "error: health check, with incorrect port number" do
conn = %{api_key: "xyz", host: "localhost", port: 8100, scheme: "http"}

assert {:error, "connection refused"} = ExTypesense.health(conn)
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "error: health check, with incorrect host" do
conn = %{api_key: "xyz", host: "my_test_host", port: 8108, scheme: "http"}

assert {:error, "non-existing domain"} = ExTypesense.health(conn)
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "error: wrong api key was configured" do

Check failure on line 67 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (26.0, 25, 1.14, false)

test error: wrong api key was configured (ClusterTest)

Check failure on line 67 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (27.0, 25, 1.14, false)

test error: wrong api key was configured (ClusterTest)

Check failure on line 67 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (27.1, 25, 1.14, false)

test error: wrong api key was configured (ClusterTest)

Check failure on line 67 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (26.0, 27, 1.18, false)

test error: wrong api key was configured (ClusterTest)

Check failure on line 67 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (27.0, 27, 1.18, false)

test error: wrong api key was configured (ClusterTest)
conn = %{
host: "localhost",
api_key: "another_key",
port: 8108,
scheme: "http"
}

assert {:error, @forbidden} == ExTypesense.list_collections(conn)
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "error: overriding config with a wrong API key" do

Check failure on line 79 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (26.0, 25, 1.14, false)

test error: overriding config with a wrong API key (ClusterTest)

Check failure on line 79 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (27.0, 25, 1.14, false)

test error: overriding config with a wrong API key (ClusterTest)

Check failure on line 79 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (27.1, 25, 1.14, false)

test error: overriding config with a wrong API key (ClusterTest)

Check failure on line 79 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (26.0, 27, 1.18, false)

test error: overriding config with a wrong API key (ClusterTest)

Check failure on line 79 in test/cluster_test.exs

View workflow job for this annotation

GitHub Actions / test (27.0, 27, 1.18, false)

test error: overriding config with a wrong API key (ClusterTest)
conn = %{
host: "localhost",
api_key: "another_key",
port: 8108,
scheme: "http"
}

assert {:error, @forbidden} = ExTypesense.list_collections(conn)
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "success: Using a struct converted to map and update its keys" do
conn = %Credential{
node: "localhost",
secret_key: "xyz",
port: 8108,
scheme: "http"
}

conn =
conn
|> Map.from_struct()
|> Map.drop([:node, :secret_key])
|> Map.put(:host, conn.node)
|> Map.put(:api_key, conn.secret_key)

assert {:ok, %HealthStatus{ok: true}} = ExTypesense.health(conn)
end

@tag ["27.1": true, "27.0": true, "26.0": true]
test "health", %{conn: conn, map_conn: map_conn} do
assert {:ok, %HealthStatus{ok: true}} = ExTypesense.health()
Expand Down
96 changes: 0 additions & 96 deletions test/connection_test.exs

This file was deleted.

0 comments on commit 870e8b8

Please sign in to comment.