-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathmain_test.go
More file actions
41 lines (33 loc) · 1.09 KB
/
main_test.go
File metadata and controls
41 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gapi
import (
"context"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
db "github.com/techschool/simplebank/db/sqlc"
"github.com/techschool/simplebank/token"
"github.com/techschool/simplebank/util"
"github.com/techschool/simplebank/worker"
"google.golang.org/grpc/metadata"
)
func newTestServer(t *testing.T, store db.Store, taskDistributor worker.TaskDistributor) *Server {
config := util.Config{
TokenSymmetricKey: util.RandomString(32),
AccessTokenDuration: time.Minute,
}
server, err := NewServer(config, store, taskDistributor)
require.NoError(t, err)
return server
}
func newContextWithBearerToken(t *testing.T, tokenMaker token.Maker, username string, role string, duration time.Duration, tokenType token.TokenType) context.Context {
accessToken, _, err := tokenMaker.CreateToken(username, role, duration, tokenType)
require.NoError(t, err)
bearerToken := fmt.Sprintf("%s %s", authorizationBearer, accessToken)
md := metadata.MD{
authorizationHeader: []string{
bearerToken,
},
}
return metadata.NewIncomingContext(context.Background(), md)
}