-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
77 lines (60 loc) · 1.98 KB
/
main_test.go
File metadata and controls
77 lines (60 loc) · 1.98 KB
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
package main
import (
"strings"
"testing"
)
func TestGetTopCommandsGenericUsecase(t *testing.T) {
shellCommands := getMockShellCommands()
topCommandsCount := 3
commands := getTopCommands(shellCommands, topCommandsCount)
if len(commands) != topCommandsCount {
t.Errorf("Commands count differs from %d, commands = %s", topCommandsCount, commands)
}
commandThree := commands[0]
if !strings.Contains(commandThree.command, "three") {
t.Errorf("Wrong command, should be three, but %s", commandThree)
}
commandTwo := commands[1]
if !strings.Contains(commandTwo.command, "two") {
t.Errorf("Wrong command, should be two, but %s", commandTwo)
}
commandOne:= commands[2]
if !strings.Contains(commandOne.command, "one") {
t.Errorf("Wrong command, should be one, but %s", commandOne)
}
}
func TestTopCommandsCountIfFoundLess(t *testing.T) {
shellCommands := getMockShellCommands() //returns 6 commands, 3 different
topCommandsCount := 4 //more than actually provided
commands := getTopCommands(shellCommands, topCommandsCount)
if len(commands) != 3 {
t.Errorf("Only 3 different commands provided, " +
"requested top count is %d, " +
"commands size must be 3\n" +
"commands = %s",
topCommandsCount, commands)
}
}
func TestTopCommandsCountIfFoundMore(t *testing.T) {
shellCommands := getMockShellCommands() //returns 6 commands, 3 different
topCommandsCount := 2 //less than actually provided
commands := getTopCommands(shellCommands, topCommandsCount)
if len(commands) != topCommandsCount {
t.Errorf("Only 3 different commands provided, " +
"requested top count is %d, which is less," +
"commands size must be %d\n" +
"commands = %s",
topCommandsCount, topCommandsCount, commands)
}
}
func getMockShellCommands() <- chan string{
shellCommands := make(chan string, 6)
shellCommands <- "one"
shellCommands <- "two"
shellCommands <- "two"
shellCommands <- "three"
shellCommands <- "three"
shellCommands <- "three"
close(shellCommands)
return shellCommands
}