moira

Форк
0
/
config_test.go 
113 строк · 2.6 Кб
1
package selfstate
2

3
import (
4
	"fmt"
5
	"testing"
6

7
	. "github.com/smartystreets/goconvey/convey"
8
)
9

10
func TestConfigCheck(testing *testing.T) {
11
	contactTypes := map[string]bool{
12
		"admin-mail": true,
13
	}
14

15
	Convey("SelfCheck disabled", testing, func() {
16
		config := Config{
17
			Enabled: false,
18
			Contacts: []map[string]string{
19
				{
20
					"type":  "admin-mail",
21
					"value": "admin@company.com",
22
				},
23
			},
24
		}
25

26
		Convey("all data valid, should return nil error", func() {
27
			actual := config.checkConfig(contactTypes)
28
			So(actual, ShouldBeNil)
29
		})
30

31
		Convey("contacts empty, should return nil error", func() {
32
			config.Contacts = []map[string]string{}
33
			actual := config.checkConfig(contactTypes)
34
			So(actual, ShouldBeNil)
35
		})
36

37
		Convey("admin sending type not registered, should return nil error", func() {
38
			actual := config.checkConfig(make(map[string]bool))
39
			So(actual, ShouldBeNil)
40
		})
41

42
		Convey("admin sending contact empty, should return nil error", func() {
43
			config.Contacts = []map[string]string{
44
				{
45
					"type":  "admin-mail",
46
					"value": "",
47
				}}
48
			actual := config.checkConfig(make(map[string]bool))
49
			So(actual, ShouldBeNil)
50
		})
51
	})
52

53
	Convey("SelfCheck contacts empty, should return contacts must be specified error", testing, func() {
54
		config := Config{
55
			Enabled: true,
56
		}
57
		actual := config.checkConfig(make(map[string]bool))
58
		So(actual, ShouldResemble, fmt.Errorf("contacts must be specified"))
59
	})
60

61
	Convey("Admin sending type not registered, should not pass check without admin contact type", testing, func() {
62
		config := Config{
63
			Enabled: true,
64
			Contacts: []map[string]string{
65
				{
66
					"type":  "admin-mail",
67
					"value": "admin@company.com",
68
				},
69
			},
70
		}
71

72
		actual := config.checkConfig(make(map[string]bool))
73
		So(actual, ShouldResemble, fmt.Errorf("Unknown contact type [admin-mail]"))
74
	})
75

76
	Convey("Admin sending contact empty, should not pass check without admin contact", testing, func() {
77
		config := Config{
78
			Enabled: true,
79
			Contacts: []map[string]string{
80
				{
81
					"type":  "admin-mail",
82
					"value": "",
83
				},
84
			},
85
		}
86

87
		contactTypes := map[string]bool{
88
			"admin-mail": true,
89
		}
90

91
		actual := config.checkConfig(contactTypes)
92
		So(actual, ShouldResemble, fmt.Errorf("Value for [admin-mail] must be present"))
93
	})
94

95
	Convey("Has registered valid admin contact, should pass check", testing, func() {
96
		config := Config{
97
			Enabled: true,
98
			Contacts: []map[string]string{
99
				{
100
					"type":  "admin-mail",
101
					"value": "admin@company.com",
102
				},
103
			},
104
		}
105

106
		contactTypes := map[string]bool{
107
			"admin-mail": true,
108
		}
109

110
		actual := config.checkConfig(contactTypes)
111
		So(actual, ShouldBeNil)
112
	})
113
}
114

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

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

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

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