<commit_before>require_relative "test_helper"

describe Plek do
  describe "overriding the uri for a service" do
    before do
      ENV.delete("PLEK_SERVICE_FOO_URI")
    end

    it "looks for an env variable matching the service name and returns its value when present" do
      ENV["PLEK_SERVICE_FOO_URI"] = "http://foo.localhost:5001"
      assert_equal "http://foo.localhost:5001", Plek.new().find("foo")
    end

    it "upcases and underscores the service name in the environment variable" do
      ENV["PLEK_SERVICE_FOO_API_URI"] = "http://foo.localhost:5001"
      assert_equal "http://foo.localhost:5001", Plek.new().find("foo-api")
    end

    it "falls back to regular behaviour when env variable is nil or empty" do
      ENV["GOVUK_APP_DOMAIN"] = "dev.gov.uk"
      ENV["PLEK_SERVICE_FOO_URI"] = nil
      ENV["PLEK_SERVICE_BAR_URI"] = ""

      assert_equal "http://foo.dev.gov.uk", Plek.new().find("foo")
      assert_equal "http://bar.dev.gov.uk", Plek.new().find("bar")
      assert_equal "http://baz.dev.gov.uk", Plek.new().find("baz") # not defined
    end

  end
end
<commit_msg>Reset all the environment variables between tests<commit_after>require_relative "test_helper"

describe Plek do
  describe "overriding the uri for a service" do
    before do
      ENV.delete("PLEK_SERVICE_FOO_URI")
      ENV.delete("PLEK_SERVICE_BAR_URI")
      ENV.delete("GOVUK_APP_DOMAIN")
    end

    it "looks for an env variable matching the service name and returns its value when present" do
      ENV["PLEK_SERVICE_FOO_URI"] = "http://foo.localhost:5001"
      assert_equal "http://foo.localhost:5001", Plek.new().find("foo")
    end

    it "upcases and underscores the service name in the environment variable" do
      ENV["PLEK_SERVICE_FOO_API_URI"] = "http://foo.localhost:5001"
      assert_equal "http://foo.localhost:5001", Plek.new().find("foo-api")
    end

    it "falls back to regular behaviour when env variable is nil or empty" do
      ENV["GOVUK_APP_DOMAIN"] = "dev.gov.uk"
      ENV["PLEK_SERVICE_FOO_URI"] = nil
      ENV["PLEK_SERVICE_BAR_URI"] = ""

      assert_equal "http://foo.dev.gov.uk", Plek.new().find("foo")
      assert_equal "http://bar.dev.gov.uk", Plek.new().find("bar")
      assert_equal "http://baz.dev.gov.uk", Plek.new().find("baz") # not defined
    end

  end
end

{'fraction_non_alphanumeric': 0.13201035375323555, 'fraction_numerical': 0.013805004314063849, 'mean_word_length': 3.485493230174081, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1172729', 'n_tokens_mistral': 827, 'n_tokens_neox': 775, 'n_words': 190}