Dragonfly2

Форк
0
/
peerhost_test.go 
789 строк · 17.8 Кб
1
/*
2
 *     Copyright 2020 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
	"fmt"
21
	"net"
22
	"net/url"
23
	"os"
24
	"reflect"
25
	"strings"
26
	"testing"
27
	"time"
28

29
	"github.com/stretchr/testify/assert"
30
	"golang.org/x/time/rate"
31
	"gopkg.in/yaml.v3"
32

33
	"d7y.io/dragonfly/v2/client/util"
34
	"d7y.io/dragonfly/v2/cmd/dependency/base"
35
	"d7y.io/dragonfly/v2/pkg/dfnet"
36
	"d7y.io/dragonfly/v2/pkg/types"
37
	"d7y.io/dragonfly/v2/pkg/unit"
38
)
39

40
func Test_AllUnmarshalYAML(t *testing.T) {
41
	var cases = []struct {
42
		text   string
43
		target any
44
	}{
45
		{
46
			text: `
47
"port": 1234
48
`,
49
			target: &struct {
50
				Port TCPListenPortRange `yaml:"port"`
51
			}{
52
				Port: TCPListenPortRange{
53
					Start: 1234,
54
				},
55
			},
56
		},
57
		{
58
			text: `
59
port:
60
  start: 1234
61
  end: 1235
62
`,
63
			target: &struct {
64
				Port TCPListenPortRange `yaml:"port"`
65
			}{
66
				Port: TCPListenPortRange{
67
					Start: 1234,
68
					End:   1235,
69
				},
70
			},
71
		},
72
		{
73
			text: `
74
timeout: 1000000000
75
`,
76
			target: &struct {
77
				Timeout util.Duration `yaml:"timeout"`
78
			}{
79
				Timeout: util.Duration{
80
					Duration: time.Second,
81
				},
82
			},
83
		},
84
		{
85
			text: `
86
timeout: 1s
87
`,
88
			target: &struct {
89
				Timeout util.Duration `yaml:"timeout"`
90
			}{
91
				Timeout: util.Duration{
92
					Duration: time.Second,
93
				},
94
			},
95
		},
96
		{
97
			text: `
98
limit: 100Mi
99
`,
100
			target: &struct {
101
				Limit util.RateLimit `yaml:"limit"`
102
			}{
103
				Limit: util.RateLimit{
104
					Limit: 100 * 1024 * 1024,
105
				},
106
			},
107
		},
108
		{
109
			text: `
110
limit: 2097152
111
`,
112
			target: &struct {
113
				Limit util.RateLimit `yaml:"limit"`
114
			}{
115
				Limit: util.RateLimit{
116
					Limit: 2 * 1024 * 1024,
117
				},
118
			},
119
		},
120
		{
121
			text: `
122
addr: 127.0.0.1:8002
123
`,
124
			target: &struct {
125
				Addr dfnet.NetAddr `yaml:"addr"`
126
			}{
127
				Addr: dfnet.NetAddr{
128
					Type: dfnet.TCP,
129
					Addr: "127.0.0.1:8002",
130
				},
131
			},
132
		},
133
		{
134
			text: `
135
listen:
136
  type: tcp
137
  addr: 127.0.0.1:8002
138
`,
139
			target: &struct {
140
				Listen dfnet.NetAddr `yaml:"listen"`
141
			}{
142
				Listen: dfnet.NetAddr{
143
					Type: dfnet.TCP,
144
					Addr: "127.0.0.1:8002",
145
				},
146
			},
147
		},
148
		{
149
			text: `
150
diskGCThreshold: 1Ki
151
`,
152
			target: &struct {
153
				Size unit.Bytes `yaml:"diskGCThreshold"`
154
			}{
155
				Size: unit.Bytes(1024),
156
			},
157
		},
158
	}
159
	for _, c := range cases {
160
		actual := reflect.New(reflect.TypeOf(c.target).Elem()).Interface()
161
		err := yaml.Unmarshal([]byte(c.text), actual)
162

163
		assert := assert.New(t)
164
		assert.Nil(err, "yaml.Unmarshal should return nil")
165
		assert.EqualValues(c.target, actual)
166
	}
167
}
168

169
func TestUnmarshalYAML(t *testing.T) {
170
	bytes := []byte(`
171
tls:
172
  key: ./testdata/certs/sca.key
173
  cert: ./testdata/certs/sca.crt
174
  caCert: ./testdata/certs/ca.crt
175
url: https://d7y.io
176
certs: ["./testdata/certs/ca.crt", "./testdata/certs/sca.crt"]
177
regx: blobs/sha256.*
178
port1: 1001 
179
port2:
180
  start: 1002
181
  end: 1003
182
timeout: 3m
183
limit: 2Mib
184
type: tcp
185
proxy1: ./testdata/config/proxy.yaml
186
proxy2: 
187
  registryMirror:
188
    url: https://index.docker.io
189
schedulers1:
190
  netAddrs:
191
    - 0.0.0.0
192
    - 0.0.0.1
193
  scheduleTimeout: 0
194
schedulers2:
195
  netAddrs:
196
    - type: tcp
197
      addr: 0.0.0.0
198
  scheduleTimeout: 0
199
`)
200

201
	var s = struct {
202
		TLSConfig   *TLSConfig         `yaml:"tls"`
203
		URL         *URL               `yaml:"url"`
204
		Certs       *CertPool          `yaml:"certs"`
205
		Regx        *Regexp            `yaml:"regx"`
206
		Port1       TCPListenPortRange `yaml:"port1"`
207
		Port2       TCPListenPortRange `yaml:"port2"`
208
		Timeout     util.Duration      `yaml:"timeout"`
209
		Limit       util.RateLimit     `yaml:"limit"`
210
		Type        dfnet.NetworkType  `yaml:"type"`
211
		Proxy1      ProxyOption        `yaml:"proxy1"`
212
		Proxy2      ProxyOption        `yaml:"proxy2"`
213
		Schedulers1 SchedulerOption    `yaml:"schedulers1"`
214
		Schedulers2 SchedulerOption    `yaml:"schedulers2"`
215
	}{}
216

217
	if err := yaml.Unmarshal(bytes, &s); err != nil {
218
		t.Fatal(err)
219
	}
220
}
221

222
func TestPeerHostOption_Load(t *testing.T) {
223
	proxyExp, _ := NewRegexp("blobs/sha256.*")
224
	hijackExp, _ := NewRegexp("mirror.aliyuncs.com:443")
225

226
	_caCert, _ := os.ReadFile("./testdata/certs/ca.crt")
227
	_cert, _ := os.ReadFile("./testdata/certs/sca.crt")
228
	_key, _ := os.ReadFile("./testdata/certs/sca.key")
229

230
	caCert := types.PEMContent(strings.TrimSpace(string(_caCert)))
231
	cert := types.PEMContent(strings.TrimSpace(string(_cert)))
232
	key := types.PEMContent(strings.TrimSpace(string(_key)))
233

234
	peerHostOption := &DaemonOption{
235
		Options: base.Options{
236
			Console:   true,
237
			Verbose:   true,
238
			PProfPort: -1,
239
			Telemetry: base.TelemetryOption{
240
				Jaeger:      "foo",
241
				ServiceName: "bar",
242
			},
243
		},
244
		AliveTime: util.Duration{
245
			Duration: 0,
246
		},
247
		GCInterval: util.Duration{
248
			Duration: 60000000000,
249
		},
250
		Metrics:      ":8000",
251
		WorkHome:     "/tmp/dragonfly/dfdaemon/",
252
		WorkHomeMode: 0700,
253
		CacheDir:     "/var/cache/dragonfly/",
254
		CacheDirMode: 0700,
255
		LogDir:       "/var/log/dragonfly/",
256
		PluginDir:    "/tmp/dragonfly/dfdaemon/plugins/",
257
		DataDir:      "/var/lib/dragonfly/",
258
		DataDirMode:  0700,
259
		KeepStorage:  false,
260
		Scheduler: SchedulerOption{
261
			Manager: ManagerOption{
262
				Enable: false,
263
				NetAddrs: []dfnet.NetAddr{
264
					{
265
						Type: dfnet.TCP,
266
						Addr: "127.0.0.1:65003",
267
					},
268
				},
269
				RefreshInterval: 5 * time.Minute,
270
				SeedPeer: SeedPeerOption{
271
					Enable:    false,
272
					Type:      types.HostTypeStrongSeedName,
273
					ClusterID: 2,
274
					KeepAlive: KeepAliveOption{
275
						Interval: 10 * time.Second,
276
					},
277
				},
278
			},
279
			NetAddrs: []dfnet.NetAddr{
280
				{
281
					Type: dfnet.TCP,
282
					Addr: "127.0.0.1:8002",
283
				},
284
			},
285
			ScheduleTimeout: util.Duration{
286
				Duration: 0,
287
			},
288
			DisableAutoBackSource: true,
289
		},
290
		Host: HostOption{
291
			Hostname:    "d7y.io",
292
			Location:    "0.0.0.0",
293
			IDC:         "d7y",
294
			AdvertiseIP: net.IPv4zero,
295
		},
296
		Download: DownloadOption{
297
			TotalRateLimit: util.RateLimit{
298
				Limit: 1024 * 1024 * 1024,
299
			},
300
			PerPeerRateLimit: util.RateLimit{
301
				Limit: 512 * 1024 * 1024,
302
			},
303
			PieceDownloadTimeout: 30 * time.Second,
304
			DownloadGRPC: ListenOption{
305
				Security: SecurityOption{
306
					Insecure:  true,
307
					CACert:    caCert,
308
					Cert:      cert,
309
					Key:       key,
310
					TLSVerify: true,
311
					TLSConfig: nil,
312
				},
313
				TCPListen: nil,
314
				UnixListen: &UnixListenOption{
315
					Socket: "/tmp/dfdaemon.sock",
316
				},
317
			},
318
			PeerGRPC: ListenOption{
319
				Security: SecurityOption{
320
					Insecure:  true,
321
					CACert:    caCert,
322
					Cert:      cert,
323
					Key:       key,
324
					TLSVerify: true,
325
					TLSConfig: nil,
326
				},
327
				TCPListen: &TCPListenOption{
328
					Listen: "0.0.0.0",
329
					PortRange: TCPListenPortRange{
330
						Start: 65000,
331
						End:   0,
332
					},
333
				},
334
			},
335
			CalculateDigest: true,
336
			Transport: &TransportOption{
337
				DialTimeout:           time.Second,
338
				KeepAlive:             time.Second,
339
				MaxIdleConns:          1,
340
				IdleConnTimeout:       time.Second,
341
				ResponseHeaderTimeout: time.Second,
342
				TLSHandshakeTimeout:   time.Second,
343
				ExpectContinueTimeout: time.Second,
344
			},
345
			GetPiecesMaxRetry: 1,
346
			Prefetch:          true,
347
			WatchdogTimeout:   time.Second,
348
			Concurrent: &ConcurrentOption{
349
				ThresholdSize: util.Size{
350
					Limit: 1,
351
				},
352
				ThresholdSpeed: unit.Bytes(1),
353
				GoroutineCount: 1,
354
				InitBackoff:    1,
355
				MaxBackoff:     1,
356
				MaxAttempts:    1,
357
			},
358
		},
359
		Upload: UploadOption{
360
			RateLimit: util.RateLimit{
361
				Limit: 1024 * 1024 * 1024,
362
			},
363
			ListenOption: ListenOption{
364
				Security: SecurityOption{
365
					Insecure:  true,
366
					CACert:    caCert,
367
					Cert:      cert,
368
					Key:       key,
369
					TLSVerify: true,
370
				},
371
				TCPListen: &TCPListenOption{
372
					Listen: "0.0.0.0",
373
					PortRange: TCPListenPortRange{
374
						Start: 65002,
375
						End:   0,
376
					},
377
				},
378
			},
379
		},
380
		ObjectStorage: ObjectStorageOption{
381
			Enable:      true,
382
			Filter:      "Expires&Signature&ns",
383
			MaxReplicas: 3,
384
			ListenOption: ListenOption{
385
				Security: SecurityOption{
386
					Insecure:  true,
387
					CACert:    caCert,
388
					Cert:      cert,
389
					Key:       key,
390
					TLSVerify: true,
391
				},
392
				TCPListen: &TCPListenOption{
393
					Listen: "0.0.0.0",
394
					PortRange: TCPListenPortRange{
395
						Start: 65004,
396
						End:   0,
397
					},
398
				},
399
			},
400
		},
401
		Storage: StorageOption{
402
			DataPath: "/tmp/storage/data",
403
			TaskExpireTime: util.Duration{
404
				Duration: 180000000000,
405
			},
406
			StoreStrategy:          StoreStrategy("io.d7y.storage.v2.simple"),
407
			DiskGCThreshold:        60 * unit.MB,
408
			DiskGCThresholdPercent: 0.6,
409
			Multiplex:              true,
410
		},
411
		Health: &HealthOption{
412
			Path: "/health",
413
		},
414
		Proxy: &ProxyOption{
415
			ListenOption: ListenOption{
416
				Security: SecurityOption{
417
					Insecure:  true,
418
					CACert:    caCert,
419
					Cert:      cert,
420
					Key:       key,
421
					TLSVerify: true,
422
				},
423
				TCPListen: &TCPListenOption{
424
					Listen: "0.0.0.0",
425
					PortRange: TCPListenPortRange{
426
						Start: 65001,
427
						End:   0,
428
					},
429
				},
430
			},
431
			BasicAuth: &BasicAuth{
432
				Username: "foo",
433
				Password: "bar",
434
			},
435
			DefaultFilter:      "baz",
436
			DefaultTag:         "tag",
437
			DefaultApplication: "application",
438
			MaxConcurrency:     1,
439
			RegistryMirror: &RegistryMirror{
440
				Remote: &URL{
441
					&url.URL{
442
						Host:   "index.docker.io",
443
						Scheme: "https",
444
					},
445
				},
446
				DynamicRemote: true,
447
				UseProxies:    true,
448
				Insecure:      true,
449
				Direct:        false,
450
			},
451
			WhiteList: []*WhiteList{
452
				{
453
					Host: "foo",
454
					Regx: proxyExp,
455
					Ports: []string{
456
						"1000",
457
						"2000",
458
					},
459
				},
460
			},
461
			ProxyRules: []*ProxyRule{
462
				{
463
					Regx:     proxyExp,
464
					UseHTTPS: false,
465
					Direct:   false,
466
					Redirect: "d7y.io",
467
				},
468
			},
469
			HijackHTTPS: &HijackConfig{
470
				Cert: "./testdata/certs/sca.crt",
471
				Key:  "./testdata/certs/sca.key",
472
				Hosts: []*HijackHost{
473
					{
474
						Regx:     hijackExp,
475
						Insecure: true,
476
					},
477
				},
478
				SNI: nil,
479
			},
480
			DumpHTTPContent: true,
481
			ExtraRegistryMirrors: []*RegistryMirror{
482
				{
483
					Remote: &URL{
484
						&url.URL{
485
							Host:   "index.docker.io",
486
							Scheme: "https",
487
						},
488
					},
489
					DynamicRemote: true,
490
					UseProxies:    true,
491
					Insecure:      true,
492
					Direct:        true,
493
				},
494
			},
495
		},
496
		Reload: ReloadOption{
497
			Interval: util.Duration{
498
				Duration: 180000000000,
499
			},
500
		},
501
		Security: GlobalSecurityOption{
502
			AutoIssueCert: true,
503
			CACert:        "-----BEGIN CERTIFICATE-----",
504
			TLSVerify:     true,
505
			TLSPolicy:     "force",
506
			CertSpec: &CertSpec{
507
				DNSNames:       []string{"foo"},
508
				IPAddresses:    []net.IP{net.IPv4zero},
509
				ValidityPeriod: 1000000000,
510
			},
511
		},
512
		Network: &NetworkOption{
513
			EnableIPv6: true,
514
		},
515
		Announcer: AnnouncerOption{
516
			SchedulerInterval: 1000000000,
517
		},
518
		NetworkTopology: NetworkTopologyOption{
519
			Enable: true,
520
			Probe: ProbeOption{
521
				Interval: 20 * time.Minute,
522
			},
523
		},
524
	}
525

526
	peerHostOptionYAML := &DaemonOption{}
527
	if err := peerHostOptionYAML.Load("./testdata/config/daemon.yaml"); err != nil {
528
		t.Fatal(err)
529
	}
530

531
	assert := assert.New(t)
532
	assert.EqualValues(peerHostOption, peerHostOptionYAML)
533
}
534

535
func TestPeerHostOption_Validate(t *testing.T) {
536
	tests := []struct {
537
		name   string
538
		config *DaemonConfig
539
		mock   func(cfg *DaemonConfig)
540
		expect func(t *testing.T, err error)
541
	}{
542
		{
543
			name:   "valid config",
544
			config: NewDaemonConfig(),
545
			mock: func(cfg *DaemonConfig) {
546
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
547
					{
548
						Type: dfnet.TCP,
549
						Addr: "127.0.0.1:8002",
550
					},
551
				}
552
			},
553
			expect: func(t *testing.T, err error) {
554
				assert := assert.New(t)
555
				assert.NoError(err)
556
			},
557
		},
558
		{
559
			name:   "manager addr is not specified",
560
			config: NewDaemonConfig(),
561
			mock: func(cfg *DaemonConfig) {
562
				cfg.Scheduler.Manager.Enable = true
563
				cfg.Scheduler.Manager.NetAddrs = nil
564
			},
565
			expect: func(t *testing.T, err error) {
566
				assert := assert.New(t)
567
				assert.EqualError(err, "manager addr is not specified")
568
			},
569
		},
570
		{
571
			name:   "manager refreshInterval not specified",
572
			config: NewDaemonConfig(),
573
			mock: func(cfg *DaemonConfig) {
574
				cfg.Scheduler.Manager.Enable = true
575
				cfg.Scheduler.Manager.RefreshInterval = 0
576
				cfg.Scheduler.Manager.NetAddrs = []dfnet.NetAddr{
577
					{
578
						Type: dfnet.TCP,
579
						Addr: "127.0.0.1:8002",
580
					},
581
				}
582
			},
583
			expect: func(t *testing.T, err error) {
584
				assert := assert.New(t)
585
				assert.EqualError(err, "manager refreshInterval is not specified")
586
			},
587
		},
588
		{
589
			name:   "empty schedulers and config server is not specified",
590
			config: NewDaemonConfig(),
591
			mock: func(cfg *DaemonConfig) {
592
				cfg.Scheduler.NetAddrs = nil
593
			},
594
			expect: func(t *testing.T, err error) {
595
				assert := assert.New(t)
596
				assert.EqualError(err, "empty schedulers and config server is not specified")
597
			},
598
		},
599
		{
600
			name:   "download rate limit must be greater",
601
			config: NewDaemonConfig(),
602
			mock: func(cfg *DaemonConfig) {
603
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
604
					{
605
						Type: dfnet.TCP,
606
						Addr: "127.0.0.1:8002",
607
					},
608
				}
609
				cfg.Download.TotalRateLimit.Limit = rate.Limit(10 * unit.MB)
610
			},
611
			expect: func(t *testing.T, err error) {
612
				assert := assert.New(t)
613
				msg := fmt.Sprintf("rate limit must be greater than %s", DefaultMinRate.String())
614
				assert.EqualError(err, msg)
615
			},
616
		},
617
		{
618
			name:   "upload rate limit must be greater",
619
			config: NewDaemonConfig(),
620
			mock: func(cfg *DaemonConfig) {
621
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
622
					{
623
						Type: dfnet.TCP,
624
						Addr: "127.0.0.1:8002",
625
					},
626
				}
627
				cfg.Upload.RateLimit.Limit = rate.Limit(10 * unit.MB)
628
			},
629
			expect: func(t *testing.T, err error) {
630
				assert := assert.New(t)
631
				msg := fmt.Sprintf("rate limit must be greater than %s", DefaultMinRate.String())
632
				assert.EqualError(err, msg)
633
			},
634
		},
635
		{
636
			name:   "max replicas must be greater than 0",
637
			config: NewDaemonConfig(),
638
			mock: func(cfg *DaemonConfig) {
639
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
640
					{
641
						Type: dfnet.TCP,
642
						Addr: "127.0.0.1:8002",
643
					},
644
				}
645
				cfg.ObjectStorage.Enable = true
646
				cfg.ObjectStorage.MaxReplicas = 0
647
			},
648
			expect: func(t *testing.T, err error) {
649
				assert := assert.New(t)
650
				assert.EqualError(err, "max replicas must be greater than 0")
651
			},
652
		},
653
		{
654
			name:   "reload interval too short, must great than 1 second",
655
			config: NewDaemonConfig(),
656
			mock: func(cfg *DaemonConfig) {
657
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
658
					{
659
						Type: dfnet.TCP,
660
						Addr: "127.0.0.1:8002",
661
					},
662
				}
663
				cfg.Reload.Interval.Duration = time.Millisecond
664
			},
665
			expect: func(t *testing.T, err error) {
666
				assert := assert.New(t)
667
				assert.EqualError(err, "reload interval too short, must great than 1 second")
668
			},
669
		},
670
		{
671
			name:   "gcInterval must be greater than 0",
672
			config: NewDaemonConfig(),
673
			mock: func(cfg *DaemonConfig) {
674
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
675
					{
676
						Type: dfnet.TCP,
677
						Addr: "127.0.0.1:8002",
678
					},
679
				}
680
				cfg.GCInterval.Duration = 0
681
			},
682
			expect: func(t *testing.T, err error) {
683
				assert := assert.New(t)
684
				assert.EqualError(err, "gcInterval must be greater than 0")
685
			},
686
		},
687
		{
688
			name:   "security requires parameter caCert",
689
			config: NewDaemonConfig(),
690
			mock: func(cfg *DaemonConfig) {
691
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
692
					{
693
						Type: dfnet.TCP,
694
						Addr: "127.0.0.1:8002",
695
					},
696
				}
697
				cfg.Security.AutoIssueCert = true
698
				cfg.Security.CACert = ""
699
			},
700
			expect: func(t *testing.T, err error) {
701
				assert := assert.New(t)
702
				assert.EqualError(err, "security requires parameter caCert")
703
			},
704
		},
705
		{
706
			name:   "certSpec requires parameter ipAddresses",
707
			config: NewDaemonConfig(),
708
			mock: func(cfg *DaemonConfig) {
709
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
710
					{
711
						Type: dfnet.TCP,
712
						Addr: "127.0.0.1:8002",
713
					},
714
				}
715
				cfg.Security.AutoIssueCert = true
716
				cfg.Security.CACert = "test"
717
				cfg.Security.CertSpec.IPAddresses = nil
718
			},
719
			expect: func(t *testing.T, err error) {
720
				assert := assert.New(t)
721
				assert.EqualError(err, "certSpec requires parameter ipAddresses")
722
			},
723
		},
724
		{
725
			name:   "certSpec requires parameter dnsNames",
726
			config: NewDaemonConfig(),
727
			mock: func(cfg *DaemonConfig) {
728
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
729
					{
730
						Type: dfnet.TCP,
731
						Addr: "127.0.0.1:8002",
732
					},
733
				}
734
				cfg.Security.AutoIssueCert = true
735
				cfg.Security.CACert = "test"
736
				cfg.Security.CertSpec.IPAddresses = []net.IP{net.ParseIP("127.0.0.1")}
737
				cfg.Security.CertSpec.DNSNames = nil
738
			},
739
			expect: func(t *testing.T, err error) {
740
				assert := assert.New(t)
741
				assert.EqualError(err, "certSpec requires parameter dnsNames")
742
			},
743
		},
744
		{
745
			name:   "certSpec requires parameter validityPeriod",
746
			config: NewDaemonConfig(),
747
			mock: func(cfg *DaemonConfig) {
748
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
749
					{
750
						Type: dfnet.TCP,
751
						Addr: "127.0.0.1:8002",
752
					},
753
				}
754
				cfg.Security.AutoIssueCert = true
755
				cfg.Security.CACert = "testcert"
756
				cfg.Security.CertSpec.ValidityPeriod = 0
757
			},
758
			expect: func(t *testing.T, err error) {
759
				assert := assert.New(t)
760
				assert.EqualError(err, "certSpec requires parameter validityPeriod")
761
			},
762
		},
763
		{
764
			name:   "probe requires parameter interval",
765
			config: NewDaemonConfig(),
766
			mock: func(cfg *DaemonConfig) {
767
				cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
768
					{
769
						Type: dfnet.TCP,
770
						Addr: "127.0.0.1:8002",
771
					},
772
				}
773
				cfg.NetworkTopology.Enable = true
774
				cfg.NetworkTopology.Probe.Interval = 0
775
			},
776
			expect: func(t *testing.T, err error) {
777
				assert := assert.New(t)
778
				assert.EqualError(err, "probe requires parameter interval")
779
			},
780
		},
781
	}
782

783
	for _, tc := range tests {
784
		t.Run(tc.name, func(t *testing.T) {
785
			tc.mock(tc.config)
786
			tc.expect(t, tc.config.Validate())
787
		})
788
	}
789
}
790

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

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

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

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