File: binfmt_test.go

package info (click to toggle)
adequate 0.17.6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: python: 254; makefile: 111; sh: 75; ansic: 29
file content (95 lines) | stat: -rw-r--r-- 2,347 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main

import (
	"strings"
	"testing"
)

func TestBinfmtFormats(t *testing.T) {
	fakeRunner := func([]string) ([]string, error) {
		return strings.Split(`cli (enabled):
     package = mono-runtime
        type = magic
      offset = 0
       magic = MZ
        mask = 
 interpreter = /usr/bin/cli
    detector = /usr/lib/cli/binfmt-detector-cli
jar (enabled):
     package = openjdk-11
        type = magic
      offset = 0
       magic = PK\x03\x04
        mask = 
 interpreter = /usr/bin/jexec
    detector = 
llvm-16-runtime.binfmt (enabled):
     package = llvm-16-runtime
        type = magic
      offset = 0
       magic = BC
        mask = 
 interpreter = /usr/bin/lli-16
    detector = 
llvm-17-runtime.binfmt (enabled):
     package = llvm-17-runtime
        type = magic
      offset = 0
       magic = BC
        mask = 
 interpreter = /usr/bin/lli-17
    detector = 
love (enabled):
     package = love
        type = extension
      offset = 0
       magic = love
        mask = 
 interpreter = /usr/bin/love
    detector = 
python3.12 (enabled):
     package = python3.12
        type = magic
      offset = 0
       magic = \xcb\x0d\x0d\x0a
        mask = 
 interpreter = /usr/bin/python3.12
    detector = 
wine (enabled):
     package = wine
        type = magic
      offset = 0
       magic = MZ
        mask = 
 interpreter = /usr/bin/wine
    detector = 
`, "\n"), nil
	}

	cc := binfmtChecker{
		displayBinfmts: fakeRunner,
	}

	got := cc.binfmtFormats()
	want := []format{
		{name: "cli", interpreter: "/usr/bin/cli", detector: "/usr/lib/cli/binfmt-detector-cli", pkg: "mono-runtime"},
		{name: "jar", interpreter: "/usr/bin/jexec", pkg: "openjdk-11"},
		{name: "llvm-16-runtime.binfmt", interpreter: "/usr/bin/lli-16", pkg: "llvm-16-runtime"},
		{name: "llvm-17-runtime.binfmt", interpreter: "/usr/bin/lli-17", pkg: "llvm-17-runtime"},
		{name: "love", interpreter: "/usr/bin/love", pkg: "love"},
		{name: "python3.12", interpreter: "/usr/bin/python3.12", pkg: "python3.12"},
		{name: "wine", interpreter: "/usr/bin/wine", pkg: "wine"},
	}

	if len(got) != len(want) {
		t.Errorf("Want %d formats, got %d", len(want), len(got))
		t.Errorf("Got %#v\n\n, want %#v\n\n", got, want)
	} else {
		for i := range got {
			if got[i] != want[i] {
				t.Errorf("Got %#v\n\n, want %#v\n\n", got, want)
				break
			}
		}
	}
}