aboutsummaryrefslogtreecommitdiffhomepage
path: root/ldd/exec_test.go
blob: a1e97344d60bd9115a8e1e9961b8e326cf3d9a6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ldd_test

import (
	"errors"
	"os"
	"os/exec"
	"testing"

	"hakurei.app/container"
	"hakurei.app/container/check"
	"hakurei.app/ldd"
	"hakurei.app/message"
)

func TestExec(t *testing.T) {
	t.Parallel()

	t.Run("failure", func(t *testing.T) {
		t.Parallel()

		_, err := ldd.Resolve(t.Context(), nil, check.MustAbs("/proc/nonexistent"))

		var exitError *exec.ExitError
		if !errors.As(err, &exitError) {
			t.Fatalf("Exec: error has incorrect concrete type: %#v", err)
		}

		const want = 1
		if got := exitError.ExitCode(); got != want {
			t.Fatalf("Exec: ExitCode = %d, want %d", got, want)
		}
	})

	t.Run("success", func(t *testing.T) {
		msg := message.New(nil)
		msg.GetLogger().SetPrefix("check: ")
		if entries, err := ldd.Resolve(t.Context(), nil, nil); err != nil {
			t.Fatalf("Exec: error = %v", err)
		} else if testing.Verbose() {
			// result cannot be measured here as build information is not known
			t.Logf("Exec: %q", entries)
		}
	})
}

func TestMain(m *testing.M) { container.TryArgv0(nil); os.Exit(m.Run()) }