entropychecker.TestEntropyChecker   A
last analyzed

Complexity

Conditions 5

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nop 1
dl 0
loc 23
rs 9.0833
c 0
b 0
f 0
1
package entropychecker
2
3
import (
4
	"testing"
5
	"time"
6
)
7
8
func TestEntropyChecker(t *testing.T) {
9
	err := WaitForEntropy()
10
	if err != nil {
11
		t.Error(err)
12
		return
13
	}
14
15
	entropy, err := GetEntropy()
16
	if err != nil {
17
		t.Error(err)
18
		return
19
	}
20
21
	if entropy < MinimumEntropy {
22
		t.Error("Insufficient entropy not properly detected")
23
		return
24
	}
25
26
	Timeout = 0
27
	err = WaitForEntropy()
28
	if err != nil {
29
		t.Error(err)
30
		return
31
	}
32
}
33
34
func TestFailure(t *testing.T) {
35
	// Make sure we get a an error if we time out
36
	Timeout = 200 * time.Millisecond
37
	MinimumEntropy = 100000
38
	err := WaitForEntropy()
39
	if err == nil {
40
		t.Error("Should get error when timeout waited too long")
41
	}
42
43
	// Make sure an unspported OS returns an error (instead of unkown behavior)
44
	supportedOS = "unknown"
45
	Timeout = 10 * time.Second
46
	MinimumEntropy = 128
47
	_, err = GetEntropy()
48
	if err == nil {
49
		t.Error("Should get error when using unknown OS")
50
	}
51
	err = WaitForEntropy()
52
	if err == nil {
53
		t.Error("Should get error when using unknown OS")
54
	}
55
56
}
57