Home / Function/ TestError() — gin Function Reference

TestError() — gin Function Reference

Architecture documentation for the TestError() function in errors_test.go from the gin codebase.

Entity Profile

Dependency Diagram

graph TD
  7c141130_dc8f_df42_ecc0_9705121c2c79["TestError()"]
  3582eb3f_bdf6_8b25_a7d8_18e77eefb341["Error()"]
  7c141130_dc8f_df42_ecc0_9705121c2c79 -->|calls| 3582eb3f_bdf6_8b25_a7d8_18e77eefb341
  style 7c141130_dc8f_df42_ecc0_9705121c2c79 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

errors_test.go lines 17–66

func TestError(t *testing.T) {
	baseError := errors.New("test error")
	err := &Error{
		Err:  baseError,
		Type: ErrorTypePrivate,
	}
	assert.Equal(t, err.Error(), baseError.Error())
	assert.Equal(t, H{"error": baseError.Error()}, err.JSON())

	assert.Equal(t, err.SetType(ErrorTypePublic), err)
	assert.Equal(t, ErrorTypePublic, err.Type)

	assert.Equal(t, err.SetMeta("some data"), err)
	assert.Equal(t, "some data", err.Meta)
	assert.Equal(t, H{
		"error": baseError.Error(),
		"meta":  "some data",
	}, err.JSON())

	jsonBytes, _ := json.API.Marshal(err)
	assert.JSONEq(t, "{\"error\":\"test error\",\"meta\":\"some data\"}", string(jsonBytes))

	err.SetMeta(H{ //nolint: errcheck
		"status": "200",
		"data":   "some data",
	})
	assert.Equal(t, H{
		"error":  baseError.Error(),
		"status": "200",
		"data":   "some data",
	}, err.JSON())

	err.SetMeta(H{ //nolint: errcheck
		"error":  "custom error",
		"status": "200",
		"data":   "some data",
	})
	assert.Equal(t, H{
		"error":  "custom error",
		"status": "200",
		"data":   "some data",
	}, err.JSON())

	type customError struct {
		status string
		data   string
	}
	err.SetMeta(customError{status: "200", data: "other data"}) //nolint: errcheck
	assert.Equal(t, customError{status: "200", data: "other data"}, err.JSON())
}

Domain

Subdomains

Calls

Frequently Asked Questions

What does TestError() do?
TestError() is a function in the gin codebase.
What does TestError() call?
TestError() calls 1 function(s): Error.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free