Skip to content

Commit

Permalink
add unit tests for dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Marlon Pina Tojal <[email protected]>
  • Loading branch information
Marlon Pina Tojal committed Dec 9, 2023
1 parent 52ccf2c commit 2706034
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion spec/cyclonedx/cocoapods/podfile_analyzer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

require 'cyclonedx/cocoapods/podfile_analyzer'
require 'rspec'

RSpec.describe CycloneDX::CocoaPods::PodfileAnalyzer do
let(:fixtures) { Pathname.new(File.expand_path('../../../fixtures/', __FILE__)) }
let(:empty_podfile) { 'EmptyPodfile/Podfile' }
Expand Down Expand Up @@ -125,4 +124,59 @@
end
end
end
context 'parsing dependencies' do
context 'when created with standard parameters' do
it 'should handle no dependencies correctly' do
analyzer = ::CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

pod_file = ::Pod::Podfile.from_file(fixtures + empty_podfile)
expect(pod_file).not_to be_nil
lock_file = ::Pod::Lockfile.from_file(fixtures + (empty_podfile + '.lock'))
expect(lock_file).not_to be_nil

dependencies = analyzer.dependencies_hash_of_lockfile_pods(pod_file, lock_file)

expect(dependencies).to eq({})
end

it 'should find all dependencies correctly (simple_pod)' do
analyzer = ::CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

pod_file = ::Pod::Podfile.from_file(fixtures + simple_pod)
expect(pod_file).not_to be_nil
lock_file = ::Pod::Lockfile.from_file(fixtures + (simple_pod + '.lock'))
expect(lock_file).not_to be_nil

dependencies = analyzer.dependencies_hash_of_lockfile_pods(pod_file, lock_file)

expect(dependencies).to eq({" pkg:cocoapods/[email protected]" => [], "pkg:cocoapods/[email protected]" => [ "pkg:cocoapods/[email protected]#app-lib" ], "pkg:cocoapods/[email protected]#app-lib" => [] })
end

it 'should find all dependencies correctly (restricted_pod)' do
analyzer = ::CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

pod_file = ::Pod::Podfile.from_file(fixtures + restricted_pod)
expect(pod_file).not_to be_nil
lock_file = ::Pod::Lockfile.from_file(fixtures + (restricted_pod + '.lock'))
expect(lock_file).not_to be_nil

dependencies = analyzer.dependencies_hash_of_lockfile_pods(pod_file, lock_file)

expect(dependencies).to eq({ "pkg:cocoapods/[email protected]" => [ "pkg:cocoapods/swift_qrcodejs@" ] })
end

it 'should find all dependencies correctly (tests_pod)' do
analyzer = ::CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

pod_file = ::Pod::Podfile.from_file(fixtures + tests_pod)
expect(pod_file).not_to be_nil
lock_file = ::Pod::Lockfile.from_file(fixtures + (tests_pod + '.lock'))
expect(lock_file).not_to be_nil

dependencies = analyzer.dependencies_hash_of_lockfile_pods(pod_file, lock_file)

expect(dependencies).to eq({ "pkg:cocoapods/[email protected]" => [] , "pkg:cocoapods/[email protected]" => ["pkg:cocoapods/[email protected]#app-lib"] , "pkg:cocoapods/[email protected]#app-lib" => [] })
end
end
end
end

0 comments on commit 2706034

Please sign in to comment.