1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
require 'spec_helper'
require 'r10k/environment'
describe R10K::Environment::Git do
subject do
described_class.new(
'myenv',
'/some/nonexistent/environmentdir',
'gitref',
{
:remote => 'https://git-server.site/my-repo.git',
:ref => 'd026ea677116424d2968edb9cee8cbc24d09322b',
}
)
end
describe "initializing" do
subject do
described_class.new('name', '/dir', 'ref', {
:remote => 'url',
:ref => 'value',
:puppetfile_name => 'Puppetfile',
:moduledir => 'modules',
:modules => { },
})
end
it "accepts valid base class initialization arguments" do
expect(subject.name).to eq 'name'
end
end
describe "storing attributes" do
it "can return the environment name" do
expect(subject.name).to eq 'myenv'
end
it "can return the environment basedir" do
expect(subject.basedir).to eq '/some/nonexistent/environmentdir'
end
it "can return the environment dirname" do
expect(subject.dirname).to eq 'gitref'
end
it "can return the environment remote" do
expect(subject.remote).to eq 'https://git-server.site/my-repo.git'
end
it "can return the environment ref" do
expect(subject.ref).to eq 'd026ea677116424d2968edb9cee8cbc24d09322b'
end
end
describe "synchronizing the environment" do
it "syncs the git repository" do
expect(subject.repo).to receive(:sync)
subject.sync
end
end
describe "generating a puppetfile for the environment" do
let(:puppetfile) { subject.puppetfile }
it "creates a puppetfile at the full path to the environment" do
expect(puppetfile.basedir).to eq '/some/nonexistent/environmentdir/gitref'
end
it "sets the moduledir to 'modules' relative to the environment path" do
expect(puppetfile.moduledir).to eq '/some/nonexistent/environmentdir/gitref/modules'
end
it "sets the puppetfile path to 'Puppetfile' relative to the environment path" do
expect(puppetfile.puppetfile_path).to eq '/some/nonexistent/environmentdir/gitref/Puppetfile'
end
end
describe "enumerating modules" do
it "loads the Puppetfile and returns modules in that puppetfile" do
loaded = { desired_contents: [], managed_directories: [], purge_exclusions: [] }
mod = double('A module', :name => 'dbl')
expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [mod]))
expect(subject.modules).to eq([mod])
end
end
describe "determining the status" do
it "delegates to the repo" do
expect(subject.repo).to receive(:status).and_return :some_status
expect(subject.status).to eq :some_status
end
end
describe "environment signature" do
it "returns the git sha of HEAD" do
expect(subject.repo).to receive(:head).and_return 'f00b00'
expect(subject.signature).to eq 'f00b00'
end
end
describe "info hash" do
let(:info_hash) { subject.info }
before(:each) do
allow(subject.repo).to receive(:head).and_return 'f00b00'
end
it "includes name and signature" do
expect(info_hash.keys).to include :name, :signature
expect(info_hash).not_to have_value(nil)
end
end
end
|