This repository has been archived on 2021-09-07. You can view files and clone it, but cannot push or open issues or pull requests.
2017-12-31 20:57:02 +03:00

29 lines
700 B
Go

package singleton
import "testing"
func TestGetInstance(t *testing.T) {
firstCounter := GetInstance()
if firstCounter == nil {
t.Error("Expected pointer to Singleton after calling GetInstance(), not nil")
}
expectedCounter := firstCounter
count := firstCounter.AddOne()
if count != 1 {
t.Errorf("After calling for the first time to count, the count must be 1 but it is %d\n", count)
}
secondCounter := GetInstance()
if secondCounter != expectedCounter {
t.Error("Expected same counter in secondCounter but got different instance")
}
count = secondCounter.AddOne()
if count != 2 {
t.Errorf("After calling AddOne in second counter, count must be 2 but was $d\n", count)
}
}