test(opflags): write more test cases for OpFlags.check()

This commit is contained in:
Tommaso Gragnato 2024-11-28 01:38:35 +01:00
parent 4ebae270c7
commit c894a547fc
3 changed files with 26 additions and 5 deletions

View File

@ -32,6 +32,11 @@ type OpFlags struct {
}
func (o *OpFlags) check() error {
if !o.RunDaemon && !o.RunWeb {
o.RunDaemon = true
o.RunWeb = true
}
if o.RunWeb {
o.Credentials = make(map[string][]byte)
if err := o.LoadCred(); err != nil {

View File

@ -92,6 +92,7 @@ func TestCheck(t *testing.T) {
opFlags: OpFlags{
RunDaemon: true,
FilterNodesCIDRs: []string{"invalid-cidr"},
IndexerAddrs: []string{"0.0.0.0:0"},
},
expectError: true,
},
@ -110,9 +111,29 @@ func TestCheck(t *testing.T) {
RunDaemon: true,
FilterNodesCIDRs: []string{"192.168.1.0/24"},
BootstrappingNodes: []string{"dht.tgragnato.it:80", "dht.tgragnato.it:443", "dht.tgragnato.it:1337", "dht.tgragnato.it:6969", "dht.tgragnato.it:6881", "dht.tgragnato.it:25401"},
IndexerAddrs: []string{"0.0.0.0:0"},
},
expectError: true,
},
{
name: "RunDaemonWithCustomBootstrappingNodesInFilterMode",
opFlags: OpFlags{
RunDaemon: true,
FilterNodesCIDRs: []string{"", "192.168.1.0/24"},
BootstrappingNodes: []string{"", "www.tgragnato.it:443"},
IndexerAddrs: []string{"0.0.0.0:0"},
},
expectError: false,
},
{
name: "RunWithBothDaemonAndWebStopped",
opFlags: OpFlags{
RunDaemon: false,
RunWeb: false,
IndexerAddrs: []string{"0.0.0.0:0"},
},
expectError: false,
},
}
for _, tt := range tests {

View File

@ -18,11 +18,6 @@ func (o *OpFlags) Parse() (err error) {
return err
}
if !o.RunDaemon && !o.RunWeb {
o.RunDaemon = true
o.RunWeb = true
}
return o.check()
}