github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/rule/tcp_port_test.go (about) 1 package rule 2 3 import "testing" 4 5 func TestTCPPortAvailableRuleValidation(t *testing.T) { 6 p := TCPPortAvailable{ProcName: "foo"} 7 if errs := p.Validate(); len(errs) != 1 { 8 t.Errorf("expected 1 error, but got %d", len(errs)) 9 } 10 p.Port = -1 11 if errs := p.Validate(); len(errs) != 1 { 12 t.Errorf("expected 1 error, but got %d", len(errs)) 13 } 14 p.Port = 901283 15 if errs := p.Validate(); len(errs) != 1 { 16 t.Errorf("expected 1 error, but got %d", len(errs)) 17 } 18 p.Port = 1024 19 if errs := p.Validate(); len(errs) != 0 { 20 t.Errorf("expected 0 error, but got %d", len(errs)) 21 } 22 p.ProcName = "" 23 if errs := p.Validate(); len(errs) != 1 { 24 t.Errorf("expected 1 error, but got %d", len(errs)) 25 } 26 } 27 28 func TestTCPPortAccessibleRuleValidation(t *testing.T) { 29 p := TCPPortAccessible{} 30 if errs := p.Validate(); len(errs) != 2 { 31 t.Errorf("expected 2 error, but got %d", len(errs)) 32 } 33 p.Port = -1 34 if errs := p.Validate(); len(errs) != 2 { 35 t.Errorf("expected 2 error, but got %d", len(errs)) 36 } 37 p.Port = 901283 38 if errs := p.Validate(); len(errs) != 2 { 39 t.Errorf("expected 2 error, but got %d", len(errs)) 40 } 41 p.Port = 1024 42 if errs := p.Validate(); len(errs) != 1 { 43 t.Errorf("expected 1 error, but got %d", len(errs)) 44 } 45 p.Timeout = "nonDuration" 46 if errs := p.Validate(); len(errs) != 1 { 47 t.Errorf("expected 1 error, but got %d", len(errs)) 48 } 49 p.Timeout = "3s" 50 if errs := p.Validate(); len(errs) != 0 { 51 t.Errorf("expected 0 error, but got %d", len(errs)) 52 } 53 }