summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi/play_utils_test.go
blob: 80a9fe5435c3efd614184eda95ed7fe9c21dad49 (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
package abi

import (
	"testing"

	"github.com/containers/podman/v4/libpod/define"
	"github.com/stretchr/testify/require"
)

func TestGetSdNotifyMode(t *testing.T) {
	tests := []struct {
		key, value, name, result string
		mustError                bool
	}{
		{sdNotifyAnnotation, define.SdNotifyModeConmon, "", define.SdNotifyModeConmon, false},
		{sdNotifyAnnotation + "/container-a", define.SdNotifyModeContainer, "container-a", define.SdNotifyModeContainer, false},
		{sdNotifyAnnotation + "/container-b", define.SdNotifyModeIgnore, "container-b", define.SdNotifyModeIgnore, false},
		{sdNotifyAnnotation + "/container-c", "", "container-c", "", false},
		{sdNotifyAnnotation + "-/wrong-key", "xxx", "wrong-key", "", false},
		{sdNotifyAnnotation + "/container-error", "invalid", "container-error", "", true},
	}

	annotations := make(map[string]string)
	// Populate the annotations
	for _, test := range tests {
		annotations[test.key] = test.value
	}
	// Run the tests
	for _, test := range tests {
		result, err := getSdNotifyMode(annotations, test.name)
		if test.mustError {
			require.Error(t, err, "%v", test)
			continue
		}
		require.NoError(t, err, "%v", test)
		require.Equal(t, test.result, result, "%v", test)
	}
}