feat: 0.0.1
This commit is contained in:
146 files changed
+10444
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package gapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/FernandoJVideira/simple_bank/internal/auth"
|
||||
"github.com/FernandoJVideira/simple_bank/internal/config"
|
||||
db "github.com/FernandoJVideira/simple_bank/internal/db/sqlc"
|
||||
"github.com/FernandoJVideira/simple_bank/internal/service"
|
||||
"github.com/FernandoJVideira/simple_bank/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)
|
||||
}
|
||||
Reference in new issue
Block a user