Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appends Org to Url Params When Using Flux Query With V1 Connection #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/instream/query/url.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ defmodule Instream.Query.URL do
|> url("api/v2/query")
|> append_param("db", opts[:database] || config[:database])
|> append_param("epoch", encode_precision(opts[:precision]))
|> append_param("org", opts[:org] || config[:org])

{:v1, _} ->
config
Expand Down
75 changes: 75 additions & 0 deletions test/influxdb_v2/connection/query_language_org_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
defmodule Instream.InfluxDBv2.Connection.QueryLanguageOrgTest do
use ExUnit.Case, async: true

@moduletag :"influxdb_include_2.x"

import Mox

alias Instream.TestHelpers.HTTPClientMock

setup :verify_on_exit!

describe "v1 client" do
defmodule MockConnectionV1 do
use Instream.Connection,
config: [
bucket: "default_bucket",
http_client: HTTPClientMock,
loggers: [],
org: "default_org",
version: :v1,
database: "mapped_database"
]
end

test "adds org to query params when using flux" do
expected_url = "http://localhost:8086/api/v2/query?db=mapped_database&org=default_org"

HTTPClientMock
|> expect(:request, fn :post, ^expected_url, _, _, _ -> {:ok, 200, [], ""} end)

MockConnectionV1.query("--ignored--", query_language: :flux)
end

test "doesn't add org to query params when using influxql" do
expected_url = "http://localhost:8086/query?db=mapped_database&q=--ignored--"

HTTPClientMock
|> expect(:request, fn :get, ^expected_url, _, _, _ -> {:ok, 200, [], ""} end)

MockConnectionV1.query("--ignored--", query_language: :influxql)
end
end

describe "v2 client" do
defmodule MockConnectionV2 do
use Instream.Connection,
config: [
bucket: "default_bucket",
http_client: HTTPClientMock,
loggers: [],
org: "default_org",
version: :v2,
database: "mapped_database"
]
end

test "adds org to query params when using flux" do
expected_url = "http://localhost:8086/api/v2/query?org=default_org"

HTTPClientMock
|> expect(:request, fn :post, ^expected_url, _, _, _ -> {:ok, 200, [], ""} end)

MockConnectionV2.query("--ignored--", query_language: :flux)
end

test "doesn't add org to query params when using influxql" do
expected_url = "http://localhost:8086/query?db=mapped_database&q=--ignored--"

HTTPClientMock
|> expect(:request, fn :post, ^expected_url, _, _, _ -> {:ok, 200, [], ""} end)

MockConnectionV2.query("--ignored--", query_language: :influxql)
end
end
end