From c894a547fc49e5dcfcac5fc53c6ce83efafbabf6 Mon Sep 17 00:00:00 2001 From: Tommaso Gragnato Date: Thu, 28 Nov 2024 01:38:35 +0100 Subject: [PATCH] test(opflags): write more test cases for OpFlags.check() --- opflags/opflags.go | 5 +++++ opflags/opflags_test.go | 21 +++++++++++++++++++++ opflags/parsers.go | 5 ----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/opflags/opflags.go b/opflags/opflags.go index 9f10d9c5..ca9e7e48 100644 --- a/opflags/opflags.go +++ b/opflags/opflags.go @@ -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 { diff --git a/opflags/opflags_test.go b/opflags/opflags_test.go index 64371943..62d4f326 100644 --- a/opflags/opflags_test.go +++ b/opflags/opflags_test.go @@ -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 { diff --git a/opflags/parsers.go b/opflags/parsers.go index e7fe2126..cd585284 100644 --- a/opflags/parsers.go +++ b/opflags/parsers.go @@ -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() }