File: plugin_test.go

package info (click to toggle)
docker.io 28.5.2%2Bdfsg3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 68,176 kB
  • sloc: sh: 5,867; makefile: 863; ansic: 184; python: 162; asm: 159
file content (43 lines) | stat: -rw-r--r-- 902 bytes parent folder | download
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
package manager

import (
	"encoding/json"
	"errors"
	"testing"

	"gotest.tools/v3/assert"
	is "gotest.tools/v3/assert/cmp"
)

func TestPluginMarshal(t *testing.T) {
	const jsonWithError = `{"Name":"some-plugin","Err":"something went wrong"}`
	const jsonNoError = `{"Name":"some-plugin"}`

	tests := []struct {
		doc      string
		error    error
		expected string
	}{
		{
			doc:      "no error",
			expected: jsonNoError,
		},
		{
			doc:      "regular error",
			error:    errors.New("something went wrong"),
			expected: jsonWithError,
		},
		{
			doc:      "custom error",
			error:    newPluginError("something went wrong"),
			expected: jsonWithError,
		},
	}
	for _, tc := range tests {
		t.Run(tc.doc, func(t *testing.T) {
			actual, err := json.Marshal(&Plugin{Name: "some-plugin", Err: tc.error})
			assert.NilError(t, err)
			assert.Check(t, is.Equal(string(actual), tc.expected))
		})
	}
}