Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4247fe7

Browse filesBrowse files
committed
all: Use test context
1 parent 2de5f7e commit 4247fe7
Copy full SHA for 4247fe7

42 files changed

+185-179Lines changed: 185 additions & 179 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkg/auth/rights/cache_test.go‎

Copy file name to clipboardExpand all lines: pkg/auth/rights/cache_test.go
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/smartystreets/assertions"
2323
"github.com/smartystreets/assertions/should"
2424
errors "go.thethings.network/lorawan-stack/pkg/errorsv3"
25+
"go.thethings.network/lorawan-stack/pkg/util/test"
2526
)
2627

2728
var currentTime time.Time
@@ -45,7 +46,7 @@ func TestCache(t *testing.T) {
4546

4647
mockFetcher.applicationError, mockFetcher.gatewayError, mockFetcher.organizationError = mockErr, mockErr, mockErr
4748

48-
ctxA := context.WithValue(context.Background(), "ctx", "A")
49+
ctxA := context.WithValue(test.Context(), "ctx", "A")
4950
res := fetchRights(ctxA, "foo", c)
5051

5152
a.So(mockFetcher.applicationCtx, should.Equal, ctxA)
@@ -58,7 +59,7 @@ func TestCache(t *testing.T) {
5859

5960
timeTravel(31 * time.Second) // Error responses should be cached for 1 minute.
6061

61-
ctxB := context.WithValue(context.Background(), "ctx", "B")
62+
ctxB := context.WithValue(test.Context(), "ctx", "B")
6263
res = fetchRights(ctxB, "foo", c)
6364

6465
a.So(mockFetcher.applicationCtx, should.Equal, ctxA)
Collapse file

‎pkg/auth/rights/fetcher_test.go‎

Copy file name to clipboardExpand all lines: pkg/auth/rights/fetcher_test.go
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/smartystreets/assertions/should"
2525
errors "go.thethings.network/lorawan-stack/pkg/errorsv3"
2626
"go.thethings.network/lorawan-stack/pkg/ttnpb"
27+
"go.thethings.network/lorawan-stack/pkg/util/test"
2728
"google.golang.org/grpc"
2829
"google.golang.org/grpc/metadata"
2930
)
@@ -112,7 +113,7 @@ func TestFetcherFunc(t *testing.T) {
112113
return fetcher.rights, fetcher.err
113114
})
114115

115-
res := fetchRights(context.Background(), "foo", f)
116+
res := fetchRights(test.Context(), "foo", f)
116117
a.So(res.AppErr, should.Resemble, fetcher.err)
117118
a.So(res.GtwErr, should.Resemble, fetcher.err)
118119
a.So(res.OrgErr, should.Resemble, fetcher.err)
@@ -151,7 +152,7 @@ func TestIdentityServerFetcher(t *testing.T) {
151152
unavailableFetcher := NewIdentityServerFetcher(func(context.Context) *grpc.ClientConn {
152153
return nil
153154
}, false)
154-
unavailableRes := fetchRights(context.Background(), "foo", unavailableFetcher)
155+
unavailableRes := fetchRights(test.Context(), "foo", unavailableFetcher)
155156
a.So(errors.IsUnavailable(unavailableRes.AppErr), should.BeTrue)
156157
a.So(errors.IsUnavailable(unavailableRes.GtwErr), should.BeTrue)
157158
a.So(errors.IsUnavailable(unavailableRes.OrgErr), should.BeTrue)
@@ -160,13 +161,13 @@ func TestIdentityServerFetcher(t *testing.T) {
160161
return cc
161162
}, false)
162163

163-
bgRes := fetchRights(context.Background(), "foo", onlySecureFetcher)
164+
bgRes := fetchRights(test.Context(), "foo", onlySecureFetcher)
164165
a.So(errors.IsUnauthenticated(bgRes.AppErr), should.BeTrue)
165166
a.So(errors.IsUnauthenticated(bgRes.GtwErr), should.BeTrue)
166167
a.So(errors.IsUnauthenticated(bgRes.OrgErr), should.BeTrue)
167168

168169
authCtx := metadata.NewIncomingContext(
169-
context.Background(),
170+
test.Context(),
170171
metadata.Pairs("authorization", "Bearer token"),
171172
)
172173

Collapse file

‎pkg/auth/rights/hook_test.go‎

Copy file name to clipboardExpand all lines: pkg/auth/rights/hook_test.go
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/smartystreets/assertions/should"
2323
errors "go.thethings.network/lorawan-stack/pkg/errorsv3"
2424
"go.thethings.network/lorawan-stack/pkg/ttnpb"
25+
"go.thethings.network/lorawan-stack/pkg/util/test"
2526
"google.golang.org/grpc/codes"
2627
"google.golang.org/grpc/status"
2728
)
@@ -119,7 +120,7 @@ func TestHook(t *testing.T) {
119120
t.Run(name, func(t *testing.T) {
120121
a := assertions.New(t)
121122

122-
ctx := context.Background()
123+
ctx := test.Context()
123124
if tt.Fetcher != nil {
124125
ctx = NewContextWithFetcher(ctx, tt.Fetcher)
125126
}
Collapse file

‎pkg/auth/rights/require_test.go‎

Copy file name to clipboardExpand all lines: pkg/auth/rights/require_test.go
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/smartystreets/assertions/should"
2424
errors "go.thethings.network/lorawan-stack/pkg/errorsv3"
2525
"go.thethings.network/lorawan-stack/pkg/ttnpb"
26+
"go.thethings.network/lorawan-stack/pkg/util/test"
2627
"google.golang.org/grpc/codes"
2728
"google.golang.org/grpc/status"
2829
)
@@ -54,16 +55,16 @@ func TestRequire(t *testing.T) {
5455
a := assertions.New(t)
5556

5657
a.So(func() {
57-
RequireApplication(context.Background(), ttnpb.ApplicationIdentifiers{}, ttnpb.RIGHT_APPLICATION_INFO)
58+
RequireApplication(test.Context(), ttnpb.ApplicationIdentifiers{}, ttnpb.RIGHT_APPLICATION_INFO)
5859
}, should.Panic)
5960
a.So(func() {
60-
RequireGateway(context.Background(), ttnpb.GatewayIdentifiers{}, ttnpb.RIGHT_GATEWAY_INFO)
61+
RequireGateway(test.Context(), ttnpb.GatewayIdentifiers{}, ttnpb.RIGHT_GATEWAY_INFO)
6162
}, should.Panic)
6263
a.So(func() {
63-
RequireOrganization(context.Background(), ttnpb.OrganizationIdentifiers{}, ttnpb.RIGHT_ORGANIZATION_INFO)
64+
RequireOrganization(test.Context(), ttnpb.OrganizationIdentifiers{}, ttnpb.RIGHT_ORGANIZATION_INFO)
6465
}, should.Panic)
6566

66-
fooCtx := newContext(context.Background(), Rights{
67+
fooCtx := newContext(test.Context(), Rights{
6768
ApplicationRights: map[ttnpb.ApplicationIdentifiers][]ttnpb.Right{
6869
{ApplicationID: "foo"}: {ttnpb.RIGHT_APPLICATION_INFO},
6970
},
@@ -86,7 +87,7 @@ func TestRequire(t *testing.T) {
8687
a.So(errors.IsPermissionDenied(barRes.OrgErr), should.BeTrue)
8788

8889
mockErr := errors.New("mock")
89-
errFetchCtx := NewContextWithFetcher(context.Background(), &mockFetcher{
90+
errFetchCtx := NewContextWithFetcher(test.Context(), &mockFetcher{
9091
applicationError: mockErr,
9192
gatewayError: mockErr,
9293
organizationError: mockErr,
@@ -97,7 +98,7 @@ func TestRequire(t *testing.T) {
9798
a.So(errFetchRes.OrgErr, should.Resemble, mockErr)
9899

99100
errPermissionDenied := status.New(codes.PermissionDenied, "permission denied").Err()
100-
permissionDeniedFetchCtx := NewContextWithFetcher(context.Background(), &mockFetcher{
101+
permissionDeniedFetchCtx := NewContextWithFetcher(test.Context(), &mockFetcher{
101102
applicationError: errPermissionDenied,
102103
gatewayError: errPermissionDenied,
103104
organizationError: errPermissionDenied,
Collapse file

‎pkg/auth/rights/rights_test.go‎

Copy file name to clipboardExpand all lines: pkg/auth/rights/rights_test.go
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
package rights
1616

1717
import (
18-
"context"
1918
"testing"
2019

2120
"github.com/smartystreets/assertions"
2221
"github.com/smartystreets/assertions/should"
2322
"go.thethings.network/lorawan-stack/pkg/ttnpb"
23+
"go.thethings.network/lorawan-stack/pkg/util/test"
2424
)
2525

2626
func TestContext(t *testing.T) {
2727
a := assertions.New(t)
2828

29-
rights, ok := FromContext(context.Background())
29+
rights, ok := FromContext(test.Context())
3030
a.So(ok, should.BeFalse)
3131
a.So(rights, should.Resemble, Rights{})
3232

@@ -42,7 +42,7 @@ func TestContext(t *testing.T) {
4242
},
4343
}
4444

45-
ctx := newContext(context.Background(), fooRights)
45+
ctx := newContext(test.Context(), fooRights)
4646

4747
rights, ok = FromContext(ctx)
4848
a.So(ok, should.BeTrue)
Collapse file

‎pkg/cluster/auth_test.go‎

Copy file name to clipboardExpand all lines: pkg/cluster/auth_test.go
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package cluster
1616

1717
import (
18-
"context"
1918
"encoding/hex"
2019
"fmt"
2120
"testing"
@@ -29,7 +28,7 @@ import (
2928
)
3029

3130
func TestVerifySource(t *testing.T) {
32-
ctx := log.NewContext(context.Background(), test.GetLogger(t))
31+
ctx := log.NewContext(test.Context(), test.GetLogger(t))
3332

3433
key := []byte{0x2A, 0x9C, 0x2C, 0x3C, 0x2A, 0x9C, 0x2A, 0x9C, 0x2A, 0x9C, 0x2A, 0x9C, 0x2A, 0x9C, 0x2A, 0x9C}
3534

Collapse file

‎pkg/cluster/cluster_test.go‎

Copy file name to clipboardExpand all lines: pkg/cluster/cluster_test.go
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"go.thethings.network/lorawan-stack/pkg/rpcmiddleware/rpclog"
2828
"go.thethings.network/lorawan-stack/pkg/rpcserver"
2929
"go.thethings.network/lorawan-stack/pkg/ttnpb"
30+
"go.thethings.network/lorawan-stack/pkg/util/test"
3031
"go.thethings.network/lorawan-stack/pkg/util/test/assertions/should"
3132
"google.golang.org/grpc"
3233
"google.golang.org/grpc/connectivity"
@@ -39,7 +40,7 @@ func init() {
3940
log.WithLevel(log.DebugLevel),
4041
log.WithHandler(log.NewCLI(os.Stdout)),
4142
)
42-
ctx = log.NewContext(context.Background(), logger.WithField("namespace", "cluster"))
43+
ctx = log.NewContext(test.Context(), logger.WithField("namespace", "cluster"))
4344
rpclog.ReplaceGrpcLogger(logger.WithField("namespace", "grpc"))
4445
}
4546

@@ -64,7 +65,7 @@ func TestCluster(t *testing.T) {
6465
Join: []string{lis.Addr().String()},
6566
}}
6667

67-
c, err := New(context.Background(), config, []rpcserver.Registerer{}...)
68+
c, err := New(test.Context(), config, []rpcserver.Registerer{}...)
6869
a.So(err, should.BeNil)
6970

7071
a.So(c.Join(), should.BeNil)
Collapse file

‎pkg/component/cluster_test.go‎

Copy file name to clipboardExpand all lines: pkg/component/cluster_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestPeers(t *testing.T) {
3939
}
4040
defer lis.Close()
4141

42-
ctx, cancel := context.WithCancel(context.Background())
42+
ctx, cancel := context.WithCancel(test.Context())
4343
defer cancel()
4444

4545
srv := rpcserver.New(ctx)
Collapse file

‎pkg/component/grpc_test.go‎

Copy file name to clipboardExpand all lines: pkg/component/grpc_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestUnaryHook(t *testing.T) {
120120
asClient := ttnpb.NewAsClient(grpcClient)
121121
gsClient := ttnpb.NewGsClient(grpcClient)
122122

123-
ctx := context.Background()
123+
ctx := test.Context()
124124

125125
// Failing calls
126126
{
Collapse file

‎pkg/errorcontext/errorcontext_test.go‎

Copy file name to clipboardExpand all lines: pkg/errorcontext/errorcontext_test.go
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import (
2121

2222
"github.com/smartystreets/assertions"
2323
"go.thethings.network/lorawan-stack/pkg/errorcontext"
24+
"go.thethings.network/lorawan-stack/pkg/util/test"
2425
"go.thethings.network/lorawan-stack/pkg/util/test/assertions/should"
2526
)
2627

2728
var err error
2829

2930
func ExampleErrorContext() {
30-
ctx, cancel := errorcontext.New(context.Background())
31+
ctx, cancel := errorcontext.New(test.Context())
3132
defer cancel(nil)
3233

3334
go func() {
@@ -53,7 +54,7 @@ func TestErrorContext(t *testing.T) {
5354

5455
{
5556
err := errors.New("foo")
56-
ctx, cancel := errorcontext.New(context.Background())
57+
ctx, cancel := errorcontext.New(test.Context())
5758
cancel(err)
5859
select {
5960
case <-ctx.Done():
@@ -68,7 +69,7 @@ func TestErrorContext(t *testing.T) {
6869
}
6970

7071
{
71-
ctx, cancel := context.WithCancel(context.Background())
72+
ctx, cancel := context.WithCancel(test.Context())
7273
ctx, _ = errorcontext.New(ctx)
7374
cancel()
7475
select {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.