vanagon 0.35.1 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ class Vanagon
5
5
  #
6
6
  # @param project [Vanagon::Project] project to build an rpm package of
7
7
  # @return [Array] list of commands required to build an rpm package for the given project from a tarball
8
- def generate_package(project) # rubocop:disable Metrics/AbcSize
8
+ def generate_package(project)
9
9
  target_dir = project.repo ? output_dir(project.repo) : output_dir
10
10
  target_source_output_dir = project.repo ? source_output_dir(project.repo) : source_output_dir
11
11
  if project.source_artifacts
@@ -61,7 +61,7 @@ class Vanagon
61
61
  defines << %(--define 'dist .#{dist}')
62
62
  end
63
63
 
64
- def add_repository(definition) # rubocop:disable Metrics/AbcSize
64
+ def add_repository(definition)
65
65
  definition = URI.parse(definition)
66
66
 
67
67
  commands = ["rpm -q curl > /dev/null || yum -y install curl"]
@@ -5,7 +5,7 @@ class Vanagon
5
5
  #
6
6
  # @param project [Vanagon::Project] project to build a solaris package of
7
7
  # @return [Array] list of commands required to build a solaris package for the given project from a tarball
8
- def generate_package(project) # rubocop:disable Metrics/AbcSize
8
+ def generate_package(project) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
9
9
  target_dir = project.repo ? output_dir(project.repo) : output_dir
10
10
  name_and_version = "#{project.name}-#{project.version}"
11
11
  pkg_name = package_name(project)
@@ -18,9 +18,9 @@ class Vanagon
18
18
  # required more string manipulation anyway. the string should be formatted like so:
19
19
  # && ($$3 ~ /directory\/regex.*/ || $$3 ~ /another\/directory\/regex.*/)
20
20
  # for as many iterations as there are directries in the package
21
- pkgdirs = project.get_root_directories.map { |dir| dir.sub(/^\//, "").gsub(/([\/\.])+/, '\\\\\1') + '.*' }
21
+ pkgdirs = project.get_root_directories.map { |dir| "#{dir.sub(/^\//, '').gsub(/([\/.])+/, '\\\\\1')}.*" }
22
22
  explicit_search_string = pkgdirs.map do |dir_regex|
23
- " $$3 ~ /" + dir_regex + "/ "
23
+ " $$3 ~ /#{dir_regex}/ "
24
24
  end.join("||")
25
25
 
26
26
  # Here we maintain backward compatibility with older vanagon versions
@@ -108,7 +108,7 @@ class Vanagon
108
108
  #
109
109
  # @param user [Vanagon::Common::User] the user to create
110
110
  # @return [String] the commands required to add a user to the system
111
- def add_user(user) # rubocop:disable Metrics/AbcSize
111
+ def add_user(user)
112
112
  # NB: system users aren't supported on solaris 10
113
113
  # Solaris 10 also doesn't support long flags
114
114
  cmd_args = ["'#{user.name}'"]
@@ -108,13 +108,13 @@ class Vanagon
108
108
  dest_pathname_fragment = src_pathname.relative_path_from(vanagon_path)
109
109
  target_dir = File.join(destination, dest_pathname_fragment.to_s)
110
110
  # Create the target directory if necessary.
111
- FileUtils.mkdir_p(target_dir) unless File.exists?(target_dir)
111
+ FileUtils.mkdir_p(target_dir)
112
112
  # Skip the file copy if either target file or ERB equivalent exists.
113
113
  # This means that any files already in place in the work directory as a
114
114
  # result of being copied from the project specific area will not be
115
115
  # overritten.
116
- next if File.exists?(Pathname.new(target_dir) + File.basename(file))
117
- next if File.exists?(Pathname.new(target_dir) + File.basename(file, ".erb"))
116
+ next if File.exist?(Pathname.new(target_dir) + File.basename(file))
117
+ next if File.exist?(Pathname.new(target_dir) + File.basename(file, ".erb"))
118
118
  FileUtils.cp(file, target_dir, :verbose => verbose)
119
119
  end
120
120
  end
@@ -228,7 +228,7 @@ class Vanagon
228
228
  # cygpath conversion is necessary as candle is unable to handle posix path specs
229
229
  # the preprocessor variables AppDataSourcePath and ApplicationSourcePath are required due to the -var input to the heat
230
230
  # runs listed above.
231
- "cd $(tempdir)/wix/wixobj; for wix_file in `find $(tempdir)/wix -name \'*.wxs\'`; do \"$$WIX/bin/candle.exe\" #{candle_flags} #{candle_preprocessor} $$(cygpath -aw $$wix_file) || exit 1; done",
231
+ "cd $(tempdir)/wix/wixobj; for wix_file in `find $(tempdir)/wix -name '*.wxs'`; do \"$$WIX/bin/candle.exe\" #{candle_flags} #{candle_preprocessor} $$(cygpath -aw $$wix_file) || exit 1; done",
232
232
  # run all wix objects through light to produce the msi
233
233
  # the -b flag simply points light to where the SourceDir location is
234
234
  # -loc is required for the UI localization it points to the actual localization .wxl
@@ -317,7 +317,7 @@ class Vanagon
317
317
 
318
318
  if definition.scheme =~ /^(http|ftp|file)/
319
319
  if File.extname(definition.path) == '.ps1'
320
- commands << %(powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'iex ((new-object net.webclient).DownloadString(\"#{definition}\"))')
320
+ commands << %(powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'iex ((new-object net.webclient).DownloadString("#{definition}"))')
321
321
  else
322
322
  commands << %(C:/ProgramData/chocolatey/bin/choco.exe source add -n #{definition.host}-#{definition.path.tr('/', '-')} -s "#{definition}" --debug || echo "Oops, it seems that you don't have chocolatey installed on this system. Please ensure it's there by adding something like 'plat.add_repository 'https://chocolatey.org/install.ps1'' to your platform definition.")
323
323
  end
@@ -438,7 +438,7 @@ class Vanagon
438
438
  #
439
439
  # @param [string] version, the original version number
440
440
  def wix_product_version(version)
441
- version.split("\.").first(3).collect { |value| value.gsub(/[^0-9]/, '') }.join("\.")
441
+ version.split(".").first(3).collect { |value| value.gsub(/[^0-9]/, '') }.join(".")
442
442
  end
443
443
 
444
444
  # Constructor. Sets up some defaults for the windows platform and calls the parent constructor
@@ -150,7 +150,7 @@ class Vanagon
150
150
  # @param config_directory [String] the path to the platform config file
151
151
  # @return [Vanagon::Platform] the platform as specified in the platform config
152
152
  # @raise if the instance_eval on Platform fails, the exception is reraised
153
- def self.load_platform(platform_name, config_directory) # rubocop:disable Metrics/AbcSize
153
+ def self.load_platform(platform_name, config_directory)
154
154
  platform_name = File.basename(platform_name, '.rb')
155
155
  platform_file_name = "#{platform_name}.rb"
156
156
  platform_path = File.join(config_directory, platform_file_name)
@@ -235,7 +235,7 @@ class Vanagon
235
235
  #
236
236
  # @param name [String] name of the platform
237
237
  # @return [Vanagon::Platform] the platform with the given name
238
- def initialize(name) # rubocop:disable Metrics/AbcSize
238
+ def initialize(name) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
239
239
  @name = name
240
240
  @settings = {}
241
241
  @os_name = os_name
@@ -590,7 +590,7 @@ class Vanagon
590
590
  # for the project
591
591
  #
592
592
  # @return [Array] all the files and directories that should be included in the tarball
593
- def get_tarball_files # rubocop:disable Metrics/AbcSize
593
+ def get_tarball_files
594
594
  # It is very important that 'file-list' remains the first element in this
595
595
  # array, lest the tar command be malformed and the package creation fail
596
596
  files = ['file-list']
@@ -779,7 +779,7 @@ class Vanagon
779
779
  # set in the project definition.
780
780
  #
781
781
  # @param [Vanagon::Platform] the platform to publish settings for
782
- def publish_yaml_settings(platform) # rubocop:disable Metrics/AbcSize
782
+ def publish_yaml_settings(platform)
783
783
  return unless yaml_settings
784
784
  raise(Vanagon::Error, "You must specify a project version") unless version
785
785
 
@@ -831,33 +831,61 @@ class Vanagon
831
831
  # @param settings_uri [String] A URI to a yaml settings file
832
832
  # @param settings_sha1_uri [String] A URI to a sha1sum file for the yaml settings file
833
833
  # @raise [Vanagon::Error] when the settings file can't be found
834
- def load_yaml_settings(settings_uri, settings_sha1_uri = nil) # rubocop:disable Metrics/AbcSize
834
+ def load_yaml_settings(settings_uri, settings_sha1_uri = nil)
835
+ source_type = yaml_settings_source_type(settings_uri, settings_sha1_uri)
836
+
837
+ Dir.mktmpdir do |working_directory|
838
+ source = Vanagon::Component::Source.source(
839
+ settings_uri,
840
+ workdir: working_directory,
841
+ sum: settings_sha1_uri,
842
+ sum_type: 'sha1'
843
+ )
844
+ source.fetch
845
+ source.verify
846
+
847
+ yaml_path = if source_type == :http
848
+ File.join(working_directory, source.file)
849
+ else
850
+ source.file
851
+ end
852
+
853
+ @settings.merge!(yaml_safe_load_shim(yaml_path))
854
+ end
855
+ end
856
+
857
+ # Get the source_type of the settings_uri. Complain if we don't like stuff about it.
858
+ def yaml_settings_source_type(settings_uri, settings_sha1_uri)
835
859
  source_type = Vanagon::Component::Source.determine_source_type(settings_uri)
836
860
 
837
861
  if %i[unknown git].include?(source_type)
838
- message = "Can't inherit settings from '#{settings_uri}'. Only http and file URIs are valid."
862
+ message = "Can't inherit settings from '#{settings_uri}'. " \
863
+ "Only http and file URIs are valid."
839
864
  if settings_uri =~ /^file/
840
- message = "Tried to load YAML settings from '#{settings_uri}', but the file doesn't exist."
865
+ message = "Tried to load YAML settings from '#{settings_uri}', " \
866
+ "but the file doesn't exist."
841
867
  end
842
868
  raise Vanagon::Error, message
843
869
  end
844
870
 
845
871
  if (source_type == :http) && !settings_sha1_uri
846
- raise Vanagon::Error, "You must provide a sha1sum URI for the YAML file when inheriting YAML settings over http"
872
+ raise Vanagon::Error, 'The sha1sum URI for the YAML file must be provided ' \
873
+ 'when inheriting YAML settings over http'
847
874
  end
848
875
 
849
- Dir.mktmpdir do |working_directory|
850
- source = Vanagon::Component::Source.source(settings_uri,
851
- workdir: working_directory,
852
- sum: settings_sha1_uri,
853
- sum_type: 'sha1')
854
- source.fetch
855
- source.verify
856
- yaml_path = source.file
857
- if source_type == :http
858
- yaml_path = File.join(working_directory, source.file)
859
- end
860
- @settings.merge!(YAML.safe_load(File.read(yaml_path), [Symbol]))
876
+ source_type
877
+ end
878
+
879
+ # YAML.safe_load introduced an incompatible change in Ruby 3.1.0
880
+ # Shim that until no longer relevant.
881
+ def yaml_safe_load_shim(yaml_path)
882
+ new_safe_load_version = Gem::Version.new('3.1.0')
883
+ this_version = Gem::Version.new(RUBY_VERSION)
884
+
885
+ if this_version >= new_safe_load_version
886
+ YAML.safe_load(File.read(yaml_path), permitted_classes: [Symbol])
887
+ else
888
+ YAML.safe_load(File.read(yaml_path), [Symbol])
861
889
  end
862
890
  end
863
891
 
@@ -77,8 +77,7 @@ class Vanagon
77
77
  end
78
78
  end
79
79
 
80
- response = http.request(request)
81
- response
80
+ http.request(request)
82
81
  rescue Errno::ETIMEDOUT, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
83
82
  EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
84
83
  Net::ProtocolError => e
@@ -159,7 +158,7 @@ class Vanagon
159
158
  # @param timeout [Integer] number of seconds to run the block before timing out
160
159
  # @return [true] If the block succeeds, true is returned
161
160
  # @raise [Vanagon::Error] if the block fails after the retries are exhausted, an error is raised
162
- def retry_with_timeout(tries = 5, timeout = 1, &blk) # rubocop:disable Metrics/AbcSize
161
+ def retry_with_timeout(tries = 5, timeout = 1, &blk)
163
162
  error = nil
164
163
  tries.to_i.times do
165
164
  Timeout::timeout(timeout.to_i) do
@@ -279,7 +278,7 @@ class Vanagon
279
278
  end
280
279
 
281
280
  def clean_environment(&block)
282
- return Bundler.with_clean_env { yield } if defined?(Bundler)
281
+ return Bundler.with_clean_env(&block) if defined?(Bundler)
283
282
  yield
284
283
  end
285
284
  private :clean_environment
data/lib/vanagon.rb CHANGED
@@ -10,7 +10,3 @@ $:.unshift(LIBDIR) unless
10
10
 
11
11
  require 'vanagon/cli'
12
12
  require 'vanagon/driver'
13
-
14
- # The main entry point is {Vanagon::Driver}.
15
- class Vanagon
16
- end
@@ -1,7 +1,6 @@
1
1
  require 'vanagon/component/source/git'
2
2
 
3
3
  describe "Vanagon::Component::Source::Git" do
4
- # before(:all) blocks are run once before all of the examples in a group
5
4
  before :all do
6
5
  @klass = Vanagon::Component::Source::Git
7
6
  # This repo will not be cloned over the network
@@ -12,106 +11,136 @@ describe "Vanagon::Component::Source::Git" do
12
11
  @workdir = nil
13
12
  end
14
13
 
15
- # before(:each) blocks are run before each example
16
- before :each do
17
- allow(Vanagon::Component::Source::Git)
18
- .to receive(:valid_remote?)
19
- .and_return(true)
20
-
21
- allow(File).to receive(:realpath).and_return(@workdir)
22
- end
23
-
24
- describe "#initialize" do
25
- it "raises error on initialization with an invalid repo" do
26
- # Ensure initializing a repo fails without calling over the network
27
- allow(Vanagon::Component::Source::Git)
28
- .to receive(:valid_remote?)
29
- .and_return(false)
30
-
31
- expect { @klass.new(@url, ref: @ref_tag, workdir: @workdir) }
32
- .to raise_error(Vanagon::InvalidRepo)
14
+ context 'with a github https: URI' do
15
+ let(:github_archive_uri) do
16
+ 'https://github.com/2ndQuadrant/pglogical/archive/a_file_name.tar.gz'
33
17
  end
34
-
35
- it "uses the realpath of the workdir if we're in a symlinked dir" do
36
- expect(File).to receive(:realpath).and_return("/tmp/bar")
37
- git_source = @klass.new(@local_url, ref: @ref_tag, workdir: "/tmp/foo")
38
- expect(git_source.workdir)
39
- .to eq('/tmp/bar')
18
+ let(:github_tarball_uri) do
19
+ 'https://github.com/Baeldung/kotlin-tutorials/tarball/main'
40
20
  end
41
-
42
- it "with no clone options should be empty" do
43
- git_source = @klass.new(@local_url, ref: @ref_tag, workdir: "/tmp/foo")
44
- expect(git_source.clone_options)
45
- .to be {}
21
+ let(:github_zipball_uri) do
22
+ 'https://github.com/Baeldung/kotlin-tutorials/zipball/master'
23
+ end
24
+ let(:github_repo_uri) do
25
+ 'https://github.com/cameronmcnz/rock-paper-scissors'
26
+ end
27
+ let(:github_repo_dotgit_uri) do
28
+ 'https://github.com/cameronmcnz/rock-paper-scissors.git'
46
29
  end
47
30
 
48
- it "add clone options depth and branch" do
49
- expected_clone_options = {:branch => "bar", :depth => 50 }
50
- git_source = @klass.new(@local_url, ref: @ref_tag, workdir: "/tmp/foo", :clone_options => expected_clone_options)
51
- expect(git_source.clone_options)
52
- .to be(expected_clone_options)
31
+ it "flags github archive uris as not valid repos" do
32
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_archive_uri)).to be false
53
33
  end
54
- end
55
34
 
56
- describe "#clone" do
57
- before :each do
58
- clone = double(Git::Base)
59
- @file_path = "/tmp/foo"
60
- allow(::Git).to receive(:clone).and_return(clone)
61
- expect(File).to receive(:realpath).and_return(@file_path)
35
+ it "flags github tarball uris as not valid repos" do
36
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_tarball_uri)).to be false
62
37
  end
63
38
 
64
- it "repository" do
65
- git_source = @klass.new(@url, ref: @ref_tag, workdir: "/tmp/foo")
66
- expect(::Git).to receive(:clone).with(git_source.url, git_source.dirname, path: @file_path)
67
- git_source.clone
39
+ it "flags git zipball uris as not valid repos" do
40
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_zipball_uri)).to be false
68
41
  end
69
42
 
70
- it "a particular branch with a depth" do
71
- expected_clone_options = {:branch => "foo", :depth => 50 }
72
- git_source = @klass.new(@url, ref: @ref_tag, workdir: "/tmp/foo", :clone_options => expected_clone_options)
73
- expect(::Git).to receive(:clone).with(git_source.url, git_source.dirname, path: @file_path, **expected_clone_options)
74
- git_source.clone
43
+ it "identifies git generic uris as valid repos" do
44
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_repo_uri)).to be true
75
45
  end
76
46
 
77
- it 'uses a custom dirname' do
78
- git_source = @klass.new(@url, ref: @ref_tag, workdir: "/tmp/foo", dirname: 'facter-ng')
79
- expect(::Git).to receive(:clone).with(git_source.url, 'facter-ng', path: @file_path)
80
- git_source.clone
47
+ it "identifies .git repo uris as valid repos" do
48
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_repo_dotgit_uri)).to be true
81
49
  end
82
50
  end
83
51
 
84
- describe "#dirname" do
85
- it "returns the name of the repo" do
86
- git_source = @klass.new(@local_url, ref: @ref_tag, workdir: @workdir)
87
- expect(git_source.dirname)
88
- .to eq('puppet-agent')
52
+ context 'with other non-github URIs' do
53
+ before :each do
54
+ allow(Vanagon::Component::Source::Git).to receive(:valid_remote?).and_return(true)
55
+ allow(File).to receive(:realpath).and_return(@workdir)
89
56
  end
90
57
 
91
- it "returns the name of the repo and strips .git" do
92
- git_source = @klass.new(@url, ref: @ref_tag, workdir: @workdir)
93
- expect(git_source.dirname)
94
- .to eq('facter')
58
+ describe "#initialize" do
59
+ it "raises error on initialization with an invalid repo" do
60
+ # Ensure initializing a repo fails without calling over the network
61
+ allow(Vanagon::Component::Source::Git).to receive(:valid_remote?).and_return(false)
62
+
63
+ expect { @klass.new(@url, ref: @ref_tag, workdir: @workdir) }
64
+ .to raise_error(Vanagon::InvalidRepo)
65
+ end
66
+
67
+ it "uses the realpath of the workdir if we're in a symlinked dir" do
68
+ expect(File).to receive(:realpath).and_return("/tmp/bar")
69
+ git_source = @klass.new(@local_url, ref: @ref_tag, workdir: "/tmp/foo")
70
+ expect(git_source.workdir).to eq('/tmp/bar')
71
+ end
72
+
73
+ it "with no clone options should be empty" do
74
+ git_source = @klass.new(@local_url, ref: @ref_tag, workdir: "/tmp/foo")
75
+ expect(git_source.clone_options).to be {}
76
+ end
77
+
78
+ it "add clone options depth and branch" do
79
+ expected_clone_options = {branch: 'bar', depth: 50 }
80
+ git_source = @klass.new(@local_url, ref: @ref_tag,
81
+ workdir: "/tmp/foo", clone_options: expected_clone_options)
82
+ expect(git_source.clone_options).to be(expected_clone_options)
83
+ end
95
84
  end
96
85
 
97
- it "returns @dirname if is set" do
98
- git_source = @klass.new(@url, ref: @ref_tag, workdir: @workdir, dirname: 'facter-ng')
99
- expect(git_source.dirname)
100
- .to eq('facter-ng')
86
+ describe "#clone" do
87
+ before :each do
88
+ clone = double(Git::Base)
89
+ @file_path = "/tmp/foo"
90
+ allow(Git).to receive(:clone).and_return(clone)
91
+ expect(File).to receive(:realpath).and_return(@file_path)
92
+ end
93
+
94
+ it "repository" do
95
+ git_source = @klass.new(@url, ref: @ref_tag, workdir: "/tmp/foo")
96
+ expect(Git).to receive(:clone).with(git_source.url, git_source.dirname, path: @file_path)
97
+ git_source.clone
98
+ end
99
+
100
+ it "a particular branch with a depth" do
101
+ expected_clone_options = {:branch => "foo", :depth => 50 }
102
+ git_source = @klass.new(@url, ref: @ref_tag, workdir: "/tmp/foo",
103
+ clone_options: expected_clone_options)
104
+ expect(Git)
105
+ .to receive(:clone)
106
+ .with(git_source.url, git_source.dirname, path: @file_path, **expected_clone_options)
107
+ git_source.clone
108
+ end
109
+
110
+ it 'uses a custom dirname' do
111
+ git_source = @klass.new(@url, ref: @ref_tag, workdir: "/tmp/foo", dirname: 'facter-ng')
112
+ expect(Git).to receive(:clone).with(git_source.url, 'facter-ng', path: @file_path)
113
+ git_source.clone
114
+ end
101
115
  end
102
- end
103
116
 
104
- describe "#ref" do
105
- it "returns a default value of HEAD when no explicit Git reference is provided" do
106
- git_source = @klass.new(@url, workdir: @workdir)
107
- expect(git_source.ref)
108
- .to eq('HEAD')
117
+ describe "#dirname" do
118
+ it "returns the name of the repo" do
119
+ git_source = @klass.new(@local_url, ref: @ref_tag, workdir: @workdir)
120
+ expect(git_source.dirname).to eq('puppet-agent')
121
+ end
122
+
123
+ it "returns the name of the repo and strips .git" do
124
+ git_source = @klass.new(@url, ref: @ref_tag, workdir: @workdir)
125
+ expect(git_source.dirname).to eq('facter')
126
+ end
127
+
128
+ it "returns @dirname if is set" do
129
+ git_source = @klass.new(@url, ref: @ref_tag, workdir: @workdir, dirname: 'facter-ng')
130
+ expect(git_source.dirname).to eq('facter-ng')
131
+ end
109
132
  end
110
133
 
111
- it "returns a default value of HEAD when Git reference is nil" do
112
- git_source = @klass.new(@url, ref: nil, workdir: @workdir)
113
- expect(git_source.ref)
114
- .to eq('HEAD')
134
+ describe "#ref" do
135
+ it "returns a default value of HEAD when no explicit Git reference is provided" do
136
+ git_source = @klass.new(@url, workdir: @workdir)
137
+ expect(git_source.ref).to eq('HEAD')
138
+ end
139
+
140
+ it "returns a default value of HEAD when Git reference is nil" do
141
+ git_source = @klass.new(@url, ref: nil, workdir: @workdir)
142
+ expect(git_source.ref).to eq('HEAD')
143
+ end
115
144
  end
116
145
  end
117
146
  end
@@ -36,7 +36,7 @@ describe "Vanagon::Component::Source" do
36
36
  .to raise_error(URI::InvalidURIError)
37
37
  end
38
38
 
39
- context "takes a Git repo" do
39
+ context "with a Git repo" do
40
40
  before do
41
41
  allow_any_instance_of(Vanagon::Component::Source::Git)
42
42
  .to receive(:valid_remote?)
@@ -64,12 +64,16 @@ describe "Vanagon::Component::Source" do
64
64
 
65
65
  it "returns a Git object for git:http:// repositories" do
66
66
  component_source = klass.source(git_prefixed_http, ref: ref, workdir: workdir)
67
- expect(component_source.url.to_s).to eq 'http://github.com/abcd/things'
68
67
  expect(component_source.class).to eq Vanagon::Component::Source::Git
69
68
  end
69
+
70
+ it "returns a Git url for git:http:// repositories" do
71
+ component_source = klass.source(git_prefixed_http, ref: ref, workdir: workdir)
72
+ expect(component_source.url.to_s).to eq 'http://github.com/abcd/things'
73
+ end
70
74
  end
71
75
 
72
- context "takes a HTTP/HTTPS file" do
76
+ context "with a HTTP/HTTPS file" do
73
77
  before do
74
78
  allow(Vanagon::Component::Source::Http)
75
79
  .to receive(:valid_url?)
@@ -96,7 +100,7 @@ describe "Vanagon::Component::Source" do
96
100
  end
97
101
  end
98
102
 
99
- context "takes a local file" do
103
+ context "with a local file" do
100
104
  before do
101
105
  allow_any_instance_of(Vanagon::Component::Source::Local)
102
106
  .to receive(:valid_file?)
@@ -113,4 +117,74 @@ describe "Vanagon::Component::Source" do
113
117
  end
114
118
  end
115
119
  end
120
+
121
+ describe "#determine_source_type" do
122
+ context 'with a github https: URI' do
123
+
124
+ let(:github_archive_uri) do
125
+ 'https://github.com/2ndQuadrant/pglogical/archive/a_file_name.tar.gz'
126
+ end
127
+ let(:github_tarball_uri) do
128
+ 'https://github.com/Baeldung/kotlin-tutorials/tarball/main'
129
+ end
130
+ let(:github_zipball_uri) do
131
+ 'https://github.com/Baeldung/kotlin-tutorials/zipball/master'
132
+ end
133
+ let(:github_repo_uri) do
134
+ 'https://github.com/cameronmcnz/rock-paper-scissors'
135
+ end
136
+ let(:github_repo_dotgit_uri) do
137
+ 'https://github.com/cameronmcnz/rock-paper-scissors.git'
138
+ end
139
+
140
+ it "identifies github archive uris" do
141
+ stub_request(:head, github_archive_uri).with(
142
+ headers: {
143
+ 'Accept' => '*/*',
144
+ 'Host' => 'github.com',
145
+ 'User-Agent' => 'Ruby'
146
+ }
147
+ ).to_return(status: 200, body: "", headers: {})
148
+
149
+ expect(Vanagon::Component::Source.determine_source_type(github_archive_uri))
150
+ .to eq(:http)
151
+ end
152
+
153
+ it "identifies github tarball uris" do
154
+ stub_request(:head, github_tarball_uri).with(
155
+ headers: {
156
+ 'Accept' => '*/*',
157
+ 'Host' => 'github.com',
158
+ 'User-Agent' => 'Ruby'
159
+ }
160
+ ).to_return(status: 200, body: "", headers: {})
161
+
162
+ expect(Vanagon::Component::Source.determine_source_type(github_tarball_uri))
163
+ .to eq(:http)
164
+ end
165
+
166
+ it "identifies github zipball uris" do
167
+ stub_request(:head, github_zipball_uri).with(
168
+ headers: {
169
+ 'Accept' => '*/*',
170
+ 'Host' => 'github.com',
171
+ 'User-Agent' => 'Ruby'
172
+ }
173
+ ).to_return(status: 200, body: "", headers: {})
174
+
175
+ expect(Vanagon::Component::Source.determine_source_type(github_zipball_uri))
176
+ .to eq(:http)
177
+ end
178
+
179
+ it "identifies github generic repo uris" do
180
+ expect(Vanagon::Component::Source.determine_source_type(github_repo_uri))
181
+ .to eq(:git)
182
+ end
183
+
184
+ it "identifies github .git repo uris" do
185
+ expect(Vanagon::Component::Source.determine_source_type(github_repo_dotgit_uri))
186
+ .to eq(:git)
187
+ end
188
+ end
189
+ end
116
190
  end