diff --git a/CHANGELOG.md b/CHANGELOG.md index 6086879a..4c3c1798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## HEAD + +- Enhancements + - [connection] Adding support to env configurations to tests + - [query] Adding support to empty map or keyword fields in `Query.Builder.where/2` + +- Bug fixes + - [connection] Fixing `Connection.Config.runtime/3` get first key instead of last + ## v0.14.0 (2016-12-18) - Enhancements diff --git a/README.md b/README.md index de76d19c..9b26a26e 100644 --- a/README.md +++ b/README.md @@ -517,6 +517,15 @@ not supported to write them to individual databases. The first point written defines the database, other values are silently ignored! +## Contributing + +##### Custom influxdb test connection + +``` +export INSTREAM_HOST=localhost +export INSTREAM_HTTP_PORT=8086 +``` + ## License [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) diff --git a/config/test.exs b/config/test.exs index c30417b9..11122e0f 100644 --- a/config/test.exs +++ b/config/test.exs @@ -5,81 +5,84 @@ config :logger, :console, format: "\n$time $metadata[$level] $levelpad$message\n", metadata: [:query_time, :response_status] +common_host = [ + database: (System.get_env("INSTREAM_DATABASE") || "instream_test"), + host: System.get_env("INSTREAM_HOST") || "localhost", + port: System.get_env("INSTREAM_HTTP_PORT") || 8086, +] -config :instream, Instream.TestHelpers.Connection, +config :instream, Instream.TestHelpers.Connection, common_host ++ [ auth: [ username: "instream_test", password: "instream_test" ], - host: "localhost", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.LogConnection, +config :instream, Instream.TestHelpers.LogConnection, common_host ++ [ auth: [ username: "instream_test", password: "instream_test" ], - host: "localhost", pool: [ max_overflow: 0, size: 1 ], - port: 8086, scheme: "http" +] - -config :instream, Instream.TestHelpers.EnvConnection, +config :instream, Instream.TestHelpers.EnvConnection, common_host ++ [ auth: [ username: { :system, "INSTREAM_TEST_USERNAME" }, password: { :system, "INSTREAM_TEST_PASSWORD" } ], host: { :system, "INSTREAM_TEST_HOST" }, loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.UDPConnection, +config :instream, Instream.TestHelpers.UDPConnection, common_host ++ [ auth: [ username: "instream_test", password: "instream_test" ], - host: "localhost", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ], port_udp: 8089, writer: Instream.Writer.UDP +] - -config :instream, Instream.TestHelpers.AnonConnection, - host: "localhost", +config :instream, Instream.TestHelpers.AnonConnection, common_host ++ [ loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.GuestConnection, +config :instream, Instream.TestHelpers.GuestConnection, common_host ++ [ auth: [ username: "instream_guest", password: "instream_guest" ], - host: "localhost", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.InvalidConnection, +config :instream, Instream.TestHelpers.InvalidConnection, common_host ++ [ auth: [ username: "instream_test", password: "instream_invalid" ], - host: "localhost", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.InvalidDbConnection, +config :instream, Instream.TestHelpers.InvalidDbConnection, common_host ++ [ auth: [ username: "instream_test", password: "instream_test" ], database: "invalid_test_database", - host: "localhost", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.NotFoundConnection, +config :instream, Instream.TestHelpers.NotFoundConnection, common_host ++ [ auth: [ username: "instream_not_found", password: "instream_not_found" ], - host: "localhost", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.QueryAuthConnection, +config :instream, Instream.TestHelpers.QueryAuthConnection, common_host ++ [ auth: [ method: :query, username: "instream_test", password: "instream_test" ], - host: "localhost", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] -config :instream, Instream.TestHelpers.UnreachableConnection, +config :instream, Instream.TestHelpers.UnreachableConnection, [ host: "some.really.unreachable.host", loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ] +] - -config :instream, Instream.TestHelpers.ConnectionWithOpts, - host: "localhost", +config :instream, Instream.TestHelpers.ConnectionWithOpts, common_host ++ [ loggers: [{ Instream.TestHelpers.NilLogger, :log, [] }], pool: [ max_overflow: 0, size: 1 ], http_opts: [ proxy: "http://invalidproxy" ] +] diff --git a/lib/instream/connection/config.ex b/lib/instream/connection/config.ex index 3be4e658..b3495838 100644 --- a/lib/instream/connection/config.ex +++ b/lib/instream/connection/config.ex @@ -30,6 +30,7 @@ defmodule Instream.Connection.Config do def runtime(otp_app, conn, keys) do otp_app |> Application.get_env(conn, []) + |> Keyword.new |> maybe_fetch_deep(keys) |> maybe_fetch_system() |> maybe_use_default(keys) diff --git a/lib/instream/query/builder.ex b/lib/instream/query/builder.ex index cd16e33d..59629b70 100644 --- a/lib/instream/query/builder.ex +++ b/lib/instream/query/builder.ex @@ -131,6 +131,9 @@ defmodule Instream.Query.Builder do Builds a `WHERE` query expression. """ @spec where(t, map) :: t + def where(query, nil ), do: query + def where(query, [] ), do: query + def where(query, fields) when fields == %{}, do: query def where(query, fields), do: set_argument(query, :where, fields) @doc """ diff --git a/mix.lock b/mix.lock index 4bb940cd..cbd7c9f6 100644 --- a/mix.lock +++ b/mix.lock @@ -4,10 +4,10 @@ "excoveralls": {:hex, :excoveralls, "0.5.7", "5d26e4a7cdf08294217594a1b0643636accc2ad30e984d62f1d166f70629ff50", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]}, "exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]}, "hackney": {:hex, :hackney, "1.6.3", "d489d7ca2d4323e307bedc4bfe684323a7bf773ecfd77938f3ee8074e488e140", [:mix, :rebar3], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]}, - "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [], []}, + "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []}, "jsx": {:hex, :jsx, "2.8.1", "1453b4eb3615acb3e2cd0a105d27e6761e2ed2e501ac0b390f5bbec497669846", [:mix, :rebar3], []}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], []}, - "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], []}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []}, + "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []}, "poison": {:hex, :poison, "3.0.0", "625ebd64d33ae2e65201c2c14d6c85c27cc8b68f2d0dd37828fde9c6920dd131", [:mix], []}, - "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [], []}, + "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}} diff --git a/test/instream/connection/config_test.exs b/test/instream/connection/config_test.exs index c9e94527..821d29fb 100644 --- a/test/instream/connection/config_test.exs +++ b/test/instream/connection/config_test.exs @@ -80,11 +80,13 @@ defmodule Instream.Connection.ConfigTest do test "system configuration connection" do assert nil == EnvConnection.config([ :host ]) - System.put_env("INSTREAM_TEST_HOST", "localhost") + host = System.get_env("INSTREAM_HOST") || "localhost" + + System.put_env("INSTREAM_TEST_HOST", host) System.put_env("INSTREAM_TEST_PASSWORD", "instream_test") System.put_env("INSTREAM_TEST_USERNAME", "instream_test") - assert "localhost" == EnvConnection.config([ :host ]) + assert host == EnvConnection.config([ :host ]) assert :pong == EnvConnection.ping() System.delete_env("INSTREAM_TEST_HOST") diff --git a/test/instream/query/builder_test.exs b/test/instream/query/builder_test.exs index 1c0f2908..15bb5a11 100644 --- a/test/instream/query/builder_test.exs +++ b/test/instream/query/builder_test.exs @@ -84,6 +84,26 @@ defmodule Instream.Query.BuilderTest do assert query_select == "SELECT * FROM some_measurement" end + test "SELECT * using WHERE with empty fields" do + keyword_query = + BuilderSeries + |> Builder.from() + |> Builder.where([]) + |> InfluxQL.encode() + + map_query = + BuilderSeries + |> Builder.from() + |> Builder.where(%{}) + |> InfluxQL.encode() + + should_query = "SELECT * FROM some_measurement" + + assert keyword_query == map_query + assert keyword_query == should_query + assert map_query == should_query + end + test "SELECT * WHERE foo = bar" do fields = %{ binary: "value", numeric: 42 } query =