diff options
Diffstat (limited to 'comm/commget_test.go')
| -rw-r--r-- | comm/commget_test.go | 50 |
1 files changed, 13 insertions, 37 deletions
diff --git a/comm/commget_test.go b/comm/commget_test.go index 62f4a2b..0845fb9 100644 --- a/comm/commget_test.go +++ b/comm/commget_test.go @@ -1,7 +1,7 @@ /* * @Author: your name * @Date: 2020-12-02 17:09:14 - * @LastEditTime: 2021-01-04 16:00:18 + * @LastEditTime: 2021-01-05 17:25:02 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: /commdetection/preprocessing/commget_test.go @@ -16,39 +16,12 @@ import ( ) func TestGetCommands(t *testing.T) { - t.Run("Get Commands From File Test", func(t *testing.T) { - commands := GetCommands("/root/.bash_history", "") - runCommands(commands, t) - }) - - t.Run("Get Commands From Net Test", func(t *testing.T) { - commands := GetCommands("", "http://127.0.0.1:8080") - runCommands(commands, t) - }) - - t.Run("Get commands from incorrect file test", func(t *testing.T) { - commands := GetCommands("/root/aaa", "") - runCommands(commands, t) - }) - - t.Run("Get commands from no-existence file test", func(t *testing.T) { - commands := GetCommands("dsfa", "") - runCommands(commands, t) - }) - - t.Run("Get commands from no-existence net", func(t *testing.T) { - commands := GetCommands("", "sdfsagd") - runCommands(commands, t) - }) - - t.Run("Get commands from nothing", func(t *testing.T) { - commands := GetCommands("", "") - runCommands(commands, t) - }) - - t.Run("Get Commands from Both Test", func(t *testing.T) { - commands := GetCommands("/root/.bash_history", "http://127.0.0.1:8080") - runCommands(commands, t) + t.Run("Get Commands From history Test", func(t *testing.T) { + commands, err := GetCommandsFromHist() + if err != nil { + t.Error(err) + } + checkCommands(commands, t) }) } @@ -76,12 +49,12 @@ func TestSplitCommandsInLine(t *testing.T) { if !reflect.DeepEqual(commands, predict) { fmt.Println(commands) fmt.Println(predict) - t.Errorf("results are not as predicted") + t.Log("result is not as predicted") } }) } -func runCommands(commands []Command, t *testing.T) { +func checkCommands(commands []Command, t *testing.T) { for commNum, command := range commands { if command.CommName == "" { t.Errorf("command %d is empty", commNum) @@ -91,9 +64,12 @@ func runCommands(commands []Command, t *testing.T) { t.Errorf("command %d: %s flag %d is empty", commNum+1, command.CommName, flagNum) } } + if command.TimeStamp.Unix() <= 0.0 { + t.Errorf("command %d: %s timestamp is empty", commNum+1, command.CommName) + } } } func BenchmarkGetCommands(b *testing.B) { - GetCommands("/root/.bash_history", "") + GetCommands() } |
