mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-25 19:17:10 +08:00
Conflicts: Gopkg.lock pkg/appsrv/appsrv.go pkg/cloudcommon/options.go pkg/compute/models/hosts.go pkg/compute/models/quotas.go pkg/compute/service/service.go pkg/mcclient/mcclient.go
64 lines
896 B
Go
64 lines
896 B
Go
package expect // import "github.com/anacrolix/missinggo/expect"
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
func Nil(x interface{}) {
|
|
if x != nil {
|
|
panic(fmt.Sprintf("expected nil; got %v", x))
|
|
}
|
|
}
|
|
|
|
func NotNil(x interface{}) {
|
|
if x == nil {
|
|
panic(x)
|
|
}
|
|
}
|
|
|
|
func Equal(x, y interface{}) {
|
|
if x == y {
|
|
return
|
|
}
|
|
yAsXType := reflect.ValueOf(y).Convert(reflect.TypeOf(x)).Interface()
|
|
if !reflect.DeepEqual(x, yAsXType) {
|
|
panic(fmt.Sprintf("%v != %v", x, y))
|
|
}
|
|
}
|
|
|
|
func StrictlyEqual(x, y interface{}) {
|
|
if x != y {
|
|
panic(fmt.Sprintf("%s != %s", x, y))
|
|
}
|
|
}
|
|
|
|
func OneRowAffected(r sql.Result) {
|
|
count, err := r.RowsAffected()
|
|
Nil(err)
|
|
if count != 1 {
|
|
panic(count)
|
|
}
|
|
}
|
|
|
|
func True(b bool) {
|
|
if !b {
|
|
panic(b)
|
|
}
|
|
}
|
|
|
|
var Ok = True
|
|
|
|
func False(b bool) {
|
|
if b {
|
|
panic(b)
|
|
}
|
|
}
|
|
|
|
func Zero(x interface{}) {
|
|
if x != reflect.Zero(reflect.TypeOf(x)).Interface() {
|
|
panic(x)
|
|
}
|
|
}
|