@@ -18,36 +18,35 @@ func (p *testProtocol) Probe(target string) (string, string, error) {
1818}
1919
2020func TestProbeValidate (t * testing.T ) {
21- protocols := []Protocol {& testProtocol {}}
21+ proto := & testProtocol {}
22+ logger := slog .Default ()
23+ reportCh := make (chan * Report )
24+ defer close (reportCh )
2225 t .Run ("returns nil with valid setup" , func (t * testing.T ) {
23- reportCh := make (chan * Report )
24- defer close (reportCh )
25- p := Probe {
26- Protocols : protocols , Logger : slog .Default (), ReportCh : reportCh ,
27- }
26+ p := Probe {Proto : proto , Logger : logger , ReportCh : reportCh }
2827 err := p .validate ()
2928 if err != nil {
3029 t .Fatalf ("got %q, want nil" , err )
3130 }
3231 })
33- t .Run ("returns an error if 'Protocols ' is nil" , func (t * testing.T ) {
32+ t .Run ("returns an error if 'Proto ' is nil" , func (t * testing.T ) {
3433 p := Probe {}
3534 err := p .validate ()
36- want := "required property: Protocols "
35+ want := "required property: Proto "
3736 if err .Error () != want {
3837 t .Fatalf ("got %q, want %q" , err , want )
3938 }
4039 })
4140 t .Run ("returns an error if 'Logger' is nil" , func (t * testing.T ) {
42- p := Probe {Protocols : protocols }
41+ p := Probe {Proto : proto }
4342 err := p .validate ()
4443 want := "required property: Logger"
4544 if err .Error () != want {
4645 t .Fatalf ("got %q, want %q" , err , want )
4746 }
4847 })
4948 t .Run ("returns an error if 'ReportCh' is nil" , func (t * testing.T ) {
50- p := Probe {Protocols : protocols , Logger : slog . Default () }
49+ p := Probe {Proto : proto , Logger : logger }
5150 err := p .validate ()
5251 want := "required property: ReportCh"
5352 if err .Error () != want {
@@ -60,29 +59,29 @@ func TestProbeDo(t *testing.T) {
6059 t .Run ("returns an error if the setup is invalid" , func (t * testing.T ) {
6160 p := Probe {}
6261 err := p .Do (context .Background ())
63- want := "invalid setup: required property: Protocols "
62+ want := "invalid setup: required property: Proto "
6463 if err .Error () != want {
6564 t .Fatalf ("got %q, want %q" , err , want )
6665 }
6766 })
68- protocols := [] Protocol { & testProtocol {} }
67+ protocol := & testProtocol {}
6968 t .Run ("sends back the report in the channel" , func (t * testing.T ) {
7069 reportCh := make (chan * Report )
7170 defer close (reportCh )
7271 p := Probe {
73- Protocols : protocols ,
74- Count : 2 ,
75- Logger : slog .Default (),
76- ReportCh : reportCh ,
72+ Proto : & testProtocol {} ,
73+ Count : 2 ,
74+ Logger : slog .Default (),
75+ ReportCh : reportCh ,
7776 }
78- protoID := protocols [ 0 ] .String ()
77+ protoID := protocol .String ()
7978 go func (t * testing.T ) {
8079 for report := range p .ReportCh {
8180 if report .ProtocolID != protoID {
8281 t .Errorf ("got %q, want %q" , report .ProtocolID , protoID )
8382 }
84- if report .RHost != testHostPort {
85- t .Errorf ("got %q, want %q" , report .RHost , testHostPort )
83+ if report .Target != testHostPort {
84+ t .Errorf ("got %q, want %q" , report .Target , testHostPort )
8685 }
8786 if report .Time == 0 {
8887 t .Errorf ("got %q, want > 0" , report .Time )
@@ -101,7 +100,7 @@ func TestProbeDo(t *testing.T) {
101100 reportCh := make (chan * Report )
102101 defer close (reportCh )
103102 p := Probe {
104- Protocols : protocols , Logger : slog .Default (), ReportCh : reportCh ,
103+ Proto : protocol , Logger : slog .Default (), ReportCh : reportCh ,
105104 }
106105 ctx , cancel := context .WithCancel (context .Background ())
107106 cancel ()
0 commit comments