Ejemplo n.º 1
0
func TestParseError_nil(t *testing.T) {
	var code int
	var msg string

	err := store.StatusFound
	msgExpect := err.Error()

	code, msg = store.ParseError(nil)

	if code != http.StatusFound {
		t.Errorf("Incorrect status code. Expecting %d but get %d",
			http.StatusFound, code)
	}
	if msg != msgExpect {
		t.Errorf("Incorrect status message. Expecting %s but get %s",
			msgExpect, msg)
	}

}
Ejemplo n.º 2
0
func TestParseError_User(t *testing.T) {

	var code int
	var msg string
	userMsg := "Some user error"

	var err error = errors.New(userMsg)
	code, msg = store.ParseError(err)

	if code != http.StatusInternalServerError {
		t.Errorf("Incorrect status code. Expecting %d but get %d",
			http.StatusInternalServerError, code)
	}
	if msg != userMsg {
		t.Errorf("Incorrect status message. Expecting %s but get %s",
			userMsg, msg)
	}

	serr := store.ExpandError(err)
	if serr.Status != http.StatusInternalServerError {
		t.Errorf("Incorrect StoreError.Status. Expecting %#v but get %#v",
			http.StatusInternalServerError, serr.Status)
	}
	if serr.Code != http.StatusInternalServerError {
		t.Errorf("Incorrect StoreError.Code. Expecting %#v but get %#v",
			http.StatusInternalServerError, serr.Code)
	}
	if serr.ServerMsg != userMsg {
		t.Errorf("Incorrect StoreError.ServerMsg. Expecting %#v but get %#v",
			userMsg, serr.ServerMsg)
	}
	if serr.ClientMsg != userMsg {
		t.Errorf("Incorrect StoreError.ClientMsg. Expecting %#v but get %#v",
			userMsg, serr.ClientMsg)
	}
	if serr.DeveloperMsg != "" {
		t.Errorf("Incorrect StoreError.DeveloperMsg. Expecting %#v but get %#v",
			"", serr.DeveloperMsg)
	}

}
Ejemplo n.º 3
0
func TestParseError_Singletons(t *testing.T) {

	var code int
	var msg string

	var err error = store.ErrorNotFound
	msgExpect := err.Error()

	code, msg = store.ParseError(err)
	if code != http.StatusNotFound {
		t.Errorf("Incorrect status code. Expecting %d but get %d",
			http.StatusNotFound, code)
	}
	if msg != msgExpect {
		t.Errorf("Incorrect status message. Expecting %s but get %s",
			msgExpect, msg)
	}

	serr := store.ExpandError(err)
	if serr.Status != http.StatusNotFound {
		t.Errorf("Incorrect StoreError.Status. Expecting %#v but get %#v",
			http.StatusNotFound, serr.Status)
	}
	if serr.Code != http.StatusNotFound {
		t.Errorf("Incorrect StoreError.Code. Expecting %#v but get %#v",
			http.StatusNotFound, serr.Code)
	}
	if serr.ServerMsg != msgExpect {
		t.Errorf("Incorrect StoreError.ServerMsg. Expecting %#v but get %#v",
			msgExpect, serr.ServerMsg)
	}
	if serr.ClientMsg != msgExpect {
		t.Errorf("Incorrect StoreError.ClientMsg. Expecting %#v but get %#v",
			msgExpect, serr.ClientMsg)
	}
	if serr.DeveloperMsg != "" {
		t.Errorf("Incorrect StoreError.DeveloperMsg. Expecting %#v but get %#v",
			"", serr.DeveloperMsg)
	}

}
Ejemplo n.º 4
0
func TestError(t *testing.T) {
	estatus, ecode, emsg := testErrorCode()
	var err error = store.Error(ecode, emsg)
	code, msg := store.ParseError(err)

	if code != ecode {
		t.Errorf("code output not correct. Expect %#v but get %#v",
			ecode, code)
	}
	if msg != emsg {
		t.Errorf("msg output not correct. Expect %#v but get %#v",
			emsg, msg)
	}

	serr := store.ExpandError(err)
	if serr.Status != estatus {
		t.Errorf("Incorrect StoreError.Status. Expecting %#v but get %#v",
			estatus, serr.Status)
	}
	if serr.Code != ecode {
		t.Errorf("Incorrect StoreError.Code. Expecting %#v but get %#v",
			ecode, serr.Code)
	}
	if serr.ServerMsg != emsg {
		t.Errorf("Incorrect StoreError.ServerMsg. Expecting %#v but get %#v",
			emsg, serr.ServerMsg)
	}
	if serr.ClientMsg != emsg {
		t.Errorf("Incorrect StoreError.ClientMsg. Expecting %#v but get %#v",
			emsg, serr.ClientMsg)
	}
	if serr.DeveloperMsg != "" {
		t.Errorf("Incorrect StoreError.DeveloperMsg. Expecting %#v but get %#v",
			"", serr.DeveloperMsg)
	}

}