File: support_test.go

package info (click to toggle)
docker.io 26.1.5%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,576 kB
  • sloc: sh: 5,748; makefile: 912; ansic: 664; asm: 228; python: 162
file content (65 lines) | stat: -rw-r--r-- 1,608 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
package instructions

import "testing"

type testCase struct {
	name       string
	args       []string
	attributes map[string]bool
	expected   []string
}

func initTestCases() []testCase {
	var testCases []testCase

	testCases = append(testCases, testCase{
		name:       "empty args",
		args:       []string{},
		attributes: make(map[string]bool),
		expected:   []string{},
	})

	jsonAttributes := make(map[string]bool)
	jsonAttributes["json"] = true

	testCases = append(testCases, testCase{
		name:       "json attribute with one element",
		args:       []string{"foo"},
		attributes: jsonAttributes,
		expected:   []string{"foo"},
	})

	testCases = append(testCases, testCase{
		name:       "json attribute with two elements",
		args:       []string{"foo", "bar"},
		attributes: jsonAttributes,
		expected:   []string{"foo", "bar"},
	})

	testCases = append(testCases, testCase{
		name:       "no attributes",
		args:       []string{"foo", "bar"},
		attributes: nil,
		expected:   []string{"foo bar"},
	})

	return testCases
}

func TestHandleJSONArgs(t *testing.T) {
	testCases := initTestCases()

	for _, test := range testCases {
		arguments := handleJSONArgs(test.args, test.attributes)

		if len(arguments) != len(test.expected) {
			t.Fatalf("In test \"%s\": length of returned slice is incorrect. Expected: %d, got: %d", test.name, len(test.expected), len(arguments))
		}

		for i := range test.expected {
			if arguments[i] != test.expected[i] {
				t.Fatalf("In test \"%s\": element as position %d is incorrect. Expected: %s, got: %s", test.name, i, test.expected[i], arguments[i])
			}
		}
	}
}