goProject/.svn/pristine/12/12f75adbec35d99e08a5f0ff52f0c36225adff02.svn-base
2025-01-06 16:21:36 +08:00

55 lines
966 B
Plaintext

package initMgr
import (
"fmt"
"testing"
)
func TestRegister(t *testing.T) {
Register("first", 1, first)
Register("second", 2, second)
Register("third", 3, third)
Register("fourth", 4, fourth)
}
func TestCallOne(t *testing.T) {
name := "first"
if err := CallOne(name); err != nil {
t.Errorf("there should be no error, but now it has:%s", err)
}
}
func TestCallAny(t *testing.T) {
errList := CallAny("second", "third")
if len(errList) != 1 {
t.Errorf("there should be 1 error, but now:%d", len(errList))
}
}
func TestCallAll(t *testing.T) {
errList := CallAll()
if len(errList) != 2 {
t.Errorf("there should be 1 error, but now:%d", len(errList))
}
}
func first() error {
fmt.Println("first")
return nil
}
func second() error {
fmt.Println("second")
return fmt.Errorf("the second error")
}
func third() error {
fmt.Println("third")
return nil
}
func fourth() error {
fmt.Println("fourth")
return fmt.Errorf("the fourth error")
}