Skip to content

Commit bbc836b

Browse files
committed
pkg/sca/sca_test.go et al: Implement test for getLdSoConfDLibPaths
This commit implements a simple test to make sure that the new function is properly parsing the configuration file inside /etc/ld.so.conf.d/. A small modification had to be made to the (th *testHandle) RelativeNames() function in order to make TestDocSca pass, because (th *testHandle) FilesystemForRelative() isn't implemented. Signed-off-by: Sergio Durigan Junior <[email protected]>
1 parent 44d1322 commit bbc836b

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

pkg/sca/sca_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//go:generate go run ./../../ build --generate-index=false --out-dir=./testdata/generated ./testdata/ld-so-conf-d-test.yaml --arch=x86_64
1516
//go:generate go run ./../../ build --generate-index=false --out-dir=./testdata/generated ./testdata/shbang-test.yaml --arch=x86_64
1617
//go:generate go run ./../../ build --generate-index=false --source-dir=./testdata/go-fips-bin/ --out-dir=./testdata/generated ./testdata/go-fips-bin/go-fips-bin.yaml --arch=x86_64
1718
//go:generate curl -s -o ./testdata/py3-seaborn.yaml https://raw.githubusercontent.com/wolfi-dev/os/7a39ac1d0603a3561790ea2201dd8ad7c2b7e51e/py3-seaborn.yaml
@@ -56,7 +57,7 @@ func (th *testHandle) Version() string {
5657

5758
func (th *testHandle) RelativeNames() []string {
5859
// TODO: Support subpackages?
59-
return []string{th.pkg.Origin}
60+
return []string{th.pkg.Name}
6061
}
6162

6263
func (th *testHandle) FilesystemForRelative(pkgName string) (SCAFS, error) {
@@ -337,3 +338,20 @@ func TestGetShbang(t *testing.T) {
337338
}
338339
}
339340
}
341+
342+
func TestLdSoConfD(t *testing.T) {
343+
ctx := slogtest.Context(t)
344+
// Generated with `go generate ./...`
345+
th := handleFromApk(ctx, t, "generated/x86_64/ld-so-conf-d-test-1-r1.apk", "ld-so-conf-d-test.yaml")
346+
defer th.exp.Close()
347+
348+
if extraLibPaths, err := getLdSoConfDLibPaths(ctx, th); err != nil {
349+
t.Fatal(err)
350+
} else if extraLibPaths == nil {
351+
t.Error("getLdSoConfDLibPaths: expected 'my/lib/test', got nil")
352+
} else {
353+
if extraLibPaths[0] != "my/lib/test" {
354+
t.Errorf("getLdSoConfDLibPaths: expected 'my/lib/test', got '%s'", extraLibPaths[0])
355+
}
356+
}
357+
}
Binary file not shown.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package:
2+
name: ld-so-conf-d-test
3+
version: 1
4+
epoch: 1
5+
description: ld.so.conf.d test
6+
copyright:
7+
- license: MIT
8+
9+
environment:
10+
contents:
11+
repositories:
12+
- https://packages.wolfi.dev/os
13+
keyring:
14+
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub
15+
packages:
16+
- build-base
17+
- busybox
18+
19+
pipeline:
20+
- runs: |
21+
mkdir -p "${{targets.destdir}}"/etc/ld.so.conf.d
22+
echo "/my/lib/test" > "${{targets.destdir}}"/etc/ld.so.conf.d/ld-so-conf-d-test.conf
23+
24+
update:
25+
enabled: false

0 commit comments

Comments
 (0)