mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-24 20:28:02 +08:00
lint: enable forbidigo context rules
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@@ -41,7 +41,6 @@ func (c *Client) LoadImage(ctx context.Context, name string, status progress.Wri
|
||||
pr, pw := io.Pipe()
|
||||
done := make(chan struct{})
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
var w *waitingWriter
|
||||
w = &waitingWriter{
|
||||
PipeWriter: pw,
|
||||
@@ -67,8 +66,7 @@ func (c *Client) LoadImage(ctx context.Context, name string, status progress.Wri
|
||||
handleErr(err)
|
||||
}
|
||||
},
|
||||
done: done,
|
||||
cancel: cancel,
|
||||
done: done,
|
||||
}
|
||||
return w, func() {
|
||||
pr.Close()
|
||||
@@ -101,12 +99,11 @@ func (c *Client) features(ctx context.Context, name string) map[Feature]bool {
|
||||
|
||||
type waitingWriter struct {
|
||||
*io.PipeWriter
|
||||
f func()
|
||||
once sync.Once
|
||||
mu sync.Mutex
|
||||
err error
|
||||
done chan struct{}
|
||||
cancel func()
|
||||
f func()
|
||||
once sync.Once
|
||||
mu sync.Mutex
|
||||
err error
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func (w *waitingWriter) Write(dt []byte) (int, error) {
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -25,7 +26,7 @@ func WithAccessToken(token string) GitServeOpt {
|
||||
func GitServeHTTP(c *Git, t testing.TB, opts ...GitServeOpt) (url string) {
|
||||
t.Helper()
|
||||
gitUpdateServerInfo(c, t)
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancelCause(context.TODO())
|
||||
|
||||
gs := &gitServe{}
|
||||
for _, opt := range opts {
|
||||
@@ -38,7 +39,7 @@ func GitServeHTTP(c *Git, t testing.TB, opts ...GitServeOpt) (url string) {
|
||||
name := "test.git"
|
||||
dir, err := c.GitDir()
|
||||
if err != nil {
|
||||
cancel()
|
||||
cancel(err)
|
||||
}
|
||||
|
||||
var addr string
|
||||
@@ -84,7 +85,7 @@ func GitServeHTTP(c *Git, t testing.TB, opts ...GitServeOpt) (url string) {
|
||||
<-ready
|
||||
|
||||
t.Cleanup(func() {
|
||||
cancel()
|
||||
cancel(errors.Errorf("cleanup"))
|
||||
<-done
|
||||
})
|
||||
return fmt.Sprintf("http://%s/%s", addr, name)
|
||||
|
@@ -61,7 +61,7 @@ func (m *Map) Get(ctx context.Context, keys ...string) (map[string]interface{},
|
||||
m.mu.Unlock()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
return nil, context.Cause(ctx)
|
||||
case <-ch:
|
||||
m.mu.Lock()
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ func TestTimeout(t *testing.T) {
|
||||
|
||||
m.Set("foo", "bar")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond)
|
||||
ctx, cancel := context.WithTimeoutCause(context.TODO(), 100*time.Millisecond, nil)
|
||||
defer cancel()
|
||||
|
||||
_, err := m.Get(ctx, "bar")
|
||||
|
Reference in New Issue
Block a user