From 13c289eb7e031d81a6df0c3b58bda952369e514a Mon Sep 17 00:00:00 2001 From: Dan Luhring Date: Wed, 23 Dec 2020 08:22:31 -0500 Subject: [PATCH] Add tests for determining site packages root Signed-off-by: Dan Luhring --- .../python/parse_wheel_egg_metadata_test.go | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/syft/cataloger/python/parse_wheel_egg_metadata_test.go b/syft/cataloger/python/parse_wheel_egg_metadata_test.go index 3c04beba2..ac6465198 100644 --- a/syft/cataloger/python/parse_wheel_egg_metadata_test.go +++ b/syft/cataloger/python/parse_wheel_egg_metadata_test.go @@ -56,5 +56,64 @@ func TestParseWheelEggMetadata(t *testing.T) { } }) } - +} + +func TestIsRegularEggFile(t *testing.T) { + cases := []struct { + path string + expected bool + }{ + { + "/usr/lib64/python2.6/site-packages/M2Crypto-0.20.2-py2.6.egg-info", + true, + }, + { + "/usr/lib64/python2.6/site-packages/M2Crypto-0.20.2-py2.6.egg-info/PKG-INFO", + false, + }, + { + "/usr/lib64/python2.6/site-packages/M2Crypto-0.20.2-py2.6.dist-info/METADATA", + false, + }, + } + + for _, c := range cases { + t.Run(c.path, func(t *testing.T) { + actual := isEggRegularFile(c.path) + + if actual != c.expected { + t.Errorf("expected %t but got %t", c.expected, actual) + } + }) + } +} + +func TestDetermineSitePackagesRootPath(t *testing.T) { + cases := []struct { + inputPath string + expected string + }{ + { + inputPath: "/usr/lib64/python2.6/site-packages/ethtool-0.6-py2.6.egg-info", + expected: "/usr/lib64/python2.6/site-packages", + }, + { + inputPath: "/usr/lib/python2.7/dist-packages/configobj-5.0.6.egg-info/top_level.txt", + expected: "/usr/lib/python2.7/dist-packages", + }, + { + inputPath: "/usr/lib/python2.7/dist-packages/six-1.10.0.egg-info/PKG-INFO", + expected: "/usr/lib/python2.7/dist-packages", + }, + } + + for _, c := range cases { + t.Run(c.inputPath, func(t *testing.T) { + actual := determineSitePackagesRootPath(c.inputPath) + + if actual != c.expected { + t.Errorf("expected %s but got %s", c.expected, actual) + } + }) + } }