<commit_before>require 'spec_helper'

describe "cli runtime config", type: :integration do
  with_reset_sandbox_before_each

  it "can upload a runtime config" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, Psych.dump(Bosh::Spec::Deployments.simple_runtime_config))
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}")).to include("Successfully updated runtime config")
    end
  end

  it "gives nice errors for common problems when uploading", no_reset: true do
    bosh_runner.run("target #{current_sandbox.director_url}")

    # not logged in
    expect(bosh_runner.run("update runtime-config some/path", failure_expected: true)).to include("Please log in first")

    bosh_runner.run("login test test")

    # no file
    expect(bosh_runner.run("update runtime-config /some/nonsense/file", failure_expected: true)).to include("Cannot find file `/some/nonsense/file'")

    # file not yaml
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, "---\n}}}i'm not really yaml, hah!")
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}", failure_expected: true)).to include("Incorrect YAML structure")
    end
  end

  it "can download a runtime config" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")

    # none present yet
    expect(bosh_runner.run("runtime-config")).to eq("Acting as user 'test' on 'Test Director'\n")

    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      runtime_config = Psych.dump(Bosh::Spec::Deployments.simple_runtime_config)
      File.write(runtime_config_filename, runtime_config)
      bosh_runner.run("update runtime-config #{runtime_config_filename}")

      expect(bosh_runner.run("runtime-config")).to include(runtime_config)
    end
  end

  it "gives an error when release version is `latest'" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, Psych.dump(Bosh::Spec::Deployments.runtime_config_latest_release))
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}", failure_expected: true)).to include("Error 530001: Runtime " +
        "manifest contains the release `release1' with version as `latest'. Please specify the actual version string.")
    end
  end

  it "gives an error when release for addon does not exist in releases section" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, Psych.dump(Bosh::Spec::Deployments.runtime_config_release_missing))
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}", failure_expected: true)).to include("Error 530002: Runtime " +
        "manifest specifies job `job1' which is defined in `release2', but `release2' is not listed in the releases section.")
    end
  end

end<commit_msg>Fixes integration tests for runtime config<commit_after>require 'spec_helper'

describe "cli runtime config", type: :integration do
  with_reset_sandbox_before_each

  it "can upload a runtime config" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, Psych.dump(Bosh::Spec::Deployments.simple_runtime_config))
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}")).to include("Successfully updated runtime config")
    end
  end

  it "gives nice errors for common problems when uploading", no_reset: true do
    bosh_runner.run("target #{current_sandbox.director_url}")

    # not logged in
    expect(bosh_runner.run("update runtime-config some/path", failure_expected: true)).to include("Please log in first")

    bosh_runner.run("login test test")

    # no file
    expect(bosh_runner.run("update runtime-config /some/nonsense/file", failure_expected: true)).to include("Cannot find file `/some/nonsense/file'")

    # file not yaml
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, "---\n}}}i'm not really yaml, hah!")
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}", failure_expected: true)).to include("Incorrect YAML structure")
    end
  end

  it "can download a runtime config" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")

    # none present yet
    expect(bosh_runner.run("runtime-config")).to eq("Acting as user 'test' on 'Test Director'\n")

    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      runtime_config = Psych.dump(Bosh::Spec::Deployments.simple_runtime_config)
      File.write(runtime_config_filename, runtime_config)
      bosh_runner.run("update runtime-config #{runtime_config_filename}")

      expect(bosh_runner.run("runtime-config")).to include(runtime_config)
    end
  end

  it "gives an error when release version is `latest'" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, Psych.dump(Bosh::Spec::Deployments.runtime_config_latest_release))
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}", failure_expected: true)).to include("Error 530001: Runtime " +
        "manifest contains the release `test_release_2' with version as `latest'. Please specify the actual version string.")
    end
  end

  it "gives an error when release for addon does not exist in releases section" do
    bosh_runner.run("target #{current_sandbox.director_url}")
    bosh_runner.run("login test test")
    Dir.mktmpdir do |tmpdir|
      runtime_config_filename = File.join(tmpdir, 'runtime_config.yml')
      File.write(runtime_config_filename, Psych.dump(Bosh::Spec::Deployments.runtime_config_release_missing))
      expect(bosh_runner.run("update runtime-config #{runtime_config_filename}", failure_expected: true)).to include("Error 530002: Runtime " +
        "manifest specifies job `job_using_pkg_2' which is defined in `release2', but `release2' is not listed in the releases section.")
    end
  end

end
{'fraction_non_alphanumeric': 0.11063464837049743, 'fraction_numerical': 0.004574042309891366, 'mean_word_length': 4.725859247135843, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4430407', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2094, 'n_words': 502}