|
| 1 | +# Copyright (c) HashiCorp, Inc. |
| 2 | +# SPDX-License-Identifier: BUSL-1.1 |
| 3 | + |
| 4 | +require_relative "../../../../../../base" |
| 5 | + |
| 6 | +require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/redhat/ansible_install") |
| 7 | + |
| 8 | +describe VagrantPlugins::Ansible::Cap::Guest::RedHat::AnsibleInstall do |
| 9 | + include_context "unit" |
| 10 | + |
| 11 | + subject { VagrantPlugins::Ansible::Cap::Guest::RedHat::AnsibleInstall } |
| 12 | + |
| 13 | + let(:iso_env) do |
| 14 | + env = isolated_environment |
| 15 | + env.vagrantfile("") |
| 16 | + env.create_vagrant_env |
| 17 | + end |
| 18 | + let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) } |
| 19 | + let(:communicator) { double("comm") } |
| 20 | + let(:dist) { ".el8" } |
| 21 | + let(:epel) { 1 } |
| 22 | + |
| 23 | + before do |
| 24 | + allow(machine).to receive(:communicate).and_return(communicator) |
| 25 | + allow(communicator).to receive(:execute).with("rpm -E %dist").and_yield(:stdout, dist) |
| 26 | + end |
| 27 | + |
| 28 | + describe "#ansible_epel_download_url" do |
| 29 | + it "returns the correct EPEL download URL for RHEL-like versions below 10" do |
| 30 | + expect(subject.ansible_epel_download_url(machine)).to eq("https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm") |
| 31 | + end |
| 32 | + |
| 33 | + context "for RHEL-like versions 10 and above" do |
| 34 | + let(:dist) { ".el10" } |
| 35 | + it "returns the correct EPEL download URL" do |
| 36 | + out = subject.ansible_epel_download_url(machine) |
| 37 | + expect(out).to eq("https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm") |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe "#ansible_rpm_install" do |
| 43 | + before do |
| 44 | + expect(communicator).to receive(:test).with("/usr/bin/which -s dnf").and_return(false) |
| 45 | + expect(communicator).to receive(:execute).with("yum repolist epel | grep -q epel", error_check: false).and_return(epel) |
| 46 | + expect(communicator).to receive(:sudo).with("yum -y --enablerepo=epel install ansible") |
| 47 | + end |
| 48 | + |
| 49 | + it "installs ansible package, when epel is not installed" do |
| 50 | + expect(communicator).to receive(:sudo).with("sudo rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm") |
| 51 | + subject.ansible_rpm_install(machine) |
| 52 | + end |
| 53 | + |
| 54 | + context "when the EPEL repository is already installed" do |
| 55 | + let(:epel) { 0 } |
| 56 | + it "installs ansible package" do |
| 57 | + expect(communicator).to_not receive(:sudo).with("sudo rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm") |
| 58 | + subject.ansible_rpm_install(machine) |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + end |
| 63 | + |
| 64 | +end |
0 commit comments