Dragonfly2

Форк
0
/
dfstore_test.go 
95 строк · 2.2 Кб
1
/*
2
 *     Copyright 2022 The Dragonfly Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package config
18

19
import (
20
	"testing"
21

22
	testifyassert "github.com/stretchr/testify/assert"
23
)
24

25
func Test_NewDfstore(t *testing.T) {
26
	tests := []struct {
27
		name   string
28
		expect func(t *testing.T, cfg *DfstoreConfig)
29
	}{
30
		{
31
			name: "new dfstore configuration",
32
			expect: func(t *testing.T, cfg *DfstoreConfig) {
33
				assert := testifyassert.New(t)
34
				assert.Equal("http://127.0.0.1:65004", cfg.Endpoint)
35
				assert.Equal(3, cfg.MaxReplicas)
36
			},
37
		},
38
	}
39

40
	for _, tc := range tests {
41
		t.Run(tc.name, func(t *testing.T) {
42
			cfg := NewDfstore()
43
			tc.expect(t, cfg)
44
		})
45
	}
46
}
47

48
func TestDfstoreConfig_Validate(t *testing.T) {
49
	tests := []struct {
50
		name   string
51
		cfg    *DfstoreConfig
52
		expect func(t *testing.T, err error)
53
	}{
54
		{
55
			name: "normal dfsrore",
56
			cfg: &DfstoreConfig{
57
				Endpoint:    "http://127.0.0.1:65004",
58
				MaxReplicas: 3,
59
			},
60
			expect: func(t *testing.T, err error) {
61
				assert := testifyassert.New(t)
62
				assert.Nil(err)
63
			},
64
		},
65
		{
66
			name: "dfstore without endpoint",
67
			cfg: &DfstoreConfig{
68
				Endpoint:    "",
69
				MaxReplicas: 3,
70
			},
71
			expect: func(t *testing.T, err error) {
72
				assert := testifyassert.New(t)
73
				assert.EqualError(err, "dfstore requires parameter endpoint")
74
			},
75
		},
76
		{
77
			name: "dfstore with invalid endpoint",
78
			cfg: &DfstoreConfig{
79
				Endpoint:    "127.0.0.1:65004",
80
				MaxReplicas: 3,
81
			},
82
			expect: func(t *testing.T, err error) {
83
				assert := testifyassert.New(t)
84
				assert.EqualError(err, "invalid endpoint: parse \"127.0.0.1:65004\": invalid URI for request")
85
			},
86
		},
87
	}
88

89
	for _, tc := range tests {
90
		t.Run(tc.name, func(t *testing.T) {
91
			err := tc.cfg.Validate()
92
			tc.expect(t, err)
93
		})
94
	}
95
}
96

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

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

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

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