Skip to content

Commit

Permalink
test(opflags): write more test cases for OpFlags.check()
Browse files Browse the repository at this point in the history
  • Loading branch information
tgragnato committed Nov 28, 2024
1 parent 4ebae27 commit c894a54
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions opflags/opflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions opflags/opflags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions opflags/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit c894a54

Please sign in to comment.