Skip to content

Commit

Permalink
Update the dummy package helper to support subfolder content
Browse files Browse the repository at this point in the history
  • Loading branch information
brrygrdn committed Jun 26, 2023
1 parent e70583c commit eeab5df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
Dependabot::Job.new_update_job(
job_id: "1558782000",
job_definition: job_definition_with_fetched_files,
repo_contents_path: create_temporary_content_directory(fixture: "bundler_vendored")
repo_contents_path: create_temporary_content_directory(fixture: "bundler_vendored", directory: "bundler/")
)
end

Expand All @@ -305,7 +305,7 @@

let(:dependency_files) do
# Let's use the already up-to-date files
original_bundler_files(fixture: "bundler_vendored")
original_bundler_files(fixture: "bundler_vendored", directory: "bundler/")
end

before do
Expand All @@ -324,32 +324,37 @@
expect(dependency_change.updated_dependency_files_hash.length).to eql(8)

# We've updated the gemfiles properly
gemfile = dependency_change.updated_dependency_files.find { |file| file.path == "/Gemfile" }
gemfile = dependency_change.updated_dependency_files.find do |file|
file.path == "/bundler/Gemfile"
end
expect(gemfile.content).to eql(fixture("bundler_vendored/updated/Gemfile"))
gemfile_lock = dependency_change.updated_dependency_files.find { |file| file.path == "/Gemfile.lock" }

gemfile_lock = dependency_change.updated_dependency_files.find do |file|
file.path == "/bundler/Gemfile.lock"
end
expect(gemfile_lock.content).to eql(fixture("bundler_vendored/updated/Gemfile.lock"))

# We've deleted the old version of dummy-pkg-b
old_dummy_pkg_b = dependency_change.updated_dependency_files.find do |file|
file.path == "/vendor/cache/dummy-pkg-b-1.1.0.gem"
file.path == "/bundler/vendor/cache/dummy-pkg-b-1.1.0.gem"
end
expect(old_dummy_pkg_b.operation).to eql("delete")

# We've created the new version of dummy-pkg-b
new_dummy_pkg_b = dependency_change.updated_dependency_files.find do |file|
file.path == "/vendor/cache/dummy-pkg-b-1.2.0.gem"
file.path == "/bundler/vendor/cache/dummy-pkg-b-1.2.0.gem"
end
expect(new_dummy_pkg_b.operation).to eql("create")

# We've deleted the old version of the vendored git dependency
old_git_dependency_files = dependency_change.updated_dependency_files.select do |file|
file.path.start_with?("/vendor/cache/ruby-dummy-git-dependency-20151f9b67c8")
file.path.start_with?("/bundler/vendor/cache/ruby-dummy-git-dependency-20151f9b67c8")
end
expect(old_git_dependency_files.map(&:operation)).to eql(%w(delete delete))

# We've created the new version of the vendored git dependency
new_git_dependency_files = dependency_change.updated_dependency_files.select do |file|
file.path.start_with?("/vendor/cache/ruby-dummy-git-dependency-c0e25c2eb332")
file.path.start_with?("/bundler/vendor/cache/ruby-dummy-git-dependency-c0e25c2eb332")
end
expect(new_git_dependency_files.map(&:operation)).to eql(%w(create create))
end
Expand Down
16 changes: 8 additions & 8 deletions updater/spec/support/dummy_pkg_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,39 @@ def stub_rubygems_calls
to_return(status: 200, body: fixture("rubygems-versions-b.json"))
end

def original_bundler_files(fixture: "bundler")
def original_bundler_files(fixture: "bundler", directory: "/")
[
Dependabot::DependencyFile.new(
name: "Gemfile",
content: fixture("#{fixture}/original/Gemfile"),
directory: "/"
directory: directory
),
Dependabot::DependencyFile.new(
name: "Gemfile.lock",
content: fixture("#{fixture}/original/Gemfile.lock"),
directory: "/"
directory: directory
)
]
end

def updated_bundler_files(fixture: "bundler")
def updated_bundler_files(fixture: "bundler", directory: "/")
[
Dependabot::DependencyFile.new(
name: "Gemfile",
content: fixture("#{fixture}/updated/Gemfile"),
directory: "/"
directory: directory
),
Dependabot::DependencyFile.new(
name: "Gemfile.lock",
content: fixture("#{fixture}/updated/Gemfile.lock"),
directory: "/"
directory: directory
)
]
end

def create_temporary_content_directory(fixture:, state: "original")
def create_temporary_content_directory(fixture:, directory: "/", state: "original")
tmp_dir = Dir.mktmpdir
FileUtils.cp_r(File.join("spec", "fixtures", fixture, state, "/."), tmp_dir)
FileUtils.cp_r(File.join("spec", "fixtures", fixture, state, "/."), File.join(tmp_dir, directory))

# The content directory needs to a repo
Dir.chdir(tmp_dir) do
Expand Down

0 comments on commit eeab5df

Please sign in to comment.