pulumi/pkg/util/assert.go
joeduffy 652305686d Add some simple assertion functions
This introduces three assertion functions:

* util.Assert: simply asserts a boolean condition, ripping the process using
  glog should it fail, with a stock message.

* util.AssertM: asserts a boolean condition, also using glog if it fails,
  but it comes with a message to help with debugging too.

* util.AssertMF: the same, except it formats the message with arguments.
2016-11-19 10:17:44 -08:00

29 lines
479 B
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package util
import (
"fmt"
"github.com/golang/glog"
)
const assertFailure = "An assertion has failed"
func Assert(cond bool) {
if !cond {
glog.Fatal(assertFailure)
}
}
func AssertM(cond bool, msg string) {
if !cond {
glog.Fatalf("%v: %v", assertFailure, msg)
}
}
func AssertMF(cond bool, msg string, args ...interface{}) {
if !cond {
glog.Fatalf("%v: %v", assertFailure, fmt.Sprintf(msg, args...))
}
}