From d38d224873087e2f06fe8cc39fa39f02a714d627 Mon Sep 17 00:00:00 2001 From: Daniel Berkompas Date: Fri, 3 Nov 2017 13:43:56 -0700 Subject: [PATCH] Fix broken tests --- bin/ci | 8 -------- lib/elasticsearch.ex | 4 ++-- lib/elasticsearch/api/http.ex | 6 +++++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/bin/ci b/bin/ci index 98e84c6..d2efce0 100755 --- a/bin/ci +++ b/bin/ci @@ -5,14 +5,6 @@ # This script contains all the test commands for this app, which will be run # on the continuous integration server. -if [ $CI ]; then - # Setup steps to ensure fast builds on Semaphore CI - export MIX_HOME=$SEMAPHORE_CACHE_DIR - mkdir -p $SEMAPHORE_CACHE_DIR/{_build,deps} - ln -s $SEMAPHORE_CACHE_DIR/deps $SEMAPHORE_PROJECT_DIR/deps - ln -s $SEMAPHORE_CACHE_DIR/_build $SEMAPHORE_PROJECT_DIR/_build -fi - MIX_ENV=test mix compile --warnings-as-errors --force || { echo 'Please fix all compiler warnings.'; exit 1; } MIX_ENV=test mix docs || { echo 'Elixir HTML docs were not generated!'; exit 1; } MIX_ENV=test mix dialyze || { echo 'Dialyzer checks failed.'; exit 1; } diff --git a/lib/elasticsearch.ex b/lib/elasticsearch.ex index 57395b4..c73a8db 100644 --- a/lib/elasticsearch.ex +++ b/lib/elasticsearch.ex @@ -182,8 +182,8 @@ defmodule Elasticsearch do with {:ok, indexes} <- get("/_cat/indices?format=json") do indexes = indexes - |> Stream.map(&(&1["index"])) - |> Stream.filter(&String.starts_with?(&1, prefix)) + |> Enum.map(&(&1["index"])) + |> Enum.filter(&String.starts_with?(&1, prefix)) |> Enum.sort() {:ok, indexes} diff --git a/lib/elasticsearch/api/http.ex b/lib/elasticsearch/api/http.ex index 0990035..b8cb557 100644 --- a/lib/elasticsearch/api/http.ex +++ b/lib/elasticsearch/api/http.ex @@ -38,10 +38,14 @@ defmodule Elasticsearch.API.HTTP do @doc false def process_response_body(body) do - if body =~ "{" do + if json?(body) do Poison.decode!(body) else body end end + + defp json?(str) do + str =~ ~r/^\{/ || str =~ ~r/^\[/ + end end