<commit_before>defmodule OpenAperture.Deployer.Task.Test do
  use   ExUnit.Case

  alias OpenAperture.Deployer
  alias Deployer.DeploymentRepo
  alias Deployer.EtcdCluster
  alias Deployer.GitHub
  alias Deployer.Task.Supervisor

  setup do
    {:ok, sup} = Supervisor.start_link
    details    = %{
      source_commit_hash: "6441611f3ee2a3542b6b46ad7c82904d2cf24786",
      container_repo: "Perceptive-Cloud/cloudos-ui_docker"
    }
    {:ok, supervisor: sup, details: details}
  end

  test "SV spawns a new deployment task", %{supervisor: sup, details: details} do
    assert {:ok, pid} = Supervisor.execute_task(sup, details)
  end

  test "deploy() crashes when no deployment_repo provided" do
    assert_raise RuntimeError, fn -> Deployer.Task.deploy(%{}) end
  end

  test "deploy() failes when the source repo is incorrect" do
    repo    = DeploymentRepo.create!(%{source_repo: "some_repo"})
    details = %{deployment_repo: repo}

    :meck.new(GitHub, [:passthrough])
    :meck.expect(GitHub, :resolve_repo_url, fn(_) -> "http://dummy.url" end)
    :meck.expect(GitHub, :clone, fn(_) -> :ok end)

    assert_raise CaseClauseError, fn -> Deployer.Task.deploy(details) end
  after
    :meck.unload(Github)
  end

  test "deploy() fails when no units are associated with the repo" do
    repo    = DeploymentRepo.create!(%{source_repo: "some_repo"})
    details = %{deployment_repo: repo}

    :meck.new(GitHub, [:passthrough])
    :meck.expect(GitHub, :resolve_repo_url, fn(_) -> "http://dummy.url" end)
    :meck.expect(GitHub, :clone, fn(_) -> :ok end)
    :meck.expect(GitHub, :checkout, fn(_) -> :ok end)

    :meck.new(File, [:passthrough])
    :meck.expect(File, :ls!, fn(_) -> {:one, :two} end)

    assert Deployer.Task.deploy(details) ==
      {:error, "no hosts associated with the repo"}

    after
      :meck.unload(GitHub)
  end

  test "deploy() under normal conditions" do
    repo    = DeploymentRepo.create!(%{source_repo: "some_repo"})
    details = %{deployment_repo: repo}<commit_msg>Fix a typo<commit_after>defmodule OpenAperture.Deployer.Task.Test do
  use   ExUnit.Case

  alias OpenAperture.Deployer
  alias Deployer.DeploymentRepo
  alias Deployer.EtcdCluster
  alias Deployer.GitHub
  alias Deployer.Task.Supervisor

  setup do
    {:ok, sup} = Supervisor.start_link
    details    = %{
      source_commit_hash: "6441611f3ee2a3542b6b46ad7c82904d2cf24786",
      container_repo: "Perceptive-Cloud/cloudos-ui_docker"
    }
    {:ok, supervisor: sup, details: details}
  end

  test "SV spawns a new deployment task", %{supervisor: sup, details: details} do
    assert {:ok, pid} = Supervisor.execute_task(sup, details)
  end

  test "deploy() crashes when no deployment_repo provided" do
    assert_raise RuntimeError, fn -> Deployer.Task.deploy(%{}) end
  end

  test "deploy() failes when the source repo is incorrect" do
    repo    = DeploymentRepo.create!(%{source_repo: "some_repo"})
    details = %{deployment_repo: repo}

    :meck.new(GitHub, [:passthrough])
    :meck.expect(GitHub, :resolve_repo_url, fn(_) -> "http://dummy.url" end)
    :meck.expect(GitHub, :clone, fn(_) -> :ok end)

    assert_raise CaseClauseError, fn -> Deployer.Task.deploy(details) end
  after
    :meck.unload(GitHub)
  end

  test "deploy() fails when no units are associated with the repo" do
    repo    = DeploymentRepo.create!(%{source_repo: "some_repo"})
    details = %{deployment_repo: repo}

    :meck.new(GitHub, [:passthrough])
    :meck.expect(GitHub, :resolve_repo_url, fn(_) -> "http://dummy.url" end)
    :meck.expect(GitHub, :clone, fn(_) -> :ok end)
    :meck.expect(GitHub, :checkout, fn(_) -> :ok end)

    :meck.new(File, [:passthrough])
    :meck.expect(File, :ls!, fn(_) -> {:one, :two} end)

    assert Deployer.Task.deploy(details) ==
      {:error, "no hosts associated with the repo"}

    after
      :meck.unload(GitHub)
  end

  test "deploy() under normal conditions" do
    repo    = DeploymentRepo.create!(%{source_repo: "some_repo"})
    details = %{deployment_repo: repo}
{'fraction_non_alphanumeric': 0.13409485969704496, 'fraction_numerical': 0.013906133598212068, 'mean_word_length': 3.766863905325444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4289556', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1420, 'n_words': 333}