Пример #1
0
func exitWithDefaultError(err error) {
	log.Error(err)
	fmt.Println(bosh.BuildDefaultErrorResponse(err, false, responseLogBuffer.String()))
	responseLogBuffer.Reset()
	os.Exit(1)
}
import (
	"encoding/json"
	"errors"

	"github.com/rackhd/rackhd-cpi/bosh"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("response handling", func() {
	Describe("exiting with a default error", func() {
		It("wraps errors in a CpiResponse", func() {
			testErrMsg := "a test error"
			testErr := errors.New(testErrMsg)
			errResp := bosh.BuildDefaultErrorResponse(testErr, false, "")
			errRespBytes := []byte(errResp)

			targetResponse := bosh.CpiResponse{}
			err := json.Unmarshal(errRespBytes, &targetResponse)
			Expect(err).ToNot(HaveOccurred())

			Expect(targetResponse.Result).To(BeNil())
			Expect(targetResponse.Log).To(BeEmpty())

			targetResponseErr := targetResponse.Error
			Expect(targetResponseErr.Type).To(Equal(bosh.DefaultErrorType))
			Expect(targetResponseErr.Message).To(Equal(testErrMsg))
			Expect(targetResponseErr.Retryable).To(BeFalse())
		})
	})