Browse Source

Do not accept a negative interval

Douglas Thrift 1 year ago
parent
commit
1e5350b9b0
3 changed files with 12 additions and 0 deletions
  1. 4 0
      config.go
  2. 5 0
      config_test.go
  3. 3 0
      tests/negative_interval.yml

+ 4 - 0
config.go

@@ -1,6 +1,7 @@
 package presence
 
 import (
+	"fmt"
 	"net"
 	"os"
 	"time"
@@ -36,6 +37,9 @@ func ParseConfig(name string) (*Config, error) {
 		return nil, err
 	}
 
+	if c.Interval < 0 {
+		return nil, fmt.Errorf("negative interval (%v)", c.Interval)
+	}
 	if c.Interval == 0 {
 		c.Interval = 30 * time.Second
 	}

+ 5 - 0
config_test.go

@@ -54,6 +54,11 @@ func TestParseConfig(t *testing.T) {
 			file: "bad_mac_encoding.yml",
 			err:  "address 00-00-00-00-00-0x: invalid MAC address",
 		},
+		{
+			name: "negative interval",
+			file: "negative_interval.yml",
+			err:  "negative interval (-1ns)",
+		},
 	}
 
 	for _, tc := range cases {

+ 3 - 0
tests/negative_interval.yml

@@ -0,0 +1,3 @@
+interval: -1ns
+mac_addresses:
+  - 00:00:00:00:00:0d