-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsssp_test.go
66 lines (52 loc) · 1.17 KB
/
sssp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package savdi_test
import (
"bufio"
"fmt"
"net"
"testing"
"github.com/rikkuness/go-savdi"
)
func createFakeClient() savdi.Client {
ln, _ := net.Listen("tcp", "127.0.0.1:0")
go func() {
defer ln.Close()
for {
server, _ := ln.Accept()
go func(c net.Conn) {
s := bufio.NewScanner(c)
for s.Scan() {
cmd := s.Text()
switch cmd {
case "BYE":
fmt.Fprintf(c, "BYE\n\n")
server.Close()
case "SSSP/1.0 QUERY ENGINE":
fmt.Fprintf(c, "engineversion: fake\nsavversion: fake\nviruscount: 1\n\n")
case "SSSP/1.0 SCANDATA":
fmt.Fprintf(c, "something\n\n")
}
}
}(server)
}
}()
client, _ := net.Dial("tcp", ln.Addr().String())
return savdi.Client{"SSSP/1.0", client}
}
func TestSSSPVersion(t *testing.T) {
sophos := createFakeClient()
defer sophos.Close()
if v := sophos.GetVersion(); v != "SSSP/1.0" {
t.Error("Did not get expected version")
}
}
func TestQueryEngine(t *testing.T) {
sophos := createFakeClient()
defer sophos.Close()
engine, err := sophos.QueryEngine()
if err != nil {
t.Error(err)
}
if engine.EngineVersion != "fake" {
t.Error("Failed to get the engine information")
}
}