Skip to content

Commit 9bec2cc

Browse files
committed
fix test
1 parent 17abc0b commit 9bec2cc

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

modules/gitrepo/gitrepo.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ func RepositoryFromRequestContextOrOpen(ctx context.Context, ds reqctx.RequestDa
6464
if err != nil {
6565
return nil, err
6666
}
67-
ds.AddCleanUp(func() {
68-
gitRepo.Close()
69-
})
67+
ds.AddCloser(gitRepo)
7068
ds.SetContextValue(ck, gitRepo)
7169
return gitRepo, nil
7270
}

modules/reqctx/datastore.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ var RequestDataStoreKey requestDataStoreKeyType
4444
type requestDataStore struct {
4545
data ContextData
4646

47-
mu sync.RWMutex
48-
values map[any]any
49-
47+
mu sync.RWMutex
48+
values map[any]any
5049
cleanUpFuncs []func()
5150
}
5251

@@ -55,12 +54,8 @@ func (r *requestDataStore) GetContextValue(key any) any {
5554
return r
5655
}
5756
r.mu.RLock()
58-
if v, ok := r.values[key]; ok {
59-
r.mu.RUnlock()
60-
return v
61-
}
62-
r.mu.RUnlock()
63-
return nil
57+
defer r.mu.RUnlock()
58+
return r.values[key]
6459
}
6560

6661
func (r *requestDataStore) SetContextValue(k, v any) {
@@ -106,9 +101,6 @@ type requestContext struct {
106101
}
107102

108103
func (c *requestContext) Value(key any) any {
109-
if key == RequestDataStoreKey {
110-
return c.dataStore
111-
}
112104
if v := c.dataStore.GetContextValue(key); v != nil {
113105
return v
114106
}

services/context/context_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestRemoveSessionCookieHeader(t *testing.T) {
2626
}
2727

2828
func TestRedirectToCurrentSite(t *testing.T) {
29+
setting.IsInTesting = true
2930
defer test.MockVariableValue(&setting.AppURL, "http://localhost:3000/sub/")()
3031
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
3132
cases := []struct {
@@ -40,7 +41,7 @@ func TestRedirectToCurrentSite(t *testing.T) {
4041
t.Run(c.location, func(t *testing.T) {
4142
req := &http.Request{URL: &url.URL{Path: "/"}}
4243
resp := httptest.NewRecorder()
43-
base := NewBaseContext(resp, req)
44+
base := NewBaseContextForTest(resp, req)
4445
ctx := NewWebContext(base, nil, nil)
4546
ctx.RedirectToCurrentSite(c.location)
4647
redirect := test.RedirectURL(resp)

0 commit comments

Comments
 (0)