Files
api_tmpl/internal/handlers/grpc/main_test.go
T
FernandoJVideira c4ee0ce4dc chore: rename simple_bank to api_tmpl and clean up for template use
Rename the module, proto service, and all identifiers from simple_bank/
SimpleBank to api_tmpl/ApiTmpl, and regenerate the gRPC/gateway/swagger/
mock code accordingly.

- Scrub real secrets (SMTP password, auth token secret) from api.env/
  api_test.env, untrack them, and add api.env.example/api_test.env.example
- Remove committed build artifacts (tmp/main, tmp/build-errors.log,
  dbml-error.log) and gitignore them going forward
- Fix Dockerfile paths (build target, migrations copy) that referenced a
  stale project layout
- Rewrite README to match the actual cmd/ + internal/ structure and add a
  "using this as a template" section
2026-08-25 03:02:37 +01:00

47 lines
1.3 KiB
Go

package gapi
import (
"context"
"fmt"
"testing"
"time"
"github.com/FernandoJVideira/api_tmpl/internal/auth"
"github.com/FernandoJVideira/api_tmpl/internal/config"
db "github.com/FernandoJVideira/api_tmpl/internal/db/sqlc"
"github.com/FernandoJVideira/api_tmpl/internal/service"
"github.com/FernandoJVideira/api_tmpl/internal/worker"
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
)
func newTestServer(t *testing.T, store db.Store, td worker.TaskDistributor, userService service.UserService, authService service.AuthService) *Server {
config := config.Config{
AuthTokenExp: time.Minute,
AllowedOrigins: []string{
"*",
},
}
tokenMaker, err := auth.NewPasetoMaker(config)
require.NoError(t, err)
server, err := NewServer(config, store, td, tokenMaker, userService, authService)
require.NoError(t, err)
return server
}
func newContextWithBearerToken(t *testing.T, tokenMaker auth.Maker, username string, role string, duration time.Duration) context.Context {
authToken, _, err := tokenMaker.CreateToken(username, role, duration)
require.NoError(t, err)
bearerToken := fmt.Sprintf("%s %s", authTypeBearer, authToken)
md := metadata.MD{
authHeaderKey: []string{
bearerToken,
},
}
return metadata.NewIncomingContext(context.Background(), md)
}