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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* @Author: EnderByEndera
* @Date: 2020-12-16 14:31:00
* @LastEditTime: 2021-01-11 10:26:26
* @LastEditors: Please set LastEditors
* @Description: Test marshalling.go
* @FilePath: /commdetection/rules/marshalling_test.go
*/
package model
import (
"encoding/json"
"reflect"
"testing"
)
func TestMarshalSensitiveCommSetting(t *testing.T) {
scomms := SComms{
{
Comm: "wget",
Coefficient: 0.8,
},
{
Comm: "apt",
Coefficient: 1.0,
},
}
err := MarshalSensitiveCommSetting(scomms)
if err != nil {
t.Error(err)
}
jsonBuf, _ := json.Marshal(scomms)
if jsonBuf == nil {
t.Errorf("results are not as predicted")
}
}
func TestUnmarshalSensitiveCommSetting(t *testing.T) {
scomms, err := UnmarshalSensitiveCommSetting()
if err != nil {
t.Error(err)
}
predict := SComms{{Comm: "wget", Coefficient: 0.8}, {Comm: "apt", Coefficient: 1}}
if !reflect.DeepEqual(scomms, predict) {
t.Errorf("results are not as predicted")
}
}
func TestMarshalSensitivePathSetting(t *testing.T) {
spaths := SPaths{
{
Path: "/root/go/src/commdetection",
Coefficient: 0.7,
},
}
err := MarshalSensitivePathSetting(spaths)
if err != nil {
t.Error(err)
}
jsonBuf, _ := json.Marshal(spaths)
if jsonBuf == nil {
t.Errorf("results are not as predicted")
}
}
func TestUnmarshalSensitivePathSetting(t *testing.T) {
spaths, err := UnmarshalSensitivePathSetting()
if err != nil {
t.Error(err)
}
predict := SPaths{
{
Path: "/root/go/src/commdetection",
Coefficient: 0.7,
},
}
if !reflect.DeepEqual(spaths, predict) {
t.Errorf("results are not as predicted")
}
}
|