Home / File/ stub_test.go — fiber Source File

stub_test.go — fiber Source File

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

File go 1 imports

Entity Profile

Dependency Diagram

graph LR
  43203cc2_ef88_b7a8_d829_7d5f91268fe9["stub_test.go"]
  cc7104af_aece_1fe5_3985_791c7f34910c["context"]
  43203cc2_ef88_b7a8_d829_7d5f91268fe9 --> cc7104af_aece_1fe5_3985_791c7f34910c
  style 43203cc2_ef88_b7a8_d829_7d5f91268fe9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package idempotency

import (
	"context"
	"time"
)

// stubLock implements Locker for testing purposes.
type stubLock struct {
	lockErr   error
	unlockErr error
	afterLock func()
}

func (s *stubLock) Lock(string) error {
	if s.afterLock != nil {
		s.afterLock()
	}
	return s.lockErr
}
func (s *stubLock) Unlock(string) error { return s.unlockErr }

// stubStorage implements fiber.Storage for testing.
type stubStorage struct {
	data     map[string][]byte
	getErr   error
	setErr   error
	setCount int
}

func (s *stubStorage) Get(key string) ([]byte, error) {
	if s.getErr != nil {
		return nil, s.getErr
	}
	if s.data == nil {
		return nil, nil
	}
	return s.data[key], nil
}

func (s *stubStorage) GetWithContext(_ context.Context, key string) ([]byte, error) {
	// Call Get method to avoid code duplication
	return s.Get(key)
}

func (s *stubStorage) Set(key string, val []byte, _ time.Duration) error {
	if s.setErr != nil {
		return s.setErr
	}
	if s.data == nil {
		s.data = make(map[string][]byte)
	}
	s.data[key] = val
	s.setCount++
	return nil
}

func (s *stubStorage) SetWithContext(_ context.Context, key string, val []byte, _ time.Duration) error {
	// Call Set method to avoid code duplication
	return s.Set(key, val, 0)
}

func (s *stubStorage) Delete(key string) error {
	if s.data != nil {
		delete(s.data, key)
	}
	return nil
}

func (s *stubStorage) DeleteWithContext(_ context.Context, key string) error {
	// Call Delete method to avoid code duplication
	return s.Delete(key)
}

func (s *stubStorage) Reset() error {
	s.data = make(map[string][]byte)
	return nil
}

func (s *stubStorage) ResetWithContext(_ context.Context) error {
	// Call Reset method to avoid code duplication
	return s.Reset()
}

func (*stubStorage) Close() error { return nil }

Dependencies

  • context

Frequently Asked Questions

What does stub_test.go do?
stub_test.go is a source file in the fiber codebase, written in go.
What does stub_test.go depend on?
stub_test.go imports 1 module(s): context.
Where is stub_test.go in the architecture?
stub_test.go is located at middleware/idempotency/stub_test.go (directory: middleware/idempotency).

Analyze Your Own Codebase

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

Try Supermodel Free