Home / File/ idempotency_test.go — fiber Source File

idempotency_test.go — fiber Source File

Architecture documentation for idempotency_test.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberCore Adapters 1 imports 16 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  94a179ed_b8df_d669_56a8_8e55d7bbb6bf["idempotency_test.go"]
  fcef1725_af89_d6cd_36cd_b228cdcc5acd["errors"]
  94a179ed_b8df_d669_56a8_8e55d7bbb6bf --> fcef1725_af89_d6cd_36cd_b228cdcc5acd
  style 94a179ed_b8df_d669_56a8_8e55d7bbb6bf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package idempotency

import (
	"errors"
	"fmt"
	"io"
	"net/http"
	"net/http/httptest"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
	"testing"
	"time"

	"github.com/gofiber/fiber/v3"
	"github.com/valyala/fasthttp"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

const validKey = "00000000-0000-0000-0000-000000000000"

// go test -run Test_Idempotency
func Test_Idempotency(t *testing.T) {
	t.Parallel()
	app := fiber.New()

	app.Use(func(c fiber.Ctx) error {
		if err := c.Next(); err != nil {
			return err
		}

		isMethodSafe := fiber.IsMethodSafe(c.Method())
		isIdempotent := IsFromCache(c) || WasPutToCache(c)
		hasReqHeader := c.Get("X-Idempotency-Key") != ""

		if isMethodSafe {
			if isIdempotent {
				return errors.New("request with safe HTTP method should not be idempotent")
			}
		} else {
			// Unsafe
			if hasReqHeader {
				if !isIdempotent {
					return errors.New("request with unsafe HTTP method should be idempotent if X-Idempotency-Key request header is set")
				}
			} else if isIdempotent {
				return errors.New("request with unsafe HTTP method should not be idempotent if X-Idempotency-Key request header is not set")
			}
		}

		return nil
	})

	// Needs to be at least a second as the memory storage doesn't support shorter durations.
	const lifetime = 2 * time.Second

	app.Use(New(Config{
// ... (400 more lines)

Domain

Subdomains

Classes

Dependencies

  • errors

Frequently Asked Questions

What does idempotency_test.go do?
idempotency_test.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in idempotency_test.go?
idempotency_test.go defines 16 function(s): Benchmark_Idempotency, Test_Idempotency, Test_New_HandlerError, Test_New_InvalidKey, Test_New_LockError, Test_New_NextSkip, Test_New_SecondPassReadError, Test_New_SkipCache_WhenBodyTooLarge, Test_New_StorageGetError, Test_New_StorageSetError, and 6 more.
What does idempotency_test.go depend on?
idempotency_test.go imports 1 module(s): errors.
Where is idempotency_test.go in the architecture?
idempotency_test.go is located at middleware/idempotency/idempotency_test.go (domain: FiberCore, subdomain: Adapters, directory: middleware/idempotency).

Analyze Your Own Codebase

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

Try Supermodel Free