Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

echonext-testing

/echonext-testing

Pisze testy API EchoNext z helperami APIClient, Suite i FixtureManager do żądań w procesie, przygotowania środowiska i danych testowych.

Repozytorium
echonext ↗
Licencja
MIT
Ostatnia zmiana repozytorium
26.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 26.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pisze testy API EchoNext z helperami APIClient, Suite i FixtureManager do żądań w procesie, przygotowania środowiska i danych testowych.

Oryginalny opis (EN)

Write tests for EchoNext APIs using the pkg/contrib/testing helpers — APIClient for in-process HTTP requests, Suite for setup/teardown, and FixtureManager for seeding test data. Use when writing or fixing tests for echonext handlers, services, or endpoints.

Jak działa

  1. APIClient — request an endpoint
  2. Suite — app + DB + fixtures with lifecycle
  3. FixtureManager — standalone data seeding
  4. Running tests
  5. Checklist
Sekcje z nagłówków SKILL.md, w oryginale · 122 linii, 426 słów
Podgląd SKILL.md
---
name: echonext-testing
description: >-
  Write tests for EchoNext APIs using the pkg/contrib/testing helpers —
  APIClient for in-process HTTP requests, Suite for setup/teardown, and
  FixtureManager for seeding test data. Use when writing or fixing tests for
  echonext handlers, services, or endpoints.
license: MIT
metadata:
  version: 0.1.0
---

# EchoNext Testing

`pkg/contrib/testing` provides in-process HTTP testing for echonext apps: build
your `*echonext.App`, drive it with an `APIClient` (no real network), and assert
on typed responses. A `Suite` bundles the app, DB, client, and fixtures with
setup/teardown.

## APIClient — request an endpoint

```go
import (
    "testing"

    echotest "github.com/abdussamadbello/echonext/pkg/contrib/testing"
)

func TestCreateTodo(t *testing.T) {
    app := buildApp() // your function that wires routes onto echonext.New()
    client := echotest.NewAPIClient(app)

    resp := client.POST("/todos", map[string]any{"title": "write tests"})
    if resp.Status() != 201 {
        t.Fatalf("got %d: %s", resp.Status(), resp.String())
    }

    var out struct {
        Data    Todo `json:"data"`
        Success bool `json:"success"`
    }
    if err := resp.JSON(&out); err != nil {
        t.Fatal(err)
    }
    if out.Data.Title != "write tests" {
        t.Fatalf("unexpected title: %q", out.Data.Title)
    }
}
```

`APIClient` methods:

- Requests: `GET(path)`, `POST(path, body)`, `PUT(path, body)`,
  `PATCH(path, body)`, `DELETE(path)` — each returns a `*Response`.
- Chainable setup: `WithHeader(key, value)`, `WithAuth(token)` (Bearer),
  `WithBasicAuth(user, pass)`.
- `*Response`: `Status() int`, `JSON(target any) error`, `String() string`,
  `Error() error`.

Remember responses are wrapped in `Response[T]` — decode into a struct with
`Data`/`Success`/`Error` fields (see the `echonext-handlers` skill).

### Authenticated requests

```go
resp := client.
    WithAuth("test-jwt").
    GET("/me")
```

## Suite — app + DB + fixtures with lifecycle

```go
func TestUsersSuite(t *testing.T) {
    app := buildApp()
    db := openTestDB(t) // *gorm.DB, e.g. in-memory sqlite

    s := echotest.NewSuite(app, db)
    if err := s.Setup(); err != nil {
        t.Fatal(err)
    }
    defer s.Teardown()

    // Seed rows for this test:
    if err := s.LoadFixtures(
        &User{ID: 1, Email: "a@example.com"},
        &User{ID: 2, Email: "b@example.com"},
    ); err != nil {
        t.Fatal(err)
    }

    resp := s.Client.GET("/users")           // shared client
    authed := s.WithAuth("token").GET("/me") // per-request auth
    _ = authed
    if resp.Status() != 200 {
        t.Fatalf("got %d", resp.Status())
    }
}
```

`Suite` fields: `App`, `DB`, `Client *APIClient`, `Fixtures *FixtureManager`.
Methods: `Setup()`, `Teardown()`, `LoadFixtures(records ...any)`,
`WithAuth(token) *APIClient`.

## FixtureManager — standalone data seeding

When you don't need a full suite:

```go
fm := echotest.NewFixtureManager(db)
fm.Load(&User{ID: 1, Email: "a@example.com"}) // insert one/several records
fm.LoadMany(users)                            // insert a slice
fm.ClearTable("users")                        // truncate one table
fm.ClearAll()                                 // clear all known fixtures
```

## Running tests

```bash
echonext test                 # framework test runner
echonext test -- -run TestX   # pass-through flags after --
go test ./...                 # or plain Go
```

## Checklist

- Build the same `*echonext.App` your `main` builds, then `NewAPIClient(app)`.
- Decode into a `{ Data, Success, Error }` wrapper, not the bare model.
- Assert on `resp.Status()`; print `resp.String()` on failure for context.
- Use a `Suite` when you need a DB + fixtures + teardown; otherwise just the
  `APIClient`.
- Seed test data with fixtures, not `echonext db seed`.

Wersje

W bazie nie ma innych skilli o nazwie echonext-testing.

Migawka bazy z 13.11.2026 · wersja paczki 906fe60f4060 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100echonext-handlers
    Tworzy i rejestruje typowane handlery HTTP EchoNext wraz ze strukturami żądań, tagami walidacji i trasami GET, POST, PUT, PATCH i DELETE.
  • 100echonext-database
    Pomaga pracować z warstwą bazy danych EchoNext: modele GORM, generyczne repozytorium Repository[T] oraz migracje i seedy Atlas przez CLI.
  • 95pytest-django
    Obsługuje testy integracyjne Django w pytest-django: fixtures db, client i settings, DRF APIClient, factory_boy, widoki async, sygnały, komendy zarządzania i testy wielu baz.
  • 100api-test-suite-builder
    Generuje testy API, zestawy testów integracyjnych, testy endpointów REST i testy kontraktowe.
  • 95testing
    Podaje wzorce testów opartych na zachowaniu: pisanie testów, fabryki danych testowych, struktura plików testowych i decyzje o tym, co testować.
  • 100networking-and-server-state
    Buduje stan serwera w TanStack Query na ApiClient: walidowane odpowiedzi, klucze, ponowienia, optymistyczne zapisy i obsługę trybu offline.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.