argo-cd

Форк
0
81 строка · 1.9 Кб
1
package v1alpha1
2

3
import (
4
	"testing"
5

6
	"github.com/stretchr/testify/assert"
7
)
8

9
func TestValues_SetString(t *testing.T) {
10
	testCases := []struct {
11
		name        string
12
		inputValue  string
13
		expectError bool
14
		expectValue string
15
	}{
16
		{
17
			name:        "an empty string should not throw an error",
18
			inputValue:  `""`,
19
			expectValue: "\"\"",
20
		},
21
		{
22
			name:        "a string with contents should not throw an error",
23
			inputValue:  `"hello"`,
24
			expectValue: "hello",
25
		},
26
		{
27
			name:        "an array should throw an error",
28
			inputValue:  "[]",
29
			expectError: true,
30
		},
31
		{
32
			name:        "a number should throw an error",
33
			inputValue:  "42",
34
			expectError: true,
35
		},
36
		{
37
			name:        "a boolean should throw an error",
38
			inputValue:  "false",
39
			expectError: true,
40
		},
41
		{
42
			name:        "null should throw an error",
43
			inputValue:  "null",
44
			expectError: true,
45
		},
46
		{
47
			name:        "an empty object should not throw an error",
48
			inputValue:  "{}",
49
			expectValue: "{}",
50
		},
51
		{
52
			name:        "an object with contents should not throw an error",
53
			inputValue:  `{"some": "inputValue"}`,
54
			expectValue: "some: inputValue",
55
		},
56
		{
57
			name:        "a complex object should not throw an error",
58
			inputValue:  `{"a": {"nested": "object"}, "an": ["array"], "bool": true, "number": 1, "some": "string"}`,
59
			expectValue: "a:\n  nested: object\nan:\n- array\nbool: true\nnumber: 1\nsome: string",
60
		},
61
	}
62

63
	for _, testCase := range testCases {
64
		var err error
65
		t.Run(testCase.name, func(t *testing.T) {
66
			source := &ApplicationSourceHelm{}
67
			err = source.SetValuesString(testCase.inputValue)
68

69
			if !testCase.expectError {
70
				assert.Equal(t, testCase.expectValue, source.ValuesString())
71
				data, err := source.ValuesObject.MarshalJSON()
72
				assert.NoError(t, err)
73
				err = source.ValuesObject.UnmarshalJSON(data)
74
				assert.NoError(t, err)
75
				assert.Equal(t, testCase.expectValue, source.ValuesString())
76
			} else {
77
				assert.Error(t, err)
78
			}
79
		})
80
	}
81
}
82

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.