-
Notifications
You must be signed in to change notification settings - Fork 0
/
greynoise_test.go
55 lines (43 loc) · 1.13 KB
/
greynoise_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
package main
import (
"context"
"testing"
)
type GNoiseMock struct{}
func (f *GNoiseMock) ParseLogFiles(directory string, days int) (map[string]string, error) {
return map[string]string{"1.1.1.1": "1.1.1.1"}, nil
}
func (f *GNoiseMock) IPLookup(ctx context.Context, ip string) (*GNoiseResponse, error) {
return &GNoiseResponse{
IP: "1.1.1.1",
Noise: true,
Riot: false,
Classification: "malicious",
Name: "Shit face",
Link: "dat link tho",
LastSeen: "never",
}, nil
}
func TestParseLogFiles(t *testing.T) {
gn := &GNoise{}
// need to update creation date of test file everytime this code runs :(
ips, err := gn.ParseLogFiles("./testdata", 30)
if err != nil {
t.Fatal(err)
}
l := len(ips)
if l != 18 {
t.Errorf("Amount of IPs is incorrect, expected %d, got %d", 18, l)
}
}
func TestCheckNoise(t *testing.T) {
ctx := context.Background()
gn := &GNoiseMock{}
result, err := CheckNoise(ctx, gn, "some dir", 1337)
if err != nil {
t.Fatal(err)
}
if result.AmountOfNoise != 1 {
t.Errorf("expected amount of noise = %d, got %d", 1, result.AmountOfNoise)
}
}