1
0
Fork 0

Add unit tests for package safe

Also fix a bug in the code found due to the tests.
This commit is contained in:
Ingo Gottwald 2017-04-30 14:39:49 +02:00 committed by Emile Vauge
parent eefcf026d2
commit 2f06f339ec
No known key found for this signature in database
GPG key ID: D808B4C167352E59
3 changed files with 196 additions and 6 deletions

24
safe/safe_test.go Normal file
View file

@ -0,0 +1,24 @@
package safe
import "testing"
func TestSafe(t *testing.T) {
const ts1 = "test1"
const ts2 = "test2"
s := New(ts1)
result, ok := s.Get().(string)
if !ok {
t.Fatalf("Safe.Get() failed, got type '%T', expected string", s.Get())
}
if result != ts1 {
t.Errorf("Safe.Get() failed, got '%s', expected '%s'", result, ts1)
}
s.Set(ts2)
result, ok = s.Get().(string)
if !ok {
t.Fatalf("Safe.Get() after Safe.Set() failed, got type '%T', expected string", s.Get())
}
if result != ts2 {
t.Errorf("Safe.Get() after Safe.Set() failed, got '%s', expected '%s'", result, ts2)
}
}