Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit a928c0d

Browse files
authored
Merge pull request #1384 from Hellcatlk/UnitTest
test: Add unit test for dfget/locator/manager.go
2 parents edd832b + 5f0f298 commit a928c0d

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

dfget/locator/manager_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 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 locator
18+
19+
import (
20+
"github.com/dragonflyoss/Dragonfly/dfget/config"
21+
)
22+
23+
func (s *LocatorTestSuite) Test_CreateLocator() {
24+
cases := []struct {
25+
cfg *config.Config
26+
expected SupernodeLocator
27+
}{
28+
{
29+
cfg: nil,
30+
expected: &StaticLocator{
31+
idx: -1,
32+
Group: &SupernodeGroup{
33+
Name: "default",
34+
Nodes: []*Supernode{
35+
{
36+
Schema: "http",
37+
IP: "127.0.0.1",
38+
Port: 8002,
39+
Weight: 1,
40+
GroupName: "default",
41+
},
42+
},
43+
},
44+
},
45+
},
46+
{
47+
cfg: &config.Config{},
48+
expected: &StaticLocator{
49+
idx: -1,
50+
Group: &SupernodeGroup{
51+
Name: "default",
52+
Nodes: []*Supernode{
53+
{
54+
Schema: "http",
55+
IP: "127.0.0.1",
56+
Port: 8002,
57+
Weight: 1,
58+
GroupName: "default",
59+
},
60+
},
61+
},
62+
},
63+
},
64+
{
65+
cfg: &config.Config{
66+
Nodes: []string{"localhost"},
67+
},
68+
expected: &StaticLocator{
69+
idx: -1,
70+
Group: &SupernodeGroup{
71+
Name: "config",
72+
Nodes: []*Supernode{
73+
{
74+
Schema: "http",
75+
IP: "localhost",
76+
Port: 8002,
77+
Weight: 1,
78+
GroupName: "config",
79+
},
80+
},
81+
},
82+
},
83+
},
84+
}
85+
86+
for _, c := range cases {
87+
got := CreateLocator(c.cfg)
88+
s.Equal(c.expected, got)
89+
}
90+
}

0 commit comments

Comments
 (0)