Dragonfly2

Форк
0
/
announcer_test.go 
86 строк · 2.7 Кб
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 announcer
18

19
import (
20
	"testing"
21

22
	"github.com/stretchr/testify/assert"
23
	"go.uber.org/mock/gomock"
24

25
	"d7y.io/dragonfly/v2/client/config"
26
	configmocks "d7y.io/dragonfly/v2/client/config/mocks"
27
	managerclientmocks "d7y.io/dragonfly/v2/pkg/rpc/manager/client/mocks"
28
	schedulerclientmocks "d7y.io/dragonfly/v2/pkg/rpc/scheduler/client/mocks"
29
)
30

31
func TestAnnouncer_New(t *testing.T) {
32
	tests := []struct {
33
		name               string
34
		config             *config.DaemonOption
35
		hostID             string
36
		deamonPort         int32
37
		deamonDownloadPort int32
38
		expect             func(t *testing.T, announcer Announcer)
39
	}{
40
		{
41
			name:               "new announcer",
42
			config:             &config.DaemonOption{},
43
			hostID:             "foo",
44
			deamonPort:         8000,
45
			deamonDownloadPort: 8001,
46
			expect: func(t *testing.T, a Announcer) {
47
				assert := assert.New(t)
48
				instance := a.(*announcer)
49
				assert.NotNil(instance.config)
50
				assert.Equal(instance.hostID, "foo")
51
				assert.Equal(instance.daemonPort, int32(8000))
52
				assert.Equal(instance.daemonDownloadPort, int32(8001))
53
				assert.NotNil(instance.managerClient)
54
				assert.NotNil(instance.schedulerClient)
55
			},
56
		},
57
		{
58
			name:               "new announcer with empty value",
59
			config:             nil,
60
			hostID:             "",
61
			deamonPort:         0,
62
			deamonDownloadPort: 0,
63
			expect: func(t *testing.T, a Announcer) {
64
				assert := assert.New(t)
65
				instance := a.(*announcer)
66
				assert.Nil(instance.config)
67
				assert.Equal(instance.hostID, "")
68
				assert.Equal(instance.daemonPort, int32(0))
69
				assert.Equal(instance.daemonDownloadPort, int32(0))
70
				assert.NotNil(instance.managerClient)
71
				assert.NotNil(instance.schedulerClient)
72
			},
73
		},
74
	}
75

76
	for _, tc := range tests {
77
		t.Run(tc.name, func(t *testing.T) {
78
			ctl := gomock.NewController(t)
79
			defer ctl.Finish()
80
			mockManagerClient := managerclientmocks.NewMockV1(ctl)
81
			mockSchedulerClient := schedulerclientmocks.NewMockV1(ctl)
82
			mockDynconfig := configmocks.NewMockDynconfig(ctl)
83
			tc.expect(t, New(tc.config, mockDynconfig, tc.hostID, tc.deamonPort, tc.deamonDownloadPort, mockSchedulerClient, WithManagerClient(mockManagerClient)))
84
		})
85
	}
86
}
87

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

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

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

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