<commit_before>require "spec_helper"
require "heroku/command/config"

module Heroku::Command
  describe Config do
    before(:each) do
      stub_core
      api.post_app("name" => "example", "stack" => "cedar")
    end

    after(:each) do
      api.delete_app("example")
    end

    it "shows all configs" do
      api.put_config_vars("example", { 'FOO_BAR' => 'one', 'BAZ_QUX' => 'two' })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
BAZ_QUX: two
FOO_BAR: one
STDOUT
    end

    it "does not trim long values" do
      api.put_config_vars("example", { 'LONG' => 'A' * 60 })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
LONG: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
STDOUT
    end

    it "handles when value is nil" do
      api.put_config_vars("example", { 'FOO_BAR' => 'one', 'BAZ_QUX' => nil })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
BAZ_QUX: 
FOO_BAR: one
STDOUT
    end

    it "handles when value is a boolean" do
      api.put_config_vars("example", { 'FOO_BAR' => 'one', 'BAZ_QUX' => true })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
BAZ_QUX: true
FOO_BAR: one
STDOUT
    end

    it "shows configs in a shell compatible format" do
      api.put_config_vars("example", { 'A' => 'one', 'B' => 'two three' })
      stderr, stdout = execute("config --shell")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
A=one
B=two three
STDOUT
    end

    it "shows a single config for get" do
      api.put_config_vars("example", { 'LONG' => 'A' * 60 })
      stderr, stdout = execute("config:get LONG")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
STDOUT
    end

    context("set") do

      it "sets config vars" do
        stderr, stdout = execute("config:set A=1 B=2")
        expect(stderr).to eq("")
        expect(stdout).to eq <<-STDOUT<commit_msg>Updated tests for #1454<commit_after>require "spec_helper"
require "heroku/command/config"

module Heroku::Command
  describe Config do
    before(:each) do
      stub_core
      api.post_app("name" => "example", "stack" => "cedar")
    end

    after(:each) do
      api.delete_app("example")
    end

    it "shows all configs" do
      api.put_config_vars("example", { 'FOO_BAR' => 'one', 'BAZ_QUX' => 'two' })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
BAZ_QUX: two
FOO_BAR: one
STDOUT
    end

    it "does not trim long values" do
      api.put_config_vars("example", { 'LONG' => 'A' * 60 })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
LONG: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
STDOUT
    end

    it "handles when value is nil" do
      api.put_config_vars("example", { 'FOO_BAR' => 'one', 'BAZ_QUX' => nil })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
BAZ_QUX: 
FOO_BAR: one
STDOUT
    end

    it "handles when value is a boolean" do
      api.put_config_vars("example", { 'FOO_BAR' => 'one', 'BAZ_QUX' => true })
      stderr, stdout = execute("config")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
=== example Config Vars
BAZ_QUX: true
FOO_BAR: one
STDOUT
    end

    it "shows configs in a shell compatible format" do
      api.put_config_vars("example", { 'A' => 'one', 'B' => 'two three', 'C' => "foo&bar" })
      stderr, stdout = execute("config --shell")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
A=one
B=two\\ three
C=foo\\&bar
STDOUT
    end

    it "shows a single config for get" do
      api.put_config_vars("example", { 'LONG' => 'A' * 60 })
      stderr, stdout = execute("config:get LONG")
      expect(stderr).to eq("")
      expect(stdout).to eq <<-STDOUT
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
STDOUT
    end

    context("set") do

      it "sets config vars" do
        stderr, stdout = execute("config:set A=1 B=2")
        expect(stderr).to eq("")
        expect(stdout).to eq <<-STDOUT
{'fraction_non_alphanumeric': 0.14737074679628812, 'fraction_numerical': 0.003535130357931949, 'mean_word_length': 3.1154545454545453, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '4992372', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1490, 'n_words': 409}