Home / Function/ testETagCustomEtag() — fiber Function Reference

testETagCustomEtag() — fiber Function Reference

Architecture documentation for the testETagCustomEtag() function in etag_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  f5ae1489_9aae_9e31_2f73_0aae0211fe32["testETagCustomEtag()"]
  dfd9dd18_1de2_7880_57b0_aa8836ab099f["etag_test.go"]
  f5ae1489_9aae_9e31_2f73_0aae0211fe32 -->|defined in| dfd9dd18_1de2_7880_57b0_aa8836ab099f
  132cc850_aac1_7a68_7037_480c8b734596["Test_ETag_CustomEtag()"]
  132cc850_aac1_7a68_7037_480c8b734596 -->|calls| f5ae1489_9aae_9e31_2f73_0aae0211fe32
  style f5ae1489_9aae_9e31_2f73_0aae0211fe32 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/etag/etag_test.go lines 203–242

func testETagCustomEtag(t *testing.T, headerIfNoneMatch, matched bool) { //nolint:revive // We're in a test, so using bools as a flow-control is fine
	t.Helper()

	app := fiber.New()

	app.Use(New())

	app.Get("/", func(c fiber.Ctx) error {
		c.Set(fiber.HeaderETag, `"custom"`)
		if bytes.Equal(c.Request().Header.Peek(fiber.HeaderIfNoneMatch), []byte(`"custom"`)) {
			return c.SendStatus(fiber.StatusNotModified)
		}
		return c.SendString("Hello, World!")
	})

	req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
	if headerIfNoneMatch {
		etag := `"non-match"`
		if matched {
			etag = `"custom"`
		}
		req.Header.Set(fiber.HeaderIfNoneMatch, etag)
	}

	resp, err := app.Test(req)
	require.NoError(t, err)

	if !headerIfNoneMatch || !matched {
		require.Equal(t, fiber.StatusOK, resp.StatusCode)
		require.Equal(t, `"custom"`, resp.Header.Get(fiber.HeaderETag))
		return
	}

	if matched {
		require.Equal(t, fiber.StatusNotModified, resp.StatusCode)
		b, err := io.ReadAll(resp.Body)
		require.NoError(t, err)
		require.Empty(t, b)
	}
}

Domain

Subdomains

Frequently Asked Questions

What does testETagCustomEtag() do?
testETagCustomEtag() is a function in the fiber codebase, defined in middleware/etag/etag_test.go.
Where is testETagCustomEtag() defined?
testETagCustomEtag() is defined in middleware/etag/etag_test.go at line 203.
What calls testETagCustomEtag()?
testETagCustomEtag() is called by 1 function(s): Test_ETag_CustomEtag.

Analyze Your Own Codebase

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

Try Supermodel Free