File: validate_test.go

package info (click to toggle)
golang-github-containers-common 0.50.1%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,440 kB
  • sloc: makefile: 118; sh: 46
file content (41 lines) | stat: -rw-r--r-- 885 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
//go:build seccomp
// +build seccomp

package seccomp

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestValidateProfile(t *testing.T) {
	for _, tc := range []struct {
		input     string
		shouldErr bool
	}{
		{ // success
			input:     `{"defaultAction": "SCMP_ACT_KILL"}`,
			shouldErr: false,
		},
		{ // Unmarshal failed
			input:     "wrong",
			shouldErr: true,
		},
		{ // setupSeccomp failed
			input:     `{"defaultAction": "SCMP_ACT_KILL", "architectures": ["SCMP_ARCH_X86"], "archMap": [{"architecture": "SCMP_ARCH_X86"}]}`,
			shouldErr: true,
		},
		{ // BuildFilter failed
			input:     `{"defaultAction": "SCMP_ACT_KILL", "architectures": ["SCMP_ARCH_X86"], "syscalls": [{ "name": "open" }]}`,
			shouldErr: true,
		},
	} {
		err := ValidateProfile(tc.input)
		if tc.shouldErr {
			require.NotNil(t, err)
		} else {
			require.Nil(t, err)
		}
	}
}