1
2
3
4
5 package fips_test
6
7 import (
8 "crypto/internal/fips"
9 "testing"
10 )
11
12 func TestIndicator(t *testing.T) {
13 fips.ResetServiceIndicator()
14 if fips.ServiceIndicator() {
15 t.Error("indicator should be false if no calls are made")
16 }
17
18 fips.ResetServiceIndicator()
19 fips.RecordApproved()
20 if !fips.ServiceIndicator() {
21 t.Error("indicator should be true if RecordApproved is called")
22 }
23
24 fips.ResetServiceIndicator()
25 fips.RecordApproved()
26 fips.RecordApproved()
27 if !fips.ServiceIndicator() {
28 t.Error("indicator should be true if RecordApproved is called multiple times")
29 }
30
31 fips.ResetServiceIndicator()
32 fips.RecordNonApproved()
33 if fips.ServiceIndicator() {
34 t.Error("indicator should be false if RecordNonApproved is called")
35 }
36
37 fips.ResetServiceIndicator()
38 fips.RecordApproved()
39 fips.RecordNonApproved()
40 if fips.ServiceIndicator() {
41 t.Error("indicator should be false if both RecordApproved and RecordNonApproved are called")
42 }
43
44 fips.ResetServiceIndicator()
45 fips.RecordNonApproved()
46 fips.RecordApproved()
47 if fips.ServiceIndicator() {
48 t.Error("indicator should be false if both RecordNonApproved and RecordApproved are called")
49 }
50
51 fips.ResetServiceIndicator()
52 fips.RecordNonApproved()
53 done := make(chan struct{})
54 go func() {
55 fips.ResetServiceIndicator()
56 fips.RecordApproved()
57 close(done)
58 }()
59 <-done
60 if fips.ServiceIndicator() {
61 t.Error("indicator should be false if RecordApproved is called in a different goroutine")
62 }
63
64 fips.ResetServiceIndicator()
65 fips.RecordApproved()
66 done = make(chan struct{})
67 go func() {
68 fips.ResetServiceIndicator()
69 fips.RecordNonApproved()
70 close(done)
71 }()
72 <-done
73 if !fips.ServiceIndicator() {
74 t.Error("indicator should be true if RecordNonApproved is called in a different goroutine")
75 }
76 }
77
View as plain text