Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699)
Signed-off-by: joshvanl <me@joshvanl.dev>
This commit is contained in:
parent
637d18d0f9
commit
d8ac01bc76
|
@ -1,6 +1,6 @@
|
|||
module github.com/dapr/components-contrib/build-tools
|
||||
|
||||
go 1.23.6
|
||||
go 1.24.1
|
||||
|
||||
require (
|
||||
github.com/dapr/components-contrib v0.0.0
|
||||
|
|
|
@ -65,7 +65,7 @@ jobs:
|
|||
GOOS: ${{ matrix.target_os }}
|
||||
GOARCH: ${{ matrix.target_arch }}
|
||||
GOPROXY: https://proxy.golang.org
|
||||
GOLANGCI_LINT_VER: "v1.61.0"
|
||||
GOLANGCI_LINT_VER: "v1.64.6"
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
|
|
|
@ -33,7 +33,7 @@ jobs:
|
|||
GOOS: linux
|
||||
GOARCH: amd64
|
||||
GOPROXY: https://proxy.golang.org
|
||||
GOLANGCI_LINT_VER: "v1.61.0"
|
||||
GOLANGCI_LINT_VER: "v1.64.6"
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
|
||||
|
|
|
@ -60,7 +60,7 @@ linters-settings:
|
|||
# [deprecated] comma-separated list of pairs of the form pkg:regex
|
||||
# the regex is used to ignore names within pkg. (default "fmt:.*").
|
||||
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
|
||||
ignore: fmt:.*,io/ioutil:^Read.*
|
||||
exclude-functions: fmt:.*,io/ioutil:^Read.*
|
||||
|
||||
# path to a file containing a list of functions to exclude from checking
|
||||
# see https://github.com/kisielk/errcheck#excluding-functions for details
|
||||
|
@ -285,7 +285,6 @@ linters:
|
|||
- unparam
|
||||
- wsl
|
||||
- mnd
|
||||
- gomnd
|
||||
- testpackage
|
||||
- err113
|
||||
- nestif
|
||||
|
|
|
@ -57,11 +57,11 @@ func TestPublishMsg(t *testing.T) { //nolint:paralleltest
|
|||
}}}
|
||||
|
||||
d := NewDingTalkWebhook(logger.NewLogger("test"))
|
||||
err := d.Init(context.Background(), m)
|
||||
err := d.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
req := &bindings.InvokeRequest{Data: []byte(msg), Operation: bindings.CreateOperation, Metadata: map[string]string{}}
|
||||
_, err = d.Invoke(context.Background(), req)
|
||||
_, err = d.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ func TestBindingReadAndInvoke(t *testing.T) { //nolint:paralleltest
|
|||
}}
|
||||
|
||||
d := NewDingTalkWebhook(logger.NewLogger("test"))
|
||||
err := d.Init(context.Background(), m)
|
||||
err := d.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
var count int32
|
||||
|
@ -92,11 +92,11 @@ func TestBindingReadAndInvoke(t *testing.T) { //nolint:paralleltest
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
err = d.Read(context.Background(), handler)
|
||||
err = d.Read(t.Context(), handler)
|
||||
require.NoError(t, err)
|
||||
|
||||
req := &bindings.InvokeRequest{Data: []byte(msg), Operation: bindings.GetOperation, Metadata: map[string]string{}}
|
||||
_, err = d.Invoke(context.Background(), req)
|
||||
_, err = d.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
select {
|
||||
|
@ -117,7 +117,7 @@ func TestBindingClose(t *testing.T) {
|
|||
"id": "x",
|
||||
},
|
||||
}}
|
||||
require.NoError(t, d.Init(context.Background(), m))
|
||||
require.NoError(t, d.Init(t.Context(), m))
|
||||
require.NoError(t, d.Close())
|
||||
require.NoError(t, d.Close(), "second close should not error")
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package tablestore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -52,7 +51,7 @@ func TestDataEncodeAndDecode(t *testing.T) {
|
|||
metadata := bindings.Metadata{Base: metadata.Base{
|
||||
Properties: getTestProperties(),
|
||||
}}
|
||||
aliCloudTableStore.Init(context.Background(), metadata)
|
||||
aliCloudTableStore.Init(t.Context(), metadata)
|
||||
|
||||
// test create
|
||||
putData := map[string]interface{}{
|
||||
|
@ -71,7 +70,7 @@ func TestDataEncodeAndDecode(t *testing.T) {
|
|||
Data: data,
|
||||
}
|
||||
|
||||
putInvokeResp, err := aliCloudTableStore.Invoke(context.Background(), putRowReq)
|
||||
putInvokeResp, err := aliCloudTableStore.Invoke(t.Context(), putRowReq)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, putInvokeResp)
|
||||
|
@ -82,7 +81,7 @@ func TestDataEncodeAndDecode(t *testing.T) {
|
|||
"column2": int64(2),
|
||||
})
|
||||
|
||||
putInvokeResp, err = aliCloudTableStore.Invoke(context.Background(), putRowReq)
|
||||
putInvokeResp, err = aliCloudTableStore.Invoke(t.Context(), putRowReq)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, putInvokeResp)
|
||||
|
@ -102,7 +101,7 @@ func TestDataEncodeAndDecode(t *testing.T) {
|
|||
Data: getData,
|
||||
}
|
||||
|
||||
getInvokeResp, err := aliCloudTableStore.Invoke(context.Background(), getInvokeReq)
|
||||
getInvokeResp, err := aliCloudTableStore.Invoke(t.Context(), getInvokeReq)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, getInvokeResp)
|
||||
|
@ -136,7 +135,7 @@ func TestDataEncodeAndDecode(t *testing.T) {
|
|||
Data: listData,
|
||||
}
|
||||
|
||||
listResp, err := aliCloudTableStore.Invoke(context.Background(), listReq)
|
||||
listResp, err := aliCloudTableStore.Invoke(t.Context(), listReq)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, listResp)
|
||||
|
||||
|
@ -164,12 +163,12 @@ func TestDataEncodeAndDecode(t *testing.T) {
|
|||
Data: deleteData,
|
||||
}
|
||||
|
||||
deleteResp, err := aliCloudTableStore.Invoke(context.Background(), deleteReq)
|
||||
deleteResp, err := aliCloudTableStore.Invoke(t.Context(), deleteReq)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, deleteResp)
|
||||
|
||||
getInvokeResp, err = aliCloudTableStore.Invoke(context.Background(), getInvokeReq)
|
||||
getInvokeResp, err = aliCloudTableStore.Invoke(t.Context(), getInvokeReq)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, getInvokeResp.Data)
|
||||
|
|
|
@ -15,7 +15,6 @@ package apns
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -52,7 +51,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, developmentPrefix, binding.urlPrefix)
|
||||
})
|
||||
|
@ -67,7 +66,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, productionPrefix, binding.urlPrefix)
|
||||
})
|
||||
|
@ -81,7 +80,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, productionPrefix, binding.urlPrefix)
|
||||
})
|
||||
|
@ -94,7 +93,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.Error(t, err, "the key-id parameter is required")
|
||||
})
|
||||
|
||||
|
@ -107,7 +106,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKeyID, binding.authorizationBuilder.keyID)
|
||||
})
|
||||
|
@ -120,7 +119,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.Error(t, err, "the team-id parameter is required")
|
||||
})
|
||||
|
||||
|
@ -133,7 +132,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testTeamID, binding.authorizationBuilder.teamID)
|
||||
})
|
||||
|
@ -146,7 +145,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.Error(t, err, "the private-key parameter is required")
|
||||
})
|
||||
|
||||
|
@ -159,7 +158,7 @@ func TestInit(t *testing.T) {
|
|||
},
|
||||
}}
|
||||
binding := NewAPNS(testLogger).(*APNS)
|
||||
err := binding.Init(context.Background(), metadata)
|
||||
err := binding.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, binding.authorizationBuilder.privateKey)
|
||||
})
|
||||
|
@ -192,7 +191,7 @@ func TestInvoke(t *testing.T) {
|
|||
t.Run("operation must be create", func(t *testing.T) {
|
||||
testBinding := makeTestBinding(t, testLogger)
|
||||
req := &bindings.InvokeRequest{Operation: bindings.DeleteOperation}
|
||||
_, err := testBinding.Invoke(context.TODO(), req)
|
||||
_, err := testBinding.Invoke(t.Context(), req)
|
||||
require.Error(t, err, "operation not supported: delete")
|
||||
})
|
||||
|
||||
|
@ -202,7 +201,7 @@ func TestInvoke(t *testing.T) {
|
|||
Operation: bindings.CreateOperation,
|
||||
Metadata: map[string]string{},
|
||||
}
|
||||
_, err := testBinding.Invoke(context.TODO(), req)
|
||||
_, err := testBinding.Invoke(t.Context(), req)
|
||||
require.Error(t, err, "the device-token parameter is required")
|
||||
})
|
||||
|
||||
|
@ -213,7 +212,7 @@ func TestInvoke(t *testing.T) {
|
|||
|
||||
return successResponse()
|
||||
})
|
||||
_, _ = testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, _ = testBinding.Invoke(t.Context(), successRequest)
|
||||
})
|
||||
|
||||
t.Run("the push type header is sent", func(t *testing.T) {
|
||||
|
@ -224,7 +223,7 @@ func TestInvoke(t *testing.T) {
|
|||
|
||||
return successResponse()
|
||||
})
|
||||
_, _ = testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, _ = testBinding.Invoke(t.Context(), successRequest)
|
||||
})
|
||||
|
||||
t.Run("the message ID is sent", func(t *testing.T) {
|
||||
|
@ -235,7 +234,7 @@ func TestInvoke(t *testing.T) {
|
|||
|
||||
return successResponse()
|
||||
})
|
||||
_, _ = testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, _ = testBinding.Invoke(t.Context(), successRequest)
|
||||
})
|
||||
|
||||
t.Run("the expiration is sent", func(t *testing.T) {
|
||||
|
@ -246,7 +245,7 @@ func TestInvoke(t *testing.T) {
|
|||
|
||||
return successResponse()
|
||||
})
|
||||
_, _ = testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, _ = testBinding.Invoke(t.Context(), successRequest)
|
||||
})
|
||||
|
||||
t.Run("the priority is sent", func(t *testing.T) {
|
||||
|
@ -257,7 +256,7 @@ func TestInvoke(t *testing.T) {
|
|||
|
||||
return successResponse()
|
||||
})
|
||||
_, _ = testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, _ = testBinding.Invoke(t.Context(), successRequest)
|
||||
})
|
||||
|
||||
t.Run("the topic is sent", func(t *testing.T) {
|
||||
|
@ -268,7 +267,7 @@ func TestInvoke(t *testing.T) {
|
|||
|
||||
return successResponse()
|
||||
})
|
||||
_, _ = testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, _ = testBinding.Invoke(t.Context(), successRequest)
|
||||
})
|
||||
|
||||
t.Run("the collapse ID is sent", func(t *testing.T) {
|
||||
|
@ -279,7 +278,7 @@ func TestInvoke(t *testing.T) {
|
|||
|
||||
return successResponse()
|
||||
})
|
||||
_, _ = testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, _ = testBinding.Invoke(t.Context(), successRequest)
|
||||
})
|
||||
|
||||
t.Run("the message ID is returned", func(t *testing.T) {
|
||||
|
@ -287,7 +286,7 @@ func TestInvoke(t *testing.T) {
|
|||
testBinding.client = newTestClient(func(req *http.Request) *http.Response {
|
||||
return successResponse()
|
||||
})
|
||||
response, err := testBinding.Invoke(context.TODO(), successRequest)
|
||||
response, err := testBinding.Invoke(t.Context(), successRequest)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, response.Data)
|
||||
var body notificationResponse
|
||||
|
@ -307,7 +306,7 @@ func TestInvoke(t *testing.T) {
|
|||
Body: io.NopCloser(strings.NewReader(body)),
|
||||
}
|
||||
})
|
||||
_, err := testBinding.Invoke(context.TODO(), successRequest)
|
||||
_, err := testBinding.Invoke(t.Context(), successRequest)
|
||||
require.Error(t, err, "BadDeviceToken")
|
||||
})
|
||||
}
|
||||
|
@ -322,7 +321,7 @@ func makeTestBinding(t *testing.T, log logger.Logger) *APNS {
|
|||
privateKeyKey: testPrivateKey,
|
||||
},
|
||||
}}
|
||||
err := testBinding.Init(context.Background(), bindingMetadata)
|
||||
err := testBinding.Init(t.Context(), bindingMetadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
return testBinding
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package s3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -176,7 +175,7 @@ func TestGetOption(t *testing.T) {
|
|||
|
||||
t.Run("return error if key is missing", func(t *testing.T) {
|
||||
r := bindings.InvokeRequest{}
|
||||
_, err := s3.get(context.Background(), &r)
|
||||
_, err := s3.get(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -187,7 +186,7 @@ func TestDeleteOption(t *testing.T) {
|
|||
|
||||
t.Run("return error if key is missing", func(t *testing.T) {
|
||||
r := bindings.InvokeRequest{}
|
||||
_, err := s3.delete(context.Background(), &r)
|
||||
_, err := s3.delete(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package blobstorage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -28,7 +27,7 @@ func TestGetOption(t *testing.T) {
|
|||
|
||||
t.Run("return error if blobName is missing", func(t *testing.T) {
|
||||
r := bindings.InvokeRequest{}
|
||||
_, err := blobStorage.get(context.Background(), &r)
|
||||
_, err := blobStorage.get(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, ErrMissingBlobName)
|
||||
})
|
||||
|
@ -39,7 +38,7 @@ func TestDeleteOption(t *testing.T) {
|
|||
|
||||
t.Run("return error if blobName is missing", func(t *testing.T) {
|
||||
r := bindings.InvokeRequest{}
|
||||
_, err := blobStorage.delete(context.Background(), &r)
|
||||
_, err := blobStorage.delete(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, ErrMissingBlobName)
|
||||
})
|
||||
|
@ -50,7 +49,7 @@ func TestDeleteOption(t *testing.T) {
|
|||
"blobName": "foo",
|
||||
"deleteSnapshots": "invalid",
|
||||
}
|
||||
_, err := blobStorage.delete(context.Background(), &r)
|
||||
_, err := blobStorage.delete(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ func createEventHubsBindingsAADMetadata() bindings.Metadata {
|
|||
}
|
||||
|
||||
func testEventHubsBindingsAADAuthentication(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
|
||||
log := logger.NewLogger("bindings.azure.eventhubs.integration.test")
|
||||
|
@ -102,7 +102,7 @@ func testEventHubsBindingsAADAuthentication(t *testing.T) {
|
|||
metadata := createEventHubsBindingsAADMetadata()
|
||||
eventHubsBindings := NewAzureEventHubs(log)
|
||||
|
||||
err := eventHubsBindings.Init(context.Background(), metadata)
|
||||
err := eventHubsBindings.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
req := &bindings.InvokeRequest{
|
||||
|
@ -142,11 +142,11 @@ func testEventHubsBindingsAADAuthentication(t *testing.T) {
|
|||
}
|
||||
|
||||
func testReadIotHubEvents(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
|
||||
logger := logger.NewLogger("bindings.azure.eventhubs.integration.test")
|
||||
eh := NewAzureEventHubs(logger)
|
||||
err := eh.Init(context.Background(), createIotHubBindingsMetadata())
|
||||
err := eh.Init(t.Context(), createIotHubBindingsMetadata())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Invoke az CLI via bash script to send test IoT device events
|
||||
|
|
|
@ -313,7 +313,7 @@ func TestWriteShouldFail(t *testing.T) {
|
|||
|
||||
t.Run("Missing hub should fail", func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
_, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{},
|
||||
})
|
||||
|
@ -325,7 +325,7 @@ func TestWriteShouldFail(t *testing.T) {
|
|||
httpTransport.reset()
|
||||
httpErr := errors.New("fake error")
|
||||
httpTransport.errToReturn = httpErr
|
||||
_, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{
|
||||
hubKey: "testHub",
|
||||
|
@ -339,7 +339,7 @@ func TestWriteShouldFail(t *testing.T) {
|
|||
t.Run("SignalR call returns status != [200, 202]", func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
httpTransport.response.StatusCode = 401
|
||||
_, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{
|
||||
hubKey: "testHub",
|
||||
|
@ -364,7 +364,7 @@ func TestWriteShouldSucceed(t *testing.T) {
|
|||
|
||||
t.Run("Has authorization", func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
_, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{
|
||||
hubKey: "testHub",
|
||||
|
@ -397,7 +397,7 @@ func TestWriteShouldSucceed(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
s.hub = tt.hubInMetadata
|
||||
_, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{
|
||||
hubKey: tt.hubInWriteRequest,
|
||||
|
@ -433,7 +433,7 @@ func TestGetShouldSucceed(t *testing.T) {
|
|||
t.Run("Can get negotiate response with accessKey", func(t *testing.T) {
|
||||
s.aadToken = nil
|
||||
s.accessKey = "AAbbcCsGEQKoLEH6oodDR0jK104Fu1c39Qgk+AA8D+M="
|
||||
res, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
hubKey: "testHub",
|
||||
},
|
||||
|
@ -463,7 +463,7 @@ func TestGetShouldSucceed(t *testing.T) {
|
|||
t.Run("Can get negotiate response with accessKey and userId", func(t *testing.T) {
|
||||
s.aadToken = nil
|
||||
s.accessKey = "AAbbcCsGEQKoLEH6oodDR0jK104Fu1c39Qgk+AA8D+M="
|
||||
res, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
hubKey: "testHub",
|
||||
userKey: "user1",
|
||||
|
@ -499,7 +499,7 @@ func TestGetShouldSucceed(t *testing.T) {
|
|||
}
|
||||
|
||||
httpTransport.reset()
|
||||
res, err := s.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := s.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
hubKey: "testHub",
|
||||
userKey: "user?1&2",
|
||||
|
|
|
@ -96,12 +96,12 @@ func TestWriteQueue(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := bindings.InvokeRequest{Data: []byte("This is my message")}
|
||||
|
||||
_, err = a.Invoke(context.Background(), &r)
|
||||
_, err = a.Invoke(t.Context(), &r)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, a.Close())
|
||||
|
@ -118,12 +118,12 @@ func TestWriteWithTTLInQueue(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1", metadata.TTLMetadataKey: "1"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := bindings.InvokeRequest{Data: []byte("This is my message")}
|
||||
|
||||
_, err = a.Invoke(context.Background(), &r)
|
||||
_, err = a.Invoke(t.Context(), &r)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, a.Close())
|
||||
|
@ -140,7 +140,7 @@ func TestWriteWithTTLInWrite(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1", metadata.TTLMetadataKey: "1"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := bindings.InvokeRequest{
|
||||
|
@ -148,7 +148,7 @@ func TestWriteWithTTLInWrite(t *testing.T) {
|
|||
Metadata: map[string]string{metadata.TTLMetadataKey: "1"},
|
||||
}
|
||||
|
||||
_, err = a.Invoke(context.Background(), &r)
|
||||
_, err = a.Invoke(t.Context(), &r)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, a.Close())
|
||||
|
@ -162,7 +162,7 @@ func TestWriteWithTTLInWrite(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := bindings.InvokeRequest{Data: []byte("This is my message")}
|
||||
|
@ -181,12 +181,12 @@ func TestReadQueue(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := bindings.InvokeRequest{Data: []byte("This is my message")}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
_, err = a.Invoke(ctx, &r)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
@ -223,12 +223,12 @@ func TestReadQueueDecode(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1", "decodeBase64": "true"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := bindings.InvokeRequest{Data: []byte("VGhpcyBpcyBteSBtZXNzYWdl")}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
_, err = a.Invoke(ctx, &r)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
@ -263,7 +263,7 @@ func TestReadQueueDecode(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := bindings.InvokeRequest{Data: []byte("This is my message")}
|
||||
|
@ -294,10 +294,10 @@ func TestReadQueueNoMessage(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"storageAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "queue": "queue1", "storageAccount": "devstoreaccount1"}
|
||||
|
||||
err := a.Init(context.Background(), m)
|
||||
err := a.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
received := 0
|
||||
handler := func(ctx context.Context, data *bindings.ReadResponse) ([]byte, error) {
|
||||
received++
|
||||
|
|
|
@ -75,7 +75,7 @@ func (q *CFQueues) Init(_ context.Context, metadata bindings.Metadata) error {
|
|||
}
|
||||
|
||||
// Operations returns the supported operations for this binding.
|
||||
func (q CFQueues) Operations() []bindings.OperationKind {
|
||||
func (q *CFQueues) Operations() []bindings.OperationKind {
|
||||
return []bindings.OperationKind{bindings.CreateOperation, "publish"}
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ func (ct *Binding) Close() error {
|
|||
}
|
||||
|
||||
// GetComponentMetadata returns the metadata of the component.
|
||||
func (ct Binding) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) {
|
||||
func (ct *Binding) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) {
|
||||
metadataStruct := commercetoolsMetadata{}
|
||||
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType)
|
||||
return
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestCronInitSuccess(t *testing.T) {
|
|||
|
||||
for _, test := range initTests {
|
||||
c := getNewCron()
|
||||
err := c.Init(context.Background(), getTestMetadata(test.schedule))
|
||||
err := c.Init(t.Context(), getTestMetadata(test.schedule))
|
||||
if test.errorExpected {
|
||||
require.Errorf(t, err, "Got no error while initializing an invalid schedule: %s", test.schedule)
|
||||
} else {
|
||||
|
@ -100,10 +100,10 @@ func TestCronRead(t *testing.T) {
|
|||
clk := clocktesting.NewFakeClock(time.Now())
|
||||
c := getNewCronWithClock(clk)
|
||||
schedule := "@every 1s"
|
||||
require.NoErrorf(t, c.Init(context.Background(), getTestMetadata(schedule)), "error initializing valid schedule")
|
||||
require.NoErrorf(t, c.Init(t.Context(), getTestMetadata(schedule)), "error initializing valid schedule")
|
||||
expectedCount := int32(5)
|
||||
var observedCount atomic.Int32
|
||||
err := c.Read(context.Background(), func(ctx context.Context, res *bindings.ReadResponse) ([]byte, error) {
|
||||
err := c.Read(t.Context(), func(ctx context.Context, res *bindings.ReadResponse) ([]byte, error) {
|
||||
assert.NotNil(t, res)
|
||||
observedCount.Add(1)
|
||||
return nil, nil
|
||||
|
@ -128,10 +128,10 @@ func TestCronReadWithContextCancellation(t *testing.T) {
|
|||
clk := clocktesting.NewFakeClock(time.Now())
|
||||
c := getNewCronWithClock(clk)
|
||||
schedule := "@every 1s"
|
||||
require.NoErrorf(t, c.Init(context.Background(), getTestMetadata(schedule)), "error initializing valid schedule")
|
||||
require.NoErrorf(t, c.Init(t.Context(), getTestMetadata(schedule)), "error initializing valid schedule")
|
||||
expectedCount := int32(5)
|
||||
var observedCount atomic.Int32
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
err := c.Read(ctx, func(ctx context.Context, res *bindings.ReadResponse) ([]byte, error) {
|
||||
assert.NotNil(t, res)
|
||||
assert.LessOrEqualf(t, observedCount.Load(), expectedCount, "Invoke didn't stop the schedule")
|
||||
|
|
|
@ -78,7 +78,7 @@ func TestInvoke(t *testing.T) {
|
|||
reqData := enc.Buffer()
|
||||
|
||||
// 3. invoke dapr dubbo output binding, get rsp bytes
|
||||
rsp, err := output.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
rsp, err := output.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
metadataRPCProviderPort: dubboPort,
|
||||
metadataRPCProviderHostname: localhostIP,
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package bucket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
|
@ -64,7 +63,7 @@ func TestParseMetadata(t *testing.T) {
|
|||
t.Run("Metadata is correctly marshalled to JSON", func(t *testing.T) {
|
||||
json, err := json.Marshal(meta)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t,
|
||||
assert.JSONEq(t,
|
||||
"{\"type\":\"my_type\",\"project_id\":\"my_project_id\",\"private_key_id\":\"my_private_key_id\","+
|
||||
"\"private_key\":\"my_private_key\",\"client_email\":\"my_email@mail.dapr\",\"client_id\":\"my_client_id\","+
|
||||
"\"auth_uri\":\"my_auth_uri\",\"token_uri\":\"my_token_uri\",\"auth_provider_x509_cert_url\":\"my_auth_provider_x509\","+
|
||||
|
@ -240,7 +239,7 @@ func TestGetOption(t *testing.T) {
|
|||
gs.metadata = &gcpMetadata{}
|
||||
t.Run("return error if key is missing", func(t *testing.T) {
|
||||
r := bindings.InvokeRequest{}
|
||||
_, err := gs.get(context.TODO(), &r)
|
||||
_, err := gs.get(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -251,7 +250,7 @@ func TestDeleteOption(t *testing.T) {
|
|||
|
||||
t.Run("return error if key is missing", func(t *testing.T) {
|
||||
r := bindings.InvokeRequest{}
|
||||
_, err := gs.delete(context.TODO(), &r)
|
||||
_, err := gs.delete(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -108,6 +108,6 @@ func TestGraphQlRequestHeadersAndVariables(t *testing.T) {
|
|||
"variable:episode": "JEDI",
|
||||
},
|
||||
}
|
||||
_, err = gql.Invoke(context.Background(), req)
|
||||
_, err = gql.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
|
@ -439,7 +439,7 @@ func TestSecurityTokenHeaderForwarded(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
_, err = hs.Invoke(context.Background(), &req)
|
||||
_, err = hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "12345", handler.Headers["X-Token"])
|
||||
})
|
||||
|
@ -455,7 +455,7 @@ func TestSecurityTokenHeaderForwarded(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
_, err = hs.Invoke(context.Background(), &req)
|
||||
_, err = hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, handler.Headers["X-Token"])
|
||||
})
|
||||
|
@ -478,7 +478,7 @@ func TestTraceHeadersForwarded(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
_, err = hs.Invoke(context.Background(), &req)
|
||||
_, err = hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "12345", handler.Headers["Traceparent"])
|
||||
assert.Equal(t, "67890", handler.Headers["Tracestate"])
|
||||
|
@ -493,7 +493,7 @@ func TestTraceHeadersForwarded(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
_, err = hs.Invoke(context.Background(), &req)
|
||||
_, err = hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
_, traceParentExists := handler.Headers["Traceparent"]
|
||||
assert.False(t, traceParentExists)
|
||||
|
@ -510,7 +510,7 @@ func TestTraceHeadersForwarded(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
_, err = hs.Invoke(context.Background(), &req)
|
||||
_, err = hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "12345", handler.Headers["Traceparent"])
|
||||
assert.Equal(t, "67890", handler.Headers["Tracestate"])
|
||||
|
@ -624,7 +624,7 @@ func TestHTTPSBinding(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
response, err := hs.Invoke(context.Background(), &req)
|
||||
response, err := hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
peerCerts, err := strconv.Atoi(string(response.Data))
|
||||
require.NoError(t, err)
|
||||
|
@ -638,7 +638,7 @@ func TestHTTPSBinding(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 201,
|
||||
}.ToInvokeRequest()
|
||||
response, err = hs.Invoke(context.Background(), &req)
|
||||
response, err = hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
peerCerts, err = strconv.Atoi(string(response.Data))
|
||||
require.NoError(t, err)
|
||||
|
@ -657,7 +657,7 @@ func TestHTTPSBinding(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
_, err = hs.Invoke(context.Background(), &req)
|
||||
_, err = hs.Invoke(t.Context(), &req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
|
@ -677,7 +677,7 @@ func TestHTTPSBinding(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 200,
|
||||
}.ToInvokeRequest()
|
||||
response, err := hs.Invoke(context.Background(), &req)
|
||||
response, err := hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
peerCerts, err := strconv.Atoi(string(response.Data))
|
||||
require.NoError(t, err)
|
||||
|
@ -694,7 +694,7 @@ func TestHTTPSBinding(t *testing.T) {
|
|||
err: "",
|
||||
statusCode: 201,
|
||||
}.ToInvokeRequest()
|
||||
response, err = hs.Invoke(context.Background(), &req)
|
||||
response, err = hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
peerCerts, err = strconv.Atoi(string(response.Data))
|
||||
require.NoError(t, err)
|
||||
|
@ -851,7 +851,7 @@ func verifyDefaultBehaviors(t *testing.T, hs bindings.OutputBinding, handler *HT
|
|||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req := tc.ToInvokeRequest()
|
||||
response, err := hs.Invoke(context.Background(), &req)
|
||||
response, err := hs.Invoke(t.Context(), &req)
|
||||
if tc.err == "" {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.path, handler.Path)
|
||||
|
@ -915,7 +915,7 @@ func verifyNon2XXErrorsSuppressed(t *testing.T, hs bindings.OutputBinding, handl
|
|||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req := tc.ToInvokeRequest()
|
||||
response, err := hs.Invoke(context.Background(), &req)
|
||||
response, err := hs.Invoke(t.Context(), &req)
|
||||
if tc.err == "" {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.path, handler.Path)
|
||||
|
@ -965,7 +965,7 @@ func verifyTimeoutBehavior(t *testing.T, hs bindings.OutputBinding, handler *HTT
|
|||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req := tc.ToInvokeRequest()
|
||||
response, err := hs.Invoke(context.Background(), &req)
|
||||
response, err := hs.Invoke(t.Context(), &req)
|
||||
if tc.err == "" {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.path, handler.Path)
|
||||
|
@ -999,7 +999,7 @@ func TestMaxBodySizeHonored(t *testing.T) {
|
|||
}
|
||||
|
||||
req := tc.ToInvokeRequest()
|
||||
response, err := hs.Invoke(context.Background(), &req)
|
||||
response, err := hs.Invoke(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should have only read 1KB
|
||||
|
|
|
@ -94,7 +94,7 @@ func TestInit(t *testing.T) {
|
|||
"accessKey": "dummy-ak",
|
||||
"secretKey": "dummy-sk",
|
||||
}
|
||||
err := obs.Init(context.Background(), m)
|
||||
err := obs.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("Init with missing bucket name", func(t *testing.T) {
|
||||
|
@ -104,7 +104,7 @@ func TestInit(t *testing.T) {
|
|||
"accessKey": "dummy-ak",
|
||||
"secretKey": "dummy-sk",
|
||||
}
|
||||
err := obs.Init(context.Background(), m)
|
||||
err := obs.Init(t.Context(), m)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, err, errors.New("missing obs bucket name"))
|
||||
})
|
||||
|
@ -115,7 +115,7 @@ func TestInit(t *testing.T) {
|
|||
"endpoint": "dummy-endpoint",
|
||||
"secretKey": "dummy-sk",
|
||||
}
|
||||
err := obs.Init(context.Background(), m)
|
||||
err := obs.Init(t.Context(), m)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, err, errors.New("missing the huawei access key"))
|
||||
})
|
||||
|
@ -126,7 +126,7 @@ func TestInit(t *testing.T) {
|
|||
"endpoint": "dummy-endpoint",
|
||||
"accessKey": "dummy-ak",
|
||||
}
|
||||
err := obs.Init(context.Background(), m)
|
||||
err := obs.Init(t.Context(), m)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, err, errors.New("missing the huawei secret key"))
|
||||
})
|
||||
|
@ -137,7 +137,7 @@ func TestInit(t *testing.T) {
|
|||
"accessKey": "dummy-ak",
|
||||
"secretKey": "dummy-sk",
|
||||
}
|
||||
err := obs.Init(context.Background(), m)
|
||||
err := obs.Init(t.Context(), m)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, err, errors.New("missing obs endpoint"))
|
||||
})
|
||||
|
@ -178,7 +178,7 @@ func TestCreateOperation(t *testing.T) {
|
|||
Data: []byte(`"Hello OBS"`),
|
||||
}
|
||||
|
||||
out, err := mo.create(context.Background(), req)
|
||||
out, err := mo.create(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var data createResponse
|
||||
|
@ -209,7 +209,7 @@ func TestCreateOperation(t *testing.T) {
|
|||
Data: []byte(`"Hello OBS"`),
|
||||
}
|
||||
|
||||
out, err := mo.create(context.Background(), req)
|
||||
out, err := mo.create(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var data createResponse
|
||||
|
@ -242,7 +242,7 @@ func TestCreateOperation(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := mo.create(context.Background(), req)
|
||||
_, err := mo.create(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -267,7 +267,7 @@ func TestCreateOperation(t *testing.T) {
|
|||
Data: []byte(`"Hello OBS"`),
|
||||
}
|
||||
|
||||
_, err := mo.create(context.Background(), req)
|
||||
_, err := mo.create(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ func TestUploadOperation(t *testing.T) {
|
|||
Data: []byte(`{"sourceFile": "dummy-path"}`),
|
||||
}
|
||||
|
||||
out, err := mo.upload(context.Background(), req)
|
||||
out, err := mo.upload(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var data createResponse
|
||||
|
@ -329,7 +329,7 @@ func TestUploadOperation(t *testing.T) {
|
|||
Data: []byte(`{"sourceFile": "dummy-path"}`),
|
||||
}
|
||||
|
||||
out, err := mo.upload(context.Background(), req)
|
||||
out, err := mo.upload(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var data createResponse
|
||||
|
@ -359,7 +359,7 @@ func TestUploadOperation(t *testing.T) {
|
|||
Data: []byte(`{"sourceFile": "dummy-path"}`),
|
||||
}
|
||||
|
||||
_, err := mo.upload(context.Background(), req)
|
||||
_, err := mo.upload(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ func TestGetOperation(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := mo.get(context.Background(), req)
|
||||
_, err := mo.get(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -410,7 +410,7 @@ func TestGetOperation(t *testing.T) {
|
|||
Operation: "get",
|
||||
}
|
||||
|
||||
_, err := mo.get(context.Background(), req)
|
||||
_, err := mo.get(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
|
@ -434,7 +434,7 @@ func TestGetOperation(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := mo.get(context.Background(), req)
|
||||
_, err := mo.get(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
|
@ -466,7 +466,7 @@ func TestGetOperation(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := mo.get(context.Background(), req)
|
||||
_, err := mo.get(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ func TestDeleteOperation(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
out, err := mo.delete(context.Background(), req)
|
||||
out, err := mo.delete(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var data createResponse
|
||||
|
@ -518,7 +518,7 @@ func TestDeleteOperation(t *testing.T) {
|
|||
Operation: "delete",
|
||||
}
|
||||
|
||||
_, err := mo.delete(context.Background(), req)
|
||||
_, err := mo.delete(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
|
@ -542,7 +542,7 @@ func TestDeleteOperation(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := mo.delete(context.Background(), req)
|
||||
_, err := mo.delete(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ func TestListOperation(t *testing.T) {
|
|||
Data: []byte("{\"maxResults\": 10}"),
|
||||
}
|
||||
|
||||
_, err := mo.list(context.Background(), req)
|
||||
_, err := mo.list(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -598,7 +598,7 @@ func TestListOperation(t *testing.T) {
|
|||
Data: []byte("{\"maxResults\": 10}"),
|
||||
}
|
||||
|
||||
_, err := mo.list(context.Background(), req)
|
||||
_, err := mo.list(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
|
@ -627,7 +627,7 @@ func TestListOperation(t *testing.T) {
|
|||
Data: []byte("{\"key\": \"value\"}"),
|
||||
}
|
||||
|
||||
_, err := mo.list(context.Background(), req)
|
||||
_, err := mo.list(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ func TestInvoke(t *testing.T) {
|
|||
Operation: "create",
|
||||
}
|
||||
|
||||
_, err := mo.Invoke(context.Background(), req)
|
||||
_, err := mo.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -686,7 +686,7 @@ func TestInvoke(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := mo.Invoke(context.Background(), req)
|
||||
_, err := mo.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -714,7 +714,7 @@ func TestInvoke(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := mo.Invoke(context.Background(), req)
|
||||
_, err := mo.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -743,7 +743,7 @@ func TestInvoke(t *testing.T) {
|
|||
Data: []byte("{\"maxResults\": 10}"),
|
||||
}
|
||||
|
||||
_, err := mo.Invoke(context.Background(), req)
|
||||
_, err := mo.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -760,7 +760,7 @@ func TestInvoke(t *testing.T) {
|
|||
Operation: "unknown",
|
||||
}
|
||||
|
||||
_, err := mo.Invoke(context.Background(), req)
|
||||
_, err := mo.Invoke(t.Context(), req)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ func (mr *MockQueryAPIMockRecorder) QueryRawWithParams(arg0, arg1, arg2, arg3 in
|
|||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRawWithParams", reflect.TypeOf((*MockQueryAPI)(nil).QueryRaw), arg0, arg1, arg2, arg3)
|
||||
}
|
||||
|
||||
|
||||
// QueryWithParams executes flux parametrized query on the InfluxDB server and returns QueryTableResult which parses streamed response into structures representing flux table parts
|
||||
func (m *MockQueryAPI) QueryWithParams(ctx context.Context, query string, params interface{}) (*api.QueryTableResult, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -181,4 +181,4 @@ func (m *MockQueryAPI) QueryWithParams(ctx context.Context, query string, params
|
|||
func (mr *MockQueryAPIMockRecorder) QueryWithParams(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryWithParams", reflect.TypeOf((*MockQueryAPI)(nil).QueryWithParams), arg0, arg1, arg2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package influx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
|
@ -55,7 +54,7 @@ func TestInflux_Init(t *testing.T) {
|
|||
assert.Nil(t, influx.client)
|
||||
|
||||
m := bindings.Metadata{Base: metadata.Base{Properties: map[string]string{"Url": "a", "Token": "a", "Org": "a", "Bucket": "a"}}}
|
||||
err := influx.Init(context.Background(), m)
|
||||
err := influx.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotNil(t, influx.queryAPI)
|
||||
|
@ -90,12 +89,12 @@ func TestInflux_Invoke_BindingCreateOperation(t *testing.T) {
|
|||
defer ctrl.Finish()
|
||||
|
||||
w := NewMockWriteAPIBlocking(ctrl)
|
||||
w.EXPECT().WriteRecord(gomock.Eq(context.TODO()), gomock.Eq("a,a a")).Return(nil)
|
||||
w.EXPECT().WriteRecord(gomock.Eq(t.Context()), gomock.Eq("a,a a")).Return(nil)
|
||||
influx := &Influx{
|
||||
writeAPI: w,
|
||||
}
|
||||
for _, test := range tests {
|
||||
resp, err := influx.Invoke(context.TODO(), test.request)
|
||||
resp, err := influx.Invoke(t.Context(), test.request)
|
||||
assert.Equal(t, test.want.resp, resp)
|
||||
assert.Equal(t, test.want.err, err)
|
||||
}
|
||||
|
@ -117,7 +116,7 @@ func TestInflux_Invoke_BindingInvalidOperation(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
resp, err := (*Influx)(nil).Invoke(context.TODO(), test.request)
|
||||
resp, err := (*Influx)(nil).Invoke(t.Context(), test.request)
|
||||
assert.Equal(t, test.want.resp, resp)
|
||||
assert.Equal(t, test.want.err, err)
|
||||
}
|
||||
|
@ -153,13 +152,13 @@ func TestInflux_Invoke_BindingQueryOperation(t *testing.T) {
|
|||
defer ctrl.Finish()
|
||||
|
||||
q := NewMockQueryAPI(ctrl)
|
||||
q.EXPECT().QueryRaw(gomock.Eq(context.TODO()), gomock.Eq("a"), gomock.Eq(influxdb2.DefaultDialect())).Return("ok", nil)
|
||||
q.EXPECT().QueryRaw(gomock.Eq(t.Context()), gomock.Eq("a"), gomock.Eq(influxdb2.DefaultDialect())).Return("ok", nil)
|
||||
influx := &Influx{
|
||||
queryAPI: q,
|
||||
logger: logger.NewLogger("test"),
|
||||
}
|
||||
for _, test := range tests {
|
||||
resp, err := influx.Invoke(context.TODO(), test.request)
|
||||
resp, err := influx.Invoke(t.Context(), test.request)
|
||||
assert.Equal(t, test.want.resp, resp)
|
||||
assert.Equal(t, test.want.err, err)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package kitex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -61,7 +60,7 @@ func TestInvoke(t *testing.T) {
|
|||
metadataRPCMethodName: MethodName,
|
||||
}
|
||||
|
||||
resp, err := output.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
resp, err := output.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: metadata,
|
||||
Data: reqData,
|
||||
Operation: bindings.GetOperation,
|
||||
|
|
|
@ -106,7 +106,7 @@ func Test_kubeMQ_Init(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
kubemq := NewKubeMQ(logger.NewLogger("test"))
|
||||
err := kubemq.Init(context.Background(), tt.meta)
|
||||
err := kubemq.Init(t.Context(), tt.meta)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
@ -117,10 +117,10 @@ func Test_kubeMQ_Init(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_kubeMQ_Invoke_Read_Single_Message(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Second*5)
|
||||
defer cancel()
|
||||
kubemq := NewKubeMQ(logger.NewLogger("test"))
|
||||
err := kubemq.Init(context.Background(), getDefaultMetadata("test.read.single"))
|
||||
err := kubemq.Init(t.Context(), getDefaultMetadata("test.read.single"))
|
||||
require.NoError(t, err)
|
||||
dataReadCh := make(chan []byte)
|
||||
invokeRequest := &bindings.InvokeRequest{
|
||||
|
@ -142,12 +142,12 @@ func Test_kubeMQ_Invoke_Read_Single_Message(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_kubeMQ_Invoke_Read_Single_MessageWithHandlerError(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Second*10)
|
||||
defer cancel()
|
||||
kubemq := NewKubeMQ(logger.NewLogger("test"))
|
||||
md := getDefaultMetadata("test.read.single.error")
|
||||
md.Properties["autoAcknowledged"] = "false"
|
||||
err := kubemq.Init(context.Background(), md)
|
||||
err := kubemq.Init(t.Context(), md)
|
||||
require.NoError(t, err)
|
||||
invokeRequest := &bindings.InvokeRequest{
|
||||
Data: []byte("test"),
|
||||
|
@ -156,7 +156,7 @@ func Test_kubeMQ_Invoke_Read_Single_MessageWithHandlerError(t *testing.T) {
|
|||
|
||||
_, err = kubemq.Invoke(ctx, invokeRequest)
|
||||
require.NoError(t, err)
|
||||
firstReadCtx, firstReadCancel := context.WithTimeout(context.Background(), time.Second*3)
|
||||
firstReadCtx, firstReadCancel := context.WithTimeout(t.Context(), time.Second*3)
|
||||
defer firstReadCancel()
|
||||
_ = kubemq.Read(firstReadCtx, func(ctx context.Context, req *bindings.ReadResponse) ([]byte, error) {
|
||||
return nil, fmt.Errorf("handler error")
|
||||
|
@ -164,7 +164,7 @@ func Test_kubeMQ_Invoke_Read_Single_MessageWithHandlerError(t *testing.T) {
|
|||
|
||||
<-firstReadCtx.Done()
|
||||
dataReadCh := make(chan []byte)
|
||||
secondReadCtx, secondReadCancel := context.WithTimeout(context.Background(), time.Second*3)
|
||||
secondReadCtx, secondReadCancel := context.WithTimeout(t.Context(), time.Second*3)
|
||||
defer secondReadCancel()
|
||||
_ = kubemq.Read(secondReadCtx, func(ctx context.Context, req *bindings.ReadResponse) ([]byte, error) {
|
||||
dataReadCh <- req.Data
|
||||
|
@ -179,10 +179,10 @@ func Test_kubeMQ_Invoke_Read_Single_MessageWithHandlerError(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_kubeMQ_Invoke_Error(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Second*5)
|
||||
defer cancel()
|
||||
kubemq := NewKubeMQ(logger.NewLogger("test"))
|
||||
err := kubemq.Init(context.Background(), getDefaultMetadata("***test***"))
|
||||
err := kubemq.Init(t.Context(), getDefaultMetadata("***test***"))
|
||||
require.NoError(t, err)
|
||||
|
||||
invokeRequest := &bindings.InvokeRequest{
|
||||
|
|
|
@ -16,7 +16,6 @@ limitations under the License.
|
|||
package mqtt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -50,7 +49,7 @@ func getConnectionString() string {
|
|||
|
||||
func TestInvokeWithTopic(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
url := getConnectionString()
|
||||
if url == "" {
|
||||
|
@ -106,7 +105,7 @@ func TestInvokeWithTopic(t *testing.T) {
|
|||
}()
|
||||
|
||||
// Test invoke with default topic configured for component.
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{Data: dataDefault})
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{Data: dataDefault})
|
||||
require.NoError(t, err)
|
||||
|
||||
m := <-msgCh
|
||||
|
@ -116,7 +115,7 @@ func TestInvokeWithTopic(t *testing.T) {
|
|||
assert.Equal(t, topicDefault, mqttMessage.Topic())
|
||||
|
||||
// Test invoke with customized topic.
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: dataCustomized,
|
||||
Metadata: map[string]string{
|
||||
mqttTopic: topicCustomized,
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package mysql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -60,13 +59,13 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
b := NewMysql(logger.NewLogger("test")).(*Mysql)
|
||||
m := bindings.Metadata{Base: metadata.Base{Properties: map[string]string{connectionURLKey: url}}}
|
||||
|
||||
err := b.Init(context.Background(), m)
|
||||
err := b.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer b.Close()
|
||||
|
||||
t.Run("Invoke create table", func(t *testing.T) {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: execOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: `CREATE TABLE IF NOT EXISTS foo (
|
||||
|
@ -81,7 +80,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Invoke delete", func(t *testing.T) {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: execOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: "DELETE FROM foo",
|
||||
|
@ -92,7 +91,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
|
||||
t.Run("Invoke insert", func(t *testing.T) {
|
||||
for i := range 10 {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: execOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: fmt.Sprintf(
|
||||
|
@ -107,7 +106,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
t.Run("Invoke update", func(t *testing.T) {
|
||||
date := time.Now().Add(time.Hour)
|
||||
for i := range 10 {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: execOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: fmt.Sprintf(
|
||||
|
@ -123,7 +122,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
t.Run("Invoke update with parameters", func(t *testing.T) {
|
||||
date := time.Now().Add(2 * time.Hour)
|
||||
for i := range 10 {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: execOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: "UPDATE foo SET ts = ? WHERE id = ?",
|
||||
|
@ -136,7 +135,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Invoke select", func(t *testing.T) {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: queryOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: "SELECT * FROM foo WHERE id < 3",
|
||||
|
@ -167,7 +166,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Invoke select with parameters", func(t *testing.T) {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: queryOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: "SELECT * FROM foo WHERE id = ?",
|
||||
|
@ -190,7 +189,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Invoke drop", func(t *testing.T) {
|
||||
res, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
res, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: execOperation,
|
||||
Metadata: map[string]string{
|
||||
commandSQLKey: "DROP TABLE foo",
|
||||
|
@ -200,7 +199,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Invoke close", func(t *testing.T) {
|
||||
_, err := b.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := b.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Operation: closeOperation,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package mysql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
@ -39,7 +38,7 @@ func TestQuery(t *testing.T) {
|
|||
AddRow(3, "value-3", time.Now().Add(2000))
|
||||
|
||||
mock.ExpectQuery("SELECT \\* FROM foo WHERE id < 4").WillReturnRows(rows)
|
||||
ret, err := m.query(context.Background(), `SELECT * FROM foo WHERE id < 4`)
|
||||
ret, err := m.query(t.Context(), `SELECT * FROM foo WHERE id < 4`)
|
||||
require.NoError(t, err)
|
||||
t.Logf("query result: %s", ret)
|
||||
assert.Contains(t, string(ret), "\"id\":1")
|
||||
|
@ -58,7 +57,7 @@ func TestQuery(t *testing.T) {
|
|||
AddRow(2, 2.2, time.Now().Add(1000)).
|
||||
AddRow(3, 3.3, time.Now().Add(2000))
|
||||
mock.ExpectQuery("SELECT \\* FROM foo WHERE id < 4").WillReturnRows(rows)
|
||||
ret, err := m.query(context.Background(), "SELECT * FROM foo WHERE id < 4")
|
||||
ret, err := m.query(t.Context(), "SELECT * FROM foo WHERE id < 4")
|
||||
require.NoError(t, err)
|
||||
t.Logf("query result: %s", ret)
|
||||
|
||||
|
@ -85,7 +84,7 @@ func TestExec(t *testing.T) {
|
|||
m, mock, _ := mockDatabase(t)
|
||||
defer m.Close()
|
||||
mock.ExpectExec("INSERT INTO foo \\(id, v1, ts\\) VALUES \\(.*\\)").WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
i, err := m.exec(context.Background(), "INSERT INTO foo (id, v1, ts) VALUES (1, 'test-1', '2021-01-22')")
|
||||
i, err := m.exec(t.Context(), "INSERT INTO foo (id, v1, ts) VALUES (1, 'test-1', '2021-01-22')")
|
||||
assert.Equal(t, int64(1), i)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
@ -102,7 +101,7 @@ func TestInvoke(t *testing.T) {
|
|||
Metadata: metadata,
|
||||
Operation: execOperation,
|
||||
}
|
||||
resp, err := m.Invoke(context.Background(), req)
|
||||
resp, err := m.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "1", resp.Metadata[respRowsAffectedKey])
|
||||
})
|
||||
|
@ -115,7 +114,7 @@ func TestInvoke(t *testing.T) {
|
|||
Metadata: metadata,
|
||||
Operation: execOperation,
|
||||
}
|
||||
resp, err := m.Invoke(context.Background(), req)
|
||||
resp, err := m.Invoke(t.Context(), req)
|
||||
assert.Nil(t, resp)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
@ -133,7 +132,7 @@ func TestInvoke(t *testing.T) {
|
|||
Metadata: metadata,
|
||||
Operation: queryOperation,
|
||||
}
|
||||
resp, err := m.Invoke(context.Background(), req)
|
||||
resp, err := m.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
var data []any
|
||||
err = json.Unmarshal(resp.Data, &data)
|
||||
|
@ -149,7 +148,7 @@ func TestInvoke(t *testing.T) {
|
|||
Metadata: metadata,
|
||||
Operation: queryOperation,
|
||||
}
|
||||
resp, err := m.Invoke(context.Background(), req)
|
||||
resp, err := m.Invoke(t.Context(), req)
|
||||
assert.Nil(t, resp)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
@ -159,7 +158,7 @@ func TestInvoke(t *testing.T) {
|
|||
req := &bindings.InvokeRequest{
|
||||
Operation: closeOperation,
|
||||
}
|
||||
resp, _ := m.Invoke(context.Background(), req)
|
||||
resp, _ := m.Invoke(t.Context(), req)
|
||||
assert.Nil(t, resp)
|
||||
})
|
||||
|
||||
|
@ -169,7 +168,7 @@ func TestInvoke(t *testing.T) {
|
|||
Metadata: map[string]string{},
|
||||
Operation: "unsupported",
|
||||
}
|
||||
resp, err := m.Invoke(context.Background(), req)
|
||||
resp, err := m.Invoke(t.Context(), req)
|
||||
assert.Nil(t, resp)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -70,7 +69,7 @@ func TestPostgresIntegration(t *testing.T) {
|
|||
// live DB test
|
||||
b := NewPostgres(logger.NewLogger("test")).(*Postgres)
|
||||
m := bindings.Metadata{Base: metadata.Base{Properties: map[string]string{"connectionString": url}}}
|
||||
if err := b.Init(context.Background(), m); err != nil {
|
||||
if err := b.Init(t.Context(), m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -79,7 +78,7 @@ func TestPostgresIntegration(t *testing.T) {
|
|||
Operation: execOperation,
|
||||
Metadata: map[string]string{commandSQLKey: testTableDDL},
|
||||
}
|
||||
ctx := context.TODO()
|
||||
ctx := t.Context()
|
||||
t.Run("Invoke create table", func(t *testing.T) {
|
||||
res, err := b.Invoke(ctx, req)
|
||||
assertResponse(t, res, err)
|
||||
|
@ -165,7 +164,7 @@ func testInitConfiguration(t *testing.T, connectionString string) {
|
|||
Base: metadata.Base{Properties: tt.props},
|
||||
}
|
||||
|
||||
err := p.Init(context.Background(), metadata)
|
||||
err := p.Init(t.Context(), metadata)
|
||||
if tt.expectedErr == nil {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
|
|
|
@ -86,7 +86,7 @@ func TestQueuesWithTTL(t *testing.T) {
|
|||
logger := logger.NewLogger("test")
|
||||
|
||||
r := NewRabbitMQ(logger).(*RabbitMQ)
|
||||
err := r.Init(context.Background(), metadata)
|
||||
err := r.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert that if waited too long, we won't see any message
|
||||
|
@ -99,7 +99,7 @@ func TestQueuesWithTTL(t *testing.T) {
|
|||
defer ch.Close()
|
||||
|
||||
const tooLateMsgContent = "too_late_msg"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{Data: []byte(tooLateMsgContent)})
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{Data: []byte(tooLateMsgContent)})
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(time.Second + (ttlInSeconds * time.Second))
|
||||
|
@ -110,7 +110,7 @@ func TestQueuesWithTTL(t *testing.T) {
|
|||
|
||||
// Getting before it is expired, should return it
|
||||
const testMsgContent = "test_msg"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{Data: []byte(testMsgContent)})
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{Data: []byte(testMsgContent)})
|
||||
require.NoError(t, err)
|
||||
|
||||
msg, ok, err := getMessageWithRetries(ch, queueName, maxGetDuration)
|
||||
|
@ -150,14 +150,14 @@ func TestQueuesReconnect(t *testing.T) {
|
|||
logger := logger.NewLogger("test")
|
||||
|
||||
r := NewRabbitMQ(logger).(*RabbitMQ)
|
||||
err := r.Init(context.Background(), metadata)
|
||||
err := r.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = r.Read(context.Background(), handler)
|
||||
err = r.Read(t.Context(), handler)
|
||||
require.NoError(t, err)
|
||||
|
||||
const tooLateMsgContent = "success_msg1"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{Data: []byte(tooLateMsgContent)})
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{Data: []byte(tooLateMsgContent)})
|
||||
require.NoError(t, err)
|
||||
|
||||
// perform a close connection with the rabbitmq server
|
||||
|
@ -165,7 +165,7 @@ func TestQueuesReconnect(t *testing.T) {
|
|||
time.Sleep(3 * defaultReconnectWait)
|
||||
|
||||
const testMsgContent = "reconnect_msg"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{Data: []byte(testMsgContent)})
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{Data: []byte(testMsgContent)})
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(defaultReconnectWait)
|
||||
|
@ -199,7 +199,7 @@ func TestPublishingWithTTL(t *testing.T) {
|
|||
logger := logger.NewLogger("test")
|
||||
|
||||
rabbitMQBinding1 := NewRabbitMQ(logger).(*RabbitMQ)
|
||||
err := rabbitMQBinding1.Init(context.Background(), metadata)
|
||||
err := rabbitMQBinding1.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert that if waited too long, we won't see any message
|
||||
|
@ -219,7 +219,7 @@ func TestPublishingWithTTL(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err = rabbitMQBinding1.Invoke(context.Background(), &writeRequest)
|
||||
_, err = rabbitMQBinding1.Invoke(t.Context(), &writeRequest)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(time.Second + (ttlInSeconds * time.Second))
|
||||
|
@ -230,7 +230,7 @@ func TestPublishingWithTTL(t *testing.T) {
|
|||
|
||||
// Getting before it is expired, should return it
|
||||
rabbitMQBinding2 := NewRabbitMQ(logger).(*RabbitMQ)
|
||||
err = rabbitMQBinding2.Init(context.Background(), metadata)
|
||||
err = rabbitMQBinding2.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
const testMsgContent = "test_msg"
|
||||
|
@ -240,7 +240,7 @@ func TestPublishingWithTTL(t *testing.T) {
|
|||
contribMetadata.TTLMetadataKey: strconv.Itoa(ttlInSeconds * 1000),
|
||||
},
|
||||
}
|
||||
_, err = rabbitMQBinding2.Invoke(context.Background(), &writeRequest)
|
||||
_, err = rabbitMQBinding2.Invoke(t.Context(), &writeRequest)
|
||||
require.NoError(t, err)
|
||||
|
||||
msg, ok, err := getMessageWithRetries(ch, queueName, maxGetDuration)
|
||||
|
@ -280,7 +280,7 @@ func TestExclusiveQueue(t *testing.T) {
|
|||
logger := logger.NewLogger("test")
|
||||
|
||||
r := NewRabbitMQ(logger).(*RabbitMQ)
|
||||
err := r.Init(context.Background(), metadata)
|
||||
err := r.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert that if waited too long, we won't see any message
|
||||
|
@ -334,7 +334,7 @@ func TestPublishWithPriority(t *testing.T) {
|
|||
logger := logger.NewLogger("test")
|
||||
|
||||
r := NewRabbitMQ(logger).(*RabbitMQ)
|
||||
err := r.Init(context.Background(), metadata)
|
||||
err := r.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert that if waited too long, we won't see any message
|
||||
|
@ -347,7 +347,7 @@ func TestPublishWithPriority(t *testing.T) {
|
|||
defer ch.Close()
|
||||
|
||||
const middlePriorityMsgContent = "middle"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
contribMetadata.PriorityMetadataKey: "5",
|
||||
},
|
||||
|
@ -356,7 +356,7 @@ func TestPublishWithPriority(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
const lowPriorityMsgContent = "low"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
contribMetadata.PriorityMetadataKey: "1",
|
||||
},
|
||||
|
@ -365,7 +365,7 @@ func TestPublishWithPriority(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
const highPriorityMsgContent = "high"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
contribMetadata.PriorityMetadataKey: "10",
|
||||
},
|
||||
|
@ -416,7 +416,7 @@ func TestPublishWithHeaders(t *testing.T) {
|
|||
logger := logger.NewLogger("test")
|
||||
|
||||
r := NewRabbitMQ(logger).(*RabbitMQ)
|
||||
err := r.Init(context.Background(), metadata)
|
||||
err := r.Init(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert that if waited too long, we won't see any message
|
||||
|
@ -429,7 +429,7 @@ func TestPublishWithHeaders(t *testing.T) {
|
|||
defer ch.Close()
|
||||
|
||||
const msgContent = "some content"
|
||||
_, err = r.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err = r.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{
|
||||
"custom_header1": "some value",
|
||||
"custom_header2": "some other value",
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -44,10 +43,10 @@ func TestInvokeCreate(t *testing.T) {
|
|||
logger: logger.NewLogger("test"),
|
||||
}
|
||||
|
||||
_, err := c.DoRead(context.Background(), "GET", testKey)
|
||||
_, err := c.DoRead(t.Context(), "GET", testKey)
|
||||
assert.Equal(t, redis.Nil, err)
|
||||
|
||||
bindingRes, err := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
bindingRes, err := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte(testData),
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.CreateOperation,
|
||||
|
@ -55,9 +54,9 @@ func TestInvokeCreate(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Nil(t, bindingRes)
|
||||
|
||||
getRes, err := c.DoRead(context.Background(), "GET", testKey)
|
||||
getRes, err := c.DoRead(t.Context(), "GET", testKey)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testData, getRes)
|
||||
assert.JSONEq(t, testData, getRes.(string))
|
||||
}
|
||||
|
||||
func TestInvokeGetWithoutDeleteFlag(t *testing.T) {
|
||||
|
@ -69,24 +68,24 @@ func TestInvokeGetWithoutDeleteFlag(t *testing.T) {
|
|||
logger: logger.NewLogger("test"),
|
||||
}
|
||||
|
||||
err := c.DoWrite(context.Background(), "SET", testKey, testData)
|
||||
err := c.DoWrite(t.Context(), "SET", testKey, testData)
|
||||
require.NoError(t, err)
|
||||
|
||||
bindingRes, err := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
bindingRes, err := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testData, string(bindingRes.Data))
|
||||
assert.JSONEq(t, testData, string(bindingRes.Data))
|
||||
|
||||
bindingResGet, err := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
bindingResGet, err := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, testData, string(bindingResGet.Data))
|
||||
assert.JSONEq(t, testData, string(bindingResGet.Data))
|
||||
}
|
||||
|
||||
func TestInvokeGetWithDeleteFlag(t *testing.T) {
|
||||
|
@ -98,17 +97,17 @@ func TestInvokeGetWithDeleteFlag(t *testing.T) {
|
|||
logger: logger.NewLogger("test"),
|
||||
}
|
||||
|
||||
err := c.DoWrite(context.Background(), "SET", testKey, testData)
|
||||
err := c.DoWrite(t.Context(), "SET", testKey, testData)
|
||||
require.NoError(t, err)
|
||||
|
||||
bindingRes, err := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
bindingRes, err := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey, "delete": "true"},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testData, string(bindingRes.Data))
|
||||
assert.JSONEq(t, testData, string(bindingRes.Data))
|
||||
|
||||
bindingResGet, err := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
bindingResGet, err := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
|
@ -127,21 +126,21 @@ func TestInvokeDelete(t *testing.T) {
|
|||
logger: logger.NewLogger("test"),
|
||||
}
|
||||
|
||||
err := c.DoWrite(context.Background(), "SET", testKey, testData)
|
||||
err := c.DoWrite(t.Context(), "SET", testKey, testData)
|
||||
require.NoError(t, err)
|
||||
|
||||
getRes, err := c.DoRead(context.Background(), "GET", testKey)
|
||||
getRes, err := c.DoRead(t.Context(), "GET", testKey)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testData, getRes)
|
||||
assert.JSONEq(t, testData, getRes.(string))
|
||||
|
||||
_, err = bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
_, err = bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.DeleteOperation,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
rgetRep, err := c.DoRead(context.Background(), "GET", testKey)
|
||||
rgetRep, err := c.DoRead(t.Context(), "GET", testKey)
|
||||
assert.Equal(t, redis.Nil, err)
|
||||
assert.Nil(t, rgetRep)
|
||||
}
|
||||
|
@ -154,35 +153,35 @@ func TestCreateExpire(t *testing.T) {
|
|||
client: c,
|
||||
logger: logger.NewLogger("test"),
|
||||
}
|
||||
_, err := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
_, err := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey, metadata.TTLMetadataKey: "1"},
|
||||
Operation: bindings.CreateOperation,
|
||||
Data: []byte(testData),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
rgetRep, err := c.DoRead(context.Background(), "TTL", testKey)
|
||||
rgetRep, err := c.DoRead(t.Context(), "TTL", testKey)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(1), rgetRep)
|
||||
|
||||
res, err2 := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
res, err2 := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
require.NoError(t, err2)
|
||||
assert.Equal(t, res.Data, []byte(testData))
|
||||
assert.JSONEq(t, testData, string(res.Data))
|
||||
|
||||
// wait for ttl to expire
|
||||
s.FastForward(2 * time.Second)
|
||||
|
||||
res, err2 = bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
res, err2 = bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
require.NoError(t, err2)
|
||||
assert.Equal(t, []byte(nil), res.Data)
|
||||
|
||||
_, err = bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
_, err = bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": testKey},
|
||||
Operation: bindings.DeleteOperation,
|
||||
})
|
||||
|
@ -197,30 +196,30 @@ func TestIncrement(t *testing.T) {
|
|||
client: c,
|
||||
logger: logger.NewLogger("test"),
|
||||
}
|
||||
_, err := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
_, err := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": "incKey"},
|
||||
Operation: IncrementOperation,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err2 := bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
res, err2 := bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": "incKey"},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
assert.Nil(t, nil, err2)
|
||||
require.NoError(t, err2)
|
||||
assert.Equal(t, res.Data, []byte("1"))
|
||||
|
||||
_, err = bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
_, err = bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": "incKey", metadata.TTLMetadataKey: "5"},
|
||||
Operation: IncrementOperation,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
rgetRep, err := c.DoRead(context.Background(), "TTL", "incKey")
|
||||
rgetRep, err := c.DoRead(t.Context(), "TTL", "incKey")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(5), rgetRep)
|
||||
|
||||
res, err2 = bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
res, err2 = bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": "incKey"},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
|
@ -230,14 +229,14 @@ func TestIncrement(t *testing.T) {
|
|||
// wait for ttl to expire
|
||||
s.FastForward(10 * time.Second)
|
||||
|
||||
res, err2 = bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
res, err2 = bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": "incKey"},
|
||||
Operation: bindings.GetOperation,
|
||||
})
|
||||
require.NoError(t, err2)
|
||||
assert.Equal(t, []byte(nil), res.Data)
|
||||
|
||||
_, err = bind.Invoke(context.TODO(), &bindings.InvokeRequest{
|
||||
_, err = bind.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Metadata: map[string]string{"key": "incKey"},
|
||||
Operation: bindings.DeleteOperation,
|
||||
})
|
||||
|
|
|
@ -71,10 +71,10 @@ func TestBinding(t *testing.T) {
|
|||
}}
|
||||
|
||||
b := getNewRethinkActorBinding()
|
||||
err := b.Init(context.Background(), m)
|
||||
err := b.Init(t.Context(), m)
|
||||
require.NoErrorf(t, err, "error initializing")
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
err = b.Read(ctx, func(_ context.Context, res *bindings.ReadResponse) ([]byte, error) {
|
||||
assert.NotNil(t, res)
|
||||
t.Logf("state change event:\n%s", string(res.Data))
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestInputBindingRead(t *testing.T) { //nolint:paralleltest
|
|||
m := bindings.Metadata{} //nolint:exhaustivestruct
|
||||
m.Properties = getTestMetadata()
|
||||
r := NewRocketMQ(logger.NewLogger("test"))
|
||||
err := r.Init(context.Background(), m)
|
||||
err := r.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
var count int32
|
||||
|
@ -45,13 +45,13 @@ func TestInputBindingRead(t *testing.T) { //nolint:paralleltest
|
|||
|
||||
return nil, nil
|
||||
}
|
||||
err = r.Read(context.Background(), handler)
|
||||
err = r.Read(t.Context(), handler)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
atomic.StoreInt32(&count, 0)
|
||||
req := &bindings.InvokeRequest{Data: []byte("hello"), Operation: bindings.CreateOperation, Metadata: map[string]string{}}
|
||||
_, err = r.Invoke(context.Background(), req)
|
||||
_, err = r.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
|
|
|
@ -176,7 +176,7 @@ func (s *Mailer) parseMetadata(meta bindings.Metadata) (Metadata, error) {
|
|||
}
|
||||
|
||||
// Helper to merge config and request metadata.
|
||||
func (metadata Metadata) mergeWithRequestMetadata(req *bindings.InvokeRequest) (Metadata, error) {
|
||||
func (metadata *Metadata) mergeWithRequestMetadata(req *bindings.InvokeRequest) (*Metadata, error) {
|
||||
merged := metadata
|
||||
|
||||
if emailFrom := req.Metadata["emailFrom"]; emailFrom != "" {
|
||||
|
@ -226,7 +226,7 @@ func (metadata *Metadata) parsePriority(req string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (metadata Metadata) parseAddresses(addresses string) []string {
|
||||
func (metadata *Metadata) parseAddresses(addresses string) []string {
|
||||
return strings.Split(addresses, mailSeparator)
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ func TestParseMetadataWithOptionalNames(t *testing.T) {
|
|||
assert.Equal(t, "test2@example.net", sgMeta.EmailTo)
|
||||
assert.Equal(t, "test 2", sgMeta.EmailToName)
|
||||
assert.Equal(t, "hello", sgMeta.Subject)
|
||||
assert.Equal(t, `{"name":{"first":"MyFirst","last":"MyLast"}}`, sgMeta.DynamicTemplateData)
|
||||
assert.JSONEq(t, `{"name":{"first":"MyFirst","last":"MyLast"}}`, sgMeta.DynamicTemplateData)
|
||||
assert.Equal(t, "456", sgMeta.DynamicTemplateID)
|
||||
})
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package sms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -53,7 +52,7 @@ func TestInit(t *testing.T) {
|
|||
m := bindings.Metadata{}
|
||||
m.Properties = map[string]string{"toNumber": "toNumber", "fromNumber": "fromNumber"}
|
||||
tw := NewSMS(logger.NewLogger("test"))
|
||||
err := tw.Init(context.Background(), m)
|
||||
err := tw.Init(t.Context(), m)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
@ -66,7 +65,7 @@ func TestParseDuration(t *testing.T) {
|
|||
"authToken": "authToken", "timeout": "badtimeout",
|
||||
}
|
||||
tw := NewSMS(logger.NewLogger("test"))
|
||||
err := tw.Init(context.Background(), m)
|
||||
err := tw.Init(t.Context(), m)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
@ -85,12 +84,12 @@ func TestWriteShouldSucceed(t *testing.T) {
|
|||
tw.httpClient = &http.Client{
|
||||
Transport: httpTransport,
|
||||
}
|
||||
err := tw.Init(context.Background(), m)
|
||||
err := tw.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Should succeed with expected url and headers", func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
_, err := tw.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := tw.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{
|
||||
toNumber: "toNumber",
|
||||
|
@ -123,12 +122,12 @@ func TestWriteShouldFail(t *testing.T) {
|
|||
tw.httpClient = &http.Client{
|
||||
Transport: httpTransport,
|
||||
}
|
||||
err := tw.Init(context.Background(), m)
|
||||
err := tw.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Missing 'to' should fail", func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
_, err := tw.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := tw.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{},
|
||||
})
|
||||
|
@ -140,7 +139,7 @@ func TestWriteShouldFail(t *testing.T) {
|
|||
httpTransport.reset()
|
||||
httpErr := errors.New("twilio fake error")
|
||||
httpTransport.errToReturn = httpErr
|
||||
_, err := tw.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := tw.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{
|
||||
toNumber: "toNumber",
|
||||
|
@ -154,7 +153,7 @@ func TestWriteShouldFail(t *testing.T) {
|
|||
t.Run("Twilio call returns status not >=200 and <300", func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
httpTransport.response.StatusCode = 401
|
||||
_, err := tw.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := tw.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: []byte("hello world"),
|
||||
Metadata: map[string]string{
|
||||
toNumber: "toNumber",
|
||||
|
@ -180,13 +179,13 @@ func TestMessageBody(t *testing.T) {
|
|||
tw.httpClient = &http.Client{
|
||||
Transport: httpTransport,
|
||||
}
|
||||
err := tw.Init(context.Background(), m)
|
||||
err := tw.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
|
||||
tester := func(reqData []byte, expectBody string) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
httpTransport.reset()
|
||||
_, err := tw.Invoke(context.Background(), &bindings.InvokeRequest{
|
||||
_, err := tw.Invoke(t.Context(), &bindings.InvokeRequest{
|
||||
Data: reqData,
|
||||
Metadata: map[string]string{
|
||||
toNumber: "toNumber",
|
||||
|
|
|
@ -15,7 +15,6 @@ package wasm
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
@ -34,7 +33,7 @@ func BenchmarkExample(b *testing.B) {
|
|||
output := NewWasmOutput(l)
|
||||
defer output.(io.Closer).Close()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := b.Context()
|
||||
err := output.Init(ctx, bindings.Metadata{Base: md})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
|
@ -46,7 +45,7 @@ func BenchmarkExample(b *testing.B) {
|
|||
expected := []byte("main")
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
if resp, err := output.Invoke(ctx, request); err != nil {
|
||||
b.Fatal(err)
|
||||
} else if !bytes.Equal(expected, resp.Data) {
|
||||
|
|
|
@ -76,7 +76,7 @@ func Test_outputBinding_Init(t *testing.T) {
|
|||
output := NewWasmOutput(logger.NewLogger(t.Name())).(*outputBinding)
|
||||
defer output.Close()
|
||||
|
||||
err := output.Init(context.Background(), bindings.Metadata{Base: tc.metadata})
|
||||
err := output.Init(t.Context(), bindings.Metadata{Base: tc.metadata})
|
||||
if tc.expectedErr == "" {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, output.runtime)
|
||||
|
@ -89,7 +89,7 @@ func Test_outputBinding_Init(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_Invoke(t *testing.T) {
|
||||
canceledCtx, cancel := context.WithCancel(context.Background())
|
||||
canceledCtx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
|
||||
type testCase struct {
|
||||
|
@ -160,7 +160,7 @@ func Test_Invoke(t *testing.T) {
|
|||
output := NewWasmOutput(l)
|
||||
defer output.(io.Closer).Close()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
err := output.Init(ctx, bindings.Metadata{Base: meta})
|
||||
require.NoError(t, err)
|
||||
|
@ -244,7 +244,7 @@ func Test_InvokeHttp(t *testing.T) {
|
|||
output := NewWasmOutput(l)
|
||||
defer output.(io.Closer).Close()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
err := output.Init(ctx, bindings.Metadata{Base: meta})
|
||||
require.NoError(t, err)
|
||||
|
@ -284,7 +284,7 @@ func TestEnsureConcurrency(t *testing.T) {
|
|||
output := NewWasmOutput(l)
|
||||
defer output.(io.Closer).Close()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
err := output.Init(ctx, bindings.Metadata{Base: meta})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -107,7 +107,7 @@ func TestActivateJobs(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: ActivateJobsOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingJobType)
|
||||
})
|
||||
|
||||
|
@ -120,7 +120,7 @@ func TestActivateJobs(t *testing.T) {
|
|||
|
||||
cmd := ZeebeCommand{logger: testLogger}
|
||||
req := &bindings.InvokeRequest{Data: data, Operation: ActivateJobsOperation}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingMaxJobsToActivate)
|
||||
})
|
||||
|
||||
|
@ -137,7 +137,7 @@ func TestActivateJobs(t *testing.T) {
|
|||
var mc mockActivateJobsClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, payload.JobType, mc.cmd1.jobType)
|
||||
|
@ -160,7 +160,7 @@ func TestActivateJobs(t *testing.T) {
|
|||
var mc mockActivateJobsClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, payload.JobType, mc.cmd1.jobType)
|
||||
|
|
|
@ -70,7 +70,7 @@ func TestCancelInstance(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: CancelInstanceOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingProcessInstanceKey)
|
||||
})
|
||||
|
||||
|
@ -86,7 +86,7 @@ func TestCancelInstance(t *testing.T) {
|
|||
var mc mockCancelInstanceClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.ProcessInstanceKey, mc.cmd1.cmd2.processInstanceKey)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
|
@ -58,7 +57,7 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
cmd := ZeebeCommand{clientFactory: mcf, logger: testLogger}
|
||||
err := cmd.Init(context.Background(), metadata)
|
||||
err := cmd.Init(t.Context(), metadata)
|
||||
require.ErrorIs(t, err, errParsing)
|
||||
})
|
||||
|
||||
|
@ -67,7 +66,7 @@ func TestInit(t *testing.T) {
|
|||
mcf := &mockClientFactory{}
|
||||
|
||||
cmd := ZeebeCommand{clientFactory: mcf, logger: testLogger}
|
||||
err := cmd.Init(context.Background(), metadata)
|
||||
err := cmd.Init(t.Context(), metadata)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -85,7 +84,7 @@ func TestInvoke(t *testing.T) {
|
|||
t.Run("operation must be supported", func(t *testing.T) {
|
||||
cmd := ZeebeCommand{logger: testLogger}
|
||||
req := &bindings.InvokeRequest{Operation: bindings.DeleteOperation}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.EqualError(t, err, ErrUnsupportedOperation(bindings.DeleteOperation).Error())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ func TestCompleteJob(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: CompleteJobOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingJobKey)
|
||||
})
|
||||
|
||||
|
@ -103,7 +103,7 @@ func TestCompleteJob(t *testing.T) {
|
|||
var mc mockCompleteJobClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.JobKey, mc.cmd1.jobKey)
|
||||
|
|
|
@ -114,7 +114,7 @@ func TestCreateInstance(t *testing.T) {
|
|||
var mc mockCreateInstanceClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrAmbiguousCreationVars)
|
||||
})
|
||||
|
||||
|
@ -128,7 +128,7 @@ func TestCreateInstance(t *testing.T) {
|
|||
var mc mockCreateInstanceClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingCreationVars)
|
||||
})
|
||||
|
||||
|
@ -145,7 +145,7 @@ func TestCreateInstance(t *testing.T) {
|
|||
var mc mockCreateInstanceClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, payload.BpmnProcessID, mc.cmd1.bpmnProcessID)
|
||||
|
@ -164,7 +164,7 @@ func TestCreateInstance(t *testing.T) {
|
|||
var mc mockCreateInstanceClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, payload.BpmnProcessID, mc.cmd1.bpmnProcessID)
|
||||
|
@ -183,7 +183,7 @@ func TestCreateInstance(t *testing.T) {
|
|||
var mc mockCreateInstanceClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.ProcessDefinitionKey, mc.cmd1.processDefinitionKey)
|
||||
|
@ -204,7 +204,7 @@ func TestCreateInstance(t *testing.T) {
|
|||
var mc mockCreateInstanceClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.ProcessDefinitionKey, mc.cmd1.processDefinitionKey)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -29,7 +28,7 @@ func TestDeployResource(t *testing.T) {
|
|||
t.Run("fileName is mandatory", func(t *testing.T) {
|
||||
cmd := ZeebeCommand{logger: testLogger}
|
||||
req := &bindings.InvokeRequest{Operation: DeployResourceOperation}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingFileName)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ func TestFailJob(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: FailJobOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingJobKey)
|
||||
})
|
||||
|
||||
|
@ -104,7 +104,7 @@ func TestFailJob(t *testing.T) {
|
|||
|
||||
cmd := ZeebeCommand{logger: testLogger}
|
||||
req := &bindings.InvokeRequest{Data: data, Operation: FailJobOperation}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingRetries)
|
||||
})
|
||||
|
||||
|
@ -122,7 +122,7 @@ func TestFailJob(t *testing.T) {
|
|||
var mc mockFailJobClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.JobKey, mc.cmd1.jobKey)
|
||||
|
|
|
@ -108,7 +108,7 @@ func TestPublishMessage(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: PublishMessageOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingMessageName)
|
||||
})
|
||||
|
||||
|
@ -124,7 +124,7 @@ func TestPublishMessage(t *testing.T) {
|
|||
var mc mockPublishMessageClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, payload.MessageName, mc.cmd1.messageName)
|
||||
|
@ -149,7 +149,7 @@ func TestPublishMessage(t *testing.T) {
|
|||
var mc mockPublishMessageClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, payload.MessageName, mc.cmd1.messageName)
|
||||
|
|
|
@ -70,7 +70,7 @@ func TestResolveIncident(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: ResolveIncidentOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingIncidentKey)
|
||||
})
|
||||
|
||||
|
@ -86,7 +86,7 @@ func TestResolveIncident(t *testing.T) {
|
|||
var mc mockResolveIncidentClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.IncidentKey, mc.cmd1.incidentKey)
|
||||
|
|
|
@ -91,7 +91,7 @@ func TestSetVariables(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: SetVariablesOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingElementInstanceKey)
|
||||
})
|
||||
|
||||
|
@ -104,7 +104,7 @@ func TestSetVariables(t *testing.T) {
|
|||
|
||||
cmd := ZeebeCommand{logger: testLogger}
|
||||
req := &bindings.InvokeRequest{Data: data, Operation: SetVariablesOperation}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingVariables)
|
||||
})
|
||||
|
||||
|
@ -123,7 +123,7 @@ func TestSetVariables(t *testing.T) {
|
|||
var mc mockSetVariableClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.ElementInstanceKey, mc.cmd1.elementInstanceKey)
|
||||
|
@ -147,7 +147,7 @@ func TestSetVariables(t *testing.T) {
|
|||
var mc mockSetVariableClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.ElementInstanceKey, mc.cmd1.elementInstanceKey)
|
||||
|
|
|
@ -91,7 +91,7 @@ func TestThrowError(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: ThrowErrorOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingJobKey)
|
||||
})
|
||||
|
||||
|
@ -104,7 +104,7 @@ func TestThrowError(t *testing.T) {
|
|||
|
||||
cmd := ZeebeCommand{logger: testLogger}
|
||||
req := &bindings.InvokeRequest{Data: data, Operation: ThrowErrorOperation}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingErrorCode)
|
||||
})
|
||||
|
||||
|
@ -122,7 +122,7 @@ func TestThrowError(t *testing.T) {
|
|||
var mc mockThrowErrorClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.JobKey, mc.cmd1.jobKey)
|
||||
|
|
|
@ -77,7 +77,7 @@ func TestUpdateJobRetries(t *testing.T) {
|
|||
data, marshalErr := json.Marshal(payload)
|
||||
require.NoError(t, marshalErr)
|
||||
req := &bindings.InvokeRequest{Operation: UpdateJobRetriesOperation, Data: data}
|
||||
_, err := cmd.Invoke(context.TODO(), req)
|
||||
_, err := cmd.Invoke(t.Context(), req)
|
||||
require.ErrorIs(t, err, ErrMissingJobKey)
|
||||
})
|
||||
|
||||
|
@ -94,7 +94,7 @@ func TestUpdateJobRetries(t *testing.T) {
|
|||
var mc mockUpdateJobRetriesClient
|
||||
|
||||
cmd := ZeebeCommand{logger: testLogger, client: &mc}
|
||||
_, err = cmd.Invoke(context.TODO(), req)
|
||||
_, err = cmd.Invoke(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, *payload.JobKey, mc.cmd1.jobKey)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package jobworker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
|
@ -60,7 +59,7 @@ func TestInit(t *testing.T) {
|
|||
var mcf mockClientFactory
|
||||
|
||||
jobWorker := ZeebeJobWorker{clientFactory: &mcf, logger: testLogger, closeCh: make(chan struct{})}
|
||||
err := jobWorker.Init(context.Background(), metadata)
|
||||
err := jobWorker.Init(t.Context(), metadata)
|
||||
|
||||
require.ErrorIs(t, err, ErrMissingJobType)
|
||||
require.NoError(t, jobWorker.Close())
|
||||
|
@ -74,7 +73,7 @@ func TestInit(t *testing.T) {
|
|||
metadata: metadata,
|
||||
}
|
||||
jobWorker := ZeebeJobWorker{clientFactory: mcf, logger: testLogger, closeCh: make(chan struct{})}
|
||||
err := jobWorker.Init(context.Background(), metadata)
|
||||
err := jobWorker.Init(t.Context(), metadata)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -95,7 +94,7 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
jobWorker := ZeebeJobWorker{clientFactory: mcf, logger: testLogger, closeCh: make(chan struct{})}
|
||||
err := jobWorker.Init(context.Background(), metadata)
|
||||
err := jobWorker.Init(t.Context(), metadata)
|
||||
require.Error(t, err, errParsing.Error())
|
||||
require.NoError(t, jobWorker.Close())
|
||||
})
|
||||
|
@ -109,7 +108,7 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
jobWorker := ZeebeJobWorker{clientFactory: mcf, logger: testLogger, closeCh: make(chan struct{})}
|
||||
err := jobWorker.Init(context.Background(), metadata)
|
||||
err := jobWorker.Init(t.Context(), metadata)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ func TestSqsClients_QueueURL(t *testing.T) {
|
|||
Sqs: mockSQS,
|
||||
}
|
||||
|
||||
url, err := client.QueueURL(context.Background(), tt.queueName)
|
||||
url, err := client.QueueURL(t.Context(), tt.queueName)
|
||||
|
||||
if tt.expectError {
|
||||
require.Error(t, err)
|
||||
|
@ -171,7 +171,7 @@ func TestKinesisClients_Stream(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := tt.kinesisClient.Stream(context.Background(), tt.streamName)
|
||||
got, err := tt.kinesisClient.Stream(t.Context(), tt.streamName)
|
||||
if tt.expectedErr != nil {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, tt.expectedErr.Error(), err.Error())
|
||||
|
@ -251,7 +251,7 @@ func TestKinesisClients_WorkerCfg(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := tt.kinesisClient.WorkerCfg(context.Background(), tt.streamName, tt.consumer, tt.mode)
|
||||
cfg := tt.kinesisClient.WorkerCfg(t.Context(), tt.streamName, tt.consumer, tt.mode)
|
||||
if tt.expectedConfig == nil {
|
||||
assert.Equal(t, tt.expectedConfig, cfg)
|
||||
return
|
||||
|
|
|
@ -98,7 +98,7 @@ func TestGetX509Client(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
errCh := make(chan error)
|
||||
go func() {
|
||||
|
|
|
@ -187,7 +187,7 @@ func TestGetMSI(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFallbackToMSI(t *testing.T) {
|
||||
os.Setenv("MSI_ENDPOINT", "test")
|
||||
t.Setenv("MSI_ENDPOINT", "test")
|
||||
defer os.Unsetenv("MSI_ENDPOINT")
|
||||
settings, err := NewEnvironmentSettings(
|
||||
map[string]string{
|
||||
|
@ -203,7 +203,7 @@ func TestFallbackToMSI(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAuthorizorWithMSI(t *testing.T) {
|
||||
os.Setenv("MSI_ENDPOINT", "test")
|
||||
t.Setenv("MSI_ENDPOINT", "test")
|
||||
defer os.Unsetenv("MSI_ENDPOINT")
|
||||
settings, err := NewEnvironmentSettings(
|
||||
map[string]string{
|
||||
|
@ -222,7 +222,7 @@ func TestAuthorizorWithMSI(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFallbackToMSIbutAzureAuthDisallowed(t *testing.T) {
|
||||
os.Setenv("MSI_ENDPOINT", "test")
|
||||
t.Setenv("MSI_ENDPOINT", "test")
|
||||
defer os.Unsetenv("MSI_ENDPOINT")
|
||||
settings, err := NewEnvironmentSettings(
|
||||
map[string]string{
|
||||
|
@ -239,7 +239,7 @@ func TestFallbackToMSIbutAzureAuthDisallowed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFallbackToMSIandInAllowedList(t *testing.T) {
|
||||
os.Setenv("MSI_ENDPOINT", "test")
|
||||
t.Setenv("MSI_ENDPOINT", "test")
|
||||
defer os.Unsetenv("MSI_ENDPOINT")
|
||||
settings, err := NewEnvironmentSettings(
|
||||
map[string]string{
|
||||
|
@ -259,7 +259,7 @@ func TestFallbackToMSIandInAllowedList(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFallbackToMSIandNotInAllowedList(t *testing.T) {
|
||||
os.Setenv("MSI_ENDPOINT", "test")
|
||||
t.Setenv("MSI_ENDPOINT", "test")
|
||||
defer os.Unsetenv("MSI_ENDPOINT")
|
||||
settings, err := NewEnvironmentSettings(
|
||||
map[string]string{
|
||||
|
@ -276,7 +276,7 @@ func TestFallbackToMSIandNotInAllowedList(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFallbackToMSIandInvalidAuthMethod(t *testing.T) {
|
||||
os.Setenv("MSI_ENDPOINT", "test")
|
||||
t.Setenv("MSI_ENDPOINT", "test")
|
||||
defer os.Unsetenv("MSI_ENDPOINT")
|
||||
settings, err := NewEnvironmentSettings(
|
||||
map[string]string{
|
||||
|
@ -296,7 +296,7 @@ func TestFallbackToMSIandInvalidAuthMethod(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAuthorizorWithMSIAndUserAssignedID(t *testing.T) {
|
||||
os.Setenv("MSI_ENDPOINT", "test")
|
||||
t.Setenv("MSI_ENDPOINT", "test")
|
||||
defer os.Unsetenv("MSI_ENDPOINT")
|
||||
settings, err := NewEnvironmentSettings(
|
||||
map[string]string{
|
||||
|
@ -333,7 +333,7 @@ func TestFallbackToCLI(t *testing.T) {
|
|||
runTest := false
|
||||
cred, credErr := azidentity.NewAzureCLICredential(nil)
|
||||
if credErr == nil {
|
||||
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancelFunc := context.WithTimeout(t.Context(), 5*time.Second)
|
||||
defer cancelFunc()
|
||||
token, err := cred.GetToken(ctx, policy.TokenRequestOptions{})
|
||||
if err == nil && token.Token != "" {
|
||||
|
@ -345,7 +345,7 @@ func TestFallbackToCLI(t *testing.T) {
|
|||
spt, err := settings.GetTokenCredential()
|
||||
require.NoError(t, err)
|
||||
|
||||
token, _ := spt.GetToken(context.Background(), policy.TokenRequestOptions{})
|
||||
token, _ := spt.GetToken(t.Context(), policy.TokenRequestOptions{})
|
||||
assert.NotNil(t, token)
|
||||
assert.NotEmpty(t, token.Token)
|
||||
} else {
|
||||
|
|
|
@ -65,7 +65,7 @@ func (m *SqliteAuthMetadata) Validate() error {
|
|||
}
|
||||
|
||||
// IsInMemoryDB returns true if the connection string is for an in-memory database.
|
||||
func (m SqliteAuthMetadata) IsInMemoryDB() bool {
|
||||
func (m *SqliteAuthMetadata) IsInMemoryDB() bool {
|
||||
lc := strings.ToLower(m.ConnectionString)
|
||||
return strings.HasPrefix(lc, ":memory:") || strings.HasPrefix(lc, "file::memory:")
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ package blobstorage
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -46,7 +45,7 @@ func TestClientInitFailures(t *testing.T) {
|
|||
|
||||
for name, s := range scenarios {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
_, _, err := CreateContainerStorageClient(context.Background(), log, s.metadata)
|
||||
_, _, err := CreateContainerStorageClient(t.Context(), log, s.metadata)
|
||||
assert.Contains(t, err.Error(), s.expectedFailureSubString)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/checkpoints"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"github.com/dapr/components-contrib/bindings"
|
||||
azauth "github.com/dapr/components-contrib/common/authentication/azure"
|
||||
|
@ -447,7 +446,7 @@ func (aeh *AzureEventHubs) Close() (err error) {
|
|||
}(producer)
|
||||
}
|
||||
wg.Wait()
|
||||
maps.Clear(aeh.producers)
|
||||
clear(aeh.producers)
|
||||
|
||||
// Remove the cached checkpoint store and metadata
|
||||
aeh.checkpointStoreCache = nil
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
servicebus "github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus"
|
||||
sbadmin "github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus/admin"
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
azauth "github.com/dapr/components-contrib/common/authentication/azure"
|
||||
"github.com/dapr/kit/logger"
|
||||
|
@ -192,7 +191,7 @@ func (c *Client) CloseAllSenders(log logger.Logger) {
|
|||
close(workersCh)
|
||||
|
||||
// Clear the map
|
||||
maps.Clear(c.senders)
|
||||
clear(c.senders)
|
||||
}
|
||||
|
||||
// Close the client and every sender or consumer created by the connnection.
|
||||
|
@ -212,7 +211,7 @@ func (c *Client) Close(log logger.Logger) {
|
|||
}
|
||||
|
||||
// Clear the map of senders
|
||||
maps.Clear(c.senders)
|
||||
clear(c.senders)
|
||||
}
|
||||
|
||||
// EnsureTopic creates the topic if it doesn't exist.
|
||||
|
|
|
@ -331,7 +331,7 @@ func (s *Subscription) doRenewLocks(ctx context.Context, receiver *MessageReceiv
|
|||
err error
|
||||
errored int
|
||||
)
|
||||
for range len(msgs) {
|
||||
for range msgs {
|
||||
// This is a nop if the received error is nil
|
||||
if multierr.AppendInto(&err, <-errCh) {
|
||||
errored++
|
||||
|
|
|
@ -110,7 +110,7 @@ func (m *BaseMetadata) Validate() error {
|
|||
}
|
||||
|
||||
// CreateToken creates a JWT token for authorizing requests
|
||||
func (m BaseMetadata) CreateToken() (string, error) {
|
||||
func (m *BaseMetadata) CreateToken() (string, error) {
|
||||
now := time.Now()
|
||||
token, err := jwt.NewBuilder().
|
||||
Audience([]string{m.WorkerName}).
|
||||
|
|
|
@ -96,7 +96,7 @@ func (w *Base) SetMetadata(metadata *BaseMetadata) {
|
|||
}
|
||||
|
||||
// Client returns the HTTP client.
|
||||
func (w Base) Client() *http.Client {
|
||||
func (w *Base) Client() *http.Client {
|
||||
return w.client
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ func TestSerializeValueCachingDisabled(t *testing.T) {
|
|||
|
||||
act, err := k.SerializeValue("my-topic", valJSON, map[string]string{})
|
||||
|
||||
require.Equal(t, valJSON, act)
|
||||
require.JSONEq(t, string(valJSON), string(act))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -197,7 +197,7 @@ func TestSerializeValueCachingDisabled(t *testing.T) {
|
|||
|
||||
act, err := k.SerializeValue("my-topic", valJSON, map[string]string{"valueSchemaType": "None"})
|
||||
|
||||
require.Equal(t, valJSON, act)
|
||||
require.JSONEq(t, string(valJSON), string(act))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -206,7 +206,7 @@ func TestSerializeValueCachingDisabled(t *testing.T) {
|
|||
|
||||
act, err := k.SerializeValue("my-topic", valJSON, map[string]string{"valueSchemaType": "NONE"})
|
||||
|
||||
require.Equal(t, valJSON, act)
|
||||
require.JSONEq(t, string(valJSON), string(act))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
@ -262,7 +262,7 @@ func TestSerializeValueCachingEnabled(t *testing.T) {
|
|||
t.Run("valueSchemaType not set, leave value as is", func(t *testing.T) {
|
||||
valJSON, _ := json.Marshal(testValue1)
|
||||
act, err := k.SerializeValue("my-topic", valJSON, map[string]string{})
|
||||
require.Equal(t, valJSON, act)
|
||||
require.JSONEq(t, string(valJSON), string(act))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ func (k *Kafka) getKafkaMetadata(meta map[string]string) (*KafkaMetadata, error)
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("kafka error: invalid value for '%s' attribute: %w", consumeRetryInterval, err)
|
||||
}
|
||||
m.ConsumeRetryInterval = time.Duration(intVal) * time.Millisecond //nolint:gosec
|
||||
m.ConsumeRetryInterval = time.Duration(intVal) * time.Millisecond
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package kafka
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/IBM/sarama"
|
||||
|
@ -47,7 +46,7 @@ func createMessageAsserter(t *testing.T, expectedKey sarama.Encoder, expectedHea
|
|||
}
|
||||
|
||||
func TestPublish(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
t.Run("produce message without partition key", func(t *testing.T) {
|
||||
// arrange
|
||||
|
@ -98,7 +97,7 @@ func TestPublish(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBulkPublish(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
metadata := map[string]string{
|
||||
"common": "common",
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import (
|
|||
func Test_reloadConsumerGroup(t *testing.T) {
|
||||
t.Run("if reload called with no topics and not closed, expect return and cancel called", func(t *testing.T) {
|
||||
var consumeCalled atomic.Bool
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cg := mocks.NewConsumerGroup().WithConsumeFn(func(context.Context, []string, sarama.ConsumerGroupHandler) error {
|
||||
|
@ -56,7 +56,7 @@ func Test_reloadConsumerGroup(t *testing.T) {
|
|||
|
||||
t.Run("if reload called with topics but is closed, expect return and cancel called", func(t *testing.T) {
|
||||
var consumeCalled atomic.Bool
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cg := mocks.NewConsumerGroup().WithConsumeFn(func(context.Context, []string, sarama.ConsumerGroupHandler) error {
|
||||
|
@ -255,7 +255,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
subscribeTopics: make(TopicHandlerConfig),
|
||||
}
|
||||
|
||||
k.Subscribe(context.Background(), SubscriptionHandlerConfig{})
|
||||
k.Subscribe(t.Context(), SubscriptionHandlerConfig{})
|
||||
|
||||
assert.Nil(t, k.consumerCancel)
|
||||
assert.Equal(t, int64(0), consumeCalled.Load())
|
||||
|
@ -282,7 +282,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
|
||||
k.closed.Store(true)
|
||||
|
||||
k.Subscribe(context.Background(), SubscriptionHandlerConfig{}, "abc")
|
||||
k.Subscribe(t.Context(), SubscriptionHandlerConfig{}, "abc")
|
||||
|
||||
assert.Nil(t, k.consumerCancel)
|
||||
assert.Equal(t, int64(0), consumeCalled.Load())
|
||||
|
@ -309,7 +309,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
subscribeTopics: make(TopicHandlerConfig),
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
k.Subscribe(ctx, SubscriptionHandlerConfig{}, "abc")
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
|
@ -347,7 +347,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
subscribeTopics: make(TopicHandlerConfig),
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
k.Subscribe(ctx, SubscriptionHandlerConfig{}, "abc")
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
|
@ -398,7 +398,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
consumeRetryInterval: time.Millisecond,
|
||||
}
|
||||
|
||||
k.Subscribe(context.Background(), SubscriptionHandlerConfig{}, "foo")
|
||||
k.Subscribe(t.Context(), SubscriptionHandlerConfig{}, "foo")
|
||||
assert.Equal(t, TopicHandlerConfig{"foo": SubscriptionHandlerConfig{}}, k.subscribeTopics)
|
||||
assert.Eventually(t, func() bool {
|
||||
return consumeCalled.Load() == 5
|
||||
|
@ -428,7 +428,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
consumeRetryInterval: time.Millisecond,
|
||||
}
|
||||
|
||||
ctx1, cancel1 := context.WithCancel(context.Background())
|
||||
ctx1, cancel1 := context.WithCancel(t.Context())
|
||||
k.Subscribe(ctx1, SubscriptionHandlerConfig{}, "abc")
|
||||
assert.Eventually(t, func() bool {
|
||||
return consumeCalled.Load() == 1
|
||||
|
@ -436,7 +436,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
assert.ElementsMatch(t, []string{"abc"}, consumeTopics.Load())
|
||||
assert.Equal(t, int64(0), cancelCalled.Load())
|
||||
|
||||
ctx2, cancel2 := context.WithCancel(context.Background())
|
||||
ctx2, cancel2 := context.WithCancel(t.Context())
|
||||
k.Subscribe(ctx2, SubscriptionHandlerConfig{}, "def")
|
||||
assert.Eventually(t, func() bool {
|
||||
return consumeCalled.Load() == 2
|
||||
|
@ -444,7 +444,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
assert.ElementsMatch(t, []string{"abc", "def"}, consumeTopics.Load())
|
||||
assert.Equal(t, int64(1), cancelCalled.Load())
|
||||
|
||||
ctx3, cancel3 := context.WithCancel(context.Background())
|
||||
ctx3, cancel3 := context.WithCancel(t.Context())
|
||||
k.Subscribe(ctx3, SubscriptionHandlerConfig{}, "123")
|
||||
assert.Eventually(t, func() bool {
|
||||
return consumeCalled.Load() == 3
|
||||
|
@ -459,7 +459,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
assert.ElementsMatch(t, []string{"abc", "123"}, consumeTopics.Load())
|
||||
assert.Equal(t, int64(3), cancelCalled.Load())
|
||||
|
||||
ctx2, cancel2 = context.WithCancel(context.Background())
|
||||
ctx2, cancel2 = context.WithCancel(t.Context())
|
||||
k.Subscribe(ctx2, SubscriptionHandlerConfig{}, "456")
|
||||
assert.Eventually(t, func() bool {
|
||||
return consumeCalled.Load() == 5
|
||||
|
@ -502,7 +502,7 @@ func Test_Subscribe(t *testing.T) {
|
|||
consumeRetryInterval: time.Millisecond,
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
for i := range 100 {
|
||||
go func(i int) {
|
||||
k.Subscribe(ctx, SubscriptionHandlerConfig{}, strconv.Itoa(i))
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestMultiWithNoRequests(t *testing.T) {
|
|||
defer m.db.Close()
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: nil,
|
||||
})
|
||||
|
||||
|
@ -69,7 +69,7 @@ func TestValidSetRequest(t *testing.T) {
|
|||
WillReturnResult(pgxmock.NewResult("INSERT", 1))
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -92,7 +92,7 @@ func TestValidSetRequest(t *testing.T) {
|
|||
m.db.ExpectRollback()
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -114,7 +114,7 @@ func TestInvalidMultiSetRequestNoKey(t *testing.T) {
|
|||
}
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -137,7 +137,7 @@ func TestValidMultiDeleteRequest(t *testing.T) {
|
|||
WillReturnResult(pgxmock.NewResult("DELETE", 1))
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -160,7 +160,7 @@ func TestValidMultiDeleteRequest(t *testing.T) {
|
|||
m.db.ExpectRollback()
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -180,7 +180,7 @@ func TestInvalidMultiDeleteRequestNoKey(t *testing.T) {
|
|||
operations := []state.TransactionalStateOperation{state.DeleteRequest{}, state.DeleteRequest{}} // Delete request without key is not valid for Delete operation
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -210,7 +210,7 @@ func TestMultiOperationOrder(t *testing.T) {
|
|||
m.db.ExpectRollback()
|
||||
|
||||
// Act
|
||||
err := m.pg.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
err := m.pg.Multi(t.Context(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ func (m *Migrations) GetConn() *sql.Conn {
|
|||
}
|
||||
|
||||
// Returns true if a table exists
|
||||
func (m Migrations) tableExists(parentCtx context.Context, db commonsql.DatabaseSQLConn, tableName string) (bool, error) {
|
||||
func (m *Migrations) tableExists(parentCtx context.Context, db commonsql.DatabaseSQLConn, tableName string) (bool, error) {
|
||||
ctx, cancel := context.WithTimeout(parentCtx, 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
@ -138,7 +138,7 @@ func (m Migrations) tableExists(parentCtx context.Context, db commonsql.Database
|
|||
return exists == "1", err
|
||||
}
|
||||
|
||||
func (m Migrations) createMetadataTable(ctx context.Context, db commonsql.DatabaseSQLConn) error {
|
||||
func (m *Migrations) createMetadataTable(ctx context.Context, db commonsql.DatabaseSQLConn) error {
|
||||
m.Logger.Infof("Creating metadata table '%s' if it doesn't exist", m.MetadataTableName)
|
||||
// Add an "IF NOT EXISTS" in case another Dapr sidecar is creating the same table at the same time
|
||||
// In the next step we'll acquire a lock so there won't be issues with concurrency
|
||||
|
|
|
@ -132,7 +132,7 @@ WHEN NOT MATCHED THEN
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m Migrations) ensureMetadataTable(ctx context.Context) error {
|
||||
func (m *Migrations) ensureMetadataTable(ctx context.Context) error {
|
||||
m.Logger.Infof("Ensuring metadata table '%s' exists", m.tableName)
|
||||
_, err := m.DB.ExecContext(ctx, fmt.Sprintf(`
|
||||
IF OBJECT_ID('%[1]s', 'U') IS NULL
|
||||
|
|
|
@ -66,7 +66,7 @@ func TestMigration(t *testing.T) {
|
|||
_, err = db.Exec(fmt.Sprintf("CREATE SCHEMA [%s]", schema))
|
||||
require.NoError(t, err, "Failed to create schema")
|
||||
t.Cleanup(func() {
|
||||
err = commonsqlserver.DropSchema(context.Background(), db, schema)
|
||||
err = commonsqlserver.DropSchema(t.Context(), db, schema)
|
||||
require.NoError(t, err, "Failed to drop schema")
|
||||
})
|
||||
|
||||
|
@ -80,14 +80,14 @@ func TestMigration(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("Create new", func(t *testing.T) {
|
||||
err = m.Perform(context.Background(), []commonsql.MigrationFn{})
|
||||
err = m.Perform(t.Context(), []commonsql.MigrationFn{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assertTableExists(t, db, schema, "metadata_1")
|
||||
})
|
||||
|
||||
t.Run("Already exists", func(t *testing.T) {
|
||||
err = m.Perform(context.Background(), []commonsql.MigrationFn{})
|
||||
err = m.Perform(t.Context(), []commonsql.MigrationFn{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assertTableExists(t, db, schema, "metadata_1")
|
||||
|
@ -109,7 +109,7 @@ func TestMigration(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("First migration", func(t *testing.T) {
|
||||
err = m.Perform(context.Background(), []commonsql.MigrationFn{fn1})
|
||||
err = m.Perform(t.Context(), []commonsql.MigrationFn{fn1})
|
||||
require.NoError(t, err)
|
||||
|
||||
assertTableExists(t, db, schema, "TestTable")
|
||||
|
@ -124,7 +124,7 @@ func TestMigration(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
err = m.Perform(context.Background(), []commonsql.MigrationFn{fn1, fn2})
|
||||
err = m.Perform(t.Context(), []commonsql.MigrationFn{fn1, fn2})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, called)
|
||||
|
@ -139,7 +139,7 @@ func TestMigration(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
err = m.Perform(context.Background(), []commonsql.MigrationFn{fn1, fn2})
|
||||
err = m.Perform(t.Context(), []commonsql.MigrationFn{fn1, fn2})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.False(t, called)
|
||||
|
@ -174,7 +174,7 @@ func TestMigration(t *testing.T) {
|
|||
MetadataKey: "migrations_concurrent",
|
||||
}
|
||||
|
||||
migrateErr := m.Perform(context.Background(), []commonsql.MigrationFn{fn})
|
||||
migrateErr := m.Perform(t.Context(), []commonsql.MigrationFn{fn})
|
||||
if migrateErr != nil {
|
||||
errs <- fmt.Errorf("migration failed in handler %d: %w", i, migrateErr)
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
package v2
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
durationpb "google.golang.org/protobuf/types/known/durationpb"
|
||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -69,7 +69,7 @@ func TestWasmHTTPFetch(t *testing.T) {
|
|||
ts := httptest.NewServer(tc.handler)
|
||||
defer ts.Close()
|
||||
c := newHTTPCLient(http.DefaultTransport)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
|
||||
defer cancel()
|
||||
parse, err := url.Parse(ts.URL)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -38,7 +38,7 @@ const (
|
|||
var binArgs []byte
|
||||
|
||||
func TestGetInitMetadata(t *testing.T) {
|
||||
testCtx, cancel := context.WithCancel(context.Background())
|
||||
testCtx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
type testCase struct {
|
||||
|
@ -184,7 +184,7 @@ func TestNewModuleConfig(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
rt := wazero.NewRuntime(ctx)
|
||||
defer rt.Close(ctx)
|
||||
wasi_snapshot_preview1.MustInstantiate(ctx, rt)
|
||||
|
|
|
@ -110,7 +110,7 @@ func Test_getConfigurationWithProvidedKeys(t *testing.T) {
|
|||
Keys: []string{"testKey"},
|
||||
Metadata: map[string]string{},
|
||||
}
|
||||
res, err := s.Get(context.Background(), &req)
|
||||
res, err := s.Get(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, res.Items, 1)
|
||||
})
|
||||
|
@ -129,13 +129,13 @@ func Test_subscribeConfigurationWithProvidedKeys(t *testing.T) {
|
|||
Keys: []string{"testKey"},
|
||||
Metadata: metadata,
|
||||
}
|
||||
subID, err := s.Subscribe(context.Background(), &req, updateEventHandler)
|
||||
subID, err := s.Subscribe(t.Context(), &req, updateEventHandler)
|
||||
assert.NotEmpty(t, subID)
|
||||
require.NoError(t, err)
|
||||
unReq := &configuration.UnsubscribeRequest{
|
||||
ID: subID,
|
||||
}
|
||||
s.Unsubscribe(context.Background(), unReq)
|
||||
s.Unsubscribe(t.Context(), unReq)
|
||||
})
|
||||
|
||||
t.Run("call subscribe w/o sentinel key", func(t *testing.T) {
|
||||
|
@ -143,7 +143,7 @@ func Test_subscribeConfigurationWithProvidedKeys(t *testing.T) {
|
|||
Keys: []string{"testKey"},
|
||||
Metadata: make(map[string]string),
|
||||
}
|
||||
_, err := s.Subscribe(context.Background(), &req, updateEventHandler)
|
||||
_, err := s.Subscribe(t.Context(), &req, updateEventHandler)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func Test_unsubscribeConfigurationWithProvidedKeys(t *testing.T) {
|
|||
s := NewAzureAppConfigurationStore(logger.NewLogger("test")).(*ConfigurationStore)
|
||||
|
||||
s.client = &MockConfigurationStore{}
|
||||
cancelContext, cancel := context.WithCancel(context.Background())
|
||||
cancelContext, cancel := context.WithCancel(t.Context())
|
||||
s.cancelMap.Store("id1", cancel)
|
||||
|
||||
t.Run("call unsubscribe with incorrect subId", func(t *testing.T) {
|
||||
|
@ -186,7 +186,7 @@ func Test_getConfigurationWithNoProvidedKeys(t *testing.T) {
|
|||
Keys: []string{},
|
||||
Metadata: map[string]string{},
|
||||
}
|
||||
res, err := s.Get(context.Background(), &req)
|
||||
res, err := s.Get(t.Context(), &req)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, res.Items, 2)
|
||||
})
|
||||
|
@ -207,7 +207,7 @@ func TestInit(t *testing.T) {
|
|||
Properties: testProperties,
|
||||
}}
|
||||
|
||||
err := s.Init(context.Background(), m)
|
||||
err := s.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
cs, ok := s.(*ConfigurationStore)
|
||||
assert.True(t, ok)
|
||||
|
@ -232,7 +232,7 @@ func TestInit(t *testing.T) {
|
|||
Properties: testProperties,
|
||||
}}
|
||||
|
||||
err := s.Init(context.Background(), m)
|
||||
err := s.Init(t.Context(), m)
|
||||
require.NoError(t, err)
|
||||
cs, ok := s.(*ConfigurationStore)
|
||||
assert.True(t, ok)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
|
@ -98,7 +97,7 @@ func TestConnectAndQuery(t *testing.T) {
|
|||
[]string{"exists"}).
|
||||
AddRow(string("t")),
|
||||
)
|
||||
rows := mock.QueryRow(context.Background(), query)
|
||||
rows := mock.QueryRow(t.Context(), query)
|
||||
var id string
|
||||
err = rows.Scan(&id)
|
||||
require.NoError(t, err, "error in scan")
|
||||
|
|
|
@ -102,7 +102,7 @@ func (r *ConfigurationStore) parseConnectedSlaves(res string) int {
|
|||
for _, info := range infos {
|
||||
if strings.Contains(info, connectedSlavesReplicas) {
|
||||
parsedReplicas, _ := strconv.ParseUint(info[len(connectedSlavesReplicas):], 10, 32)
|
||||
return int(parsedReplicas) //nolint:gosec
|
||||
return int(parsedReplicas)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ func TestConfigurationStore_Get(t *testing.T) {
|
|||
req: &configuration.GetRequest{
|
||||
Keys: []string{"testKey"},
|
||||
},
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
},
|
||||
want: &configuration.GetResponse{
|
||||
Items: map[string]*configuration.Item{
|
||||
|
@ -86,7 +86,7 @@ func TestConfigurationStore_Get(t *testing.T) {
|
|||
},
|
||||
args: args{
|
||||
req: &configuration.GetRequest{},
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
},
|
||||
want: &configuration.GetResponse{
|
||||
Items: map[string]*configuration.Item{
|
||||
|
@ -112,7 +112,7 @@ func TestConfigurationStore_Get(t *testing.T) {
|
|||
req: &configuration.GetRequest{
|
||||
Keys: []string{"notExistKey"},
|
||||
},
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
},
|
||||
want: &configuration.GetResponse{
|
||||
Items: map[string]*configuration.Item{},
|
||||
|
@ -121,7 +121,7 @@ func TestConfigurationStore_Get(t *testing.T) {
|
|||
{
|
||||
name: "test does not throw error for wrong type during get all",
|
||||
prepare: func(client redisComponent.RedisClient) {
|
||||
client.DoWrite(context.Background(), "HSET", "notSupportedType", []string{"key1", "value1", "key2", "value2"})
|
||||
client.DoWrite(t.Context(), "HSET", "notSupportedType", []string{"key1", "value1", "key2", "value2"})
|
||||
},
|
||||
fields: fields{
|
||||
client: c,
|
||||
|
@ -130,7 +130,7 @@ func TestConfigurationStore_Get(t *testing.T) {
|
|||
},
|
||||
args: args{
|
||||
req: &configuration.GetRequest{},
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
},
|
||||
want: &configuration.GetResponse{
|
||||
Items: map[string]*configuration.Item{
|
||||
|
@ -145,7 +145,7 @@ func TestConfigurationStore_Get(t *testing.T) {
|
|||
},
|
||||
},
|
||||
restore: func(client redisComponent.RedisClient) {
|
||||
client.DoWrite(context.Background(), "HDEL", "notSupportedType")
|
||||
client.DoWrite(t.Context(), "HDEL", "notSupportedType")
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ func Test_parseRedisMetadata(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
log := logger.NewLogger("dapr.components")
|
||||
_, got, err := redisComponent.ParseClientFromProperties(tt.args.meta.Properties, contribMetadata.ConfigurationStoreType, ctx, &log)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package echo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/dapr/components-contrib/conversation"
|
||||
|
@ -13,9 +12,9 @@ import (
|
|||
|
||||
func TestConverse(t *testing.T) {
|
||||
e := NewEcho(logger.NewLogger("echo test"))
|
||||
e.Init(context.Background(), conversation.Metadata{})
|
||||
e.Init(t.Context(), conversation.Metadata{})
|
||||
|
||||
r, err := e.Converse(context.Background(), &conversation.ConversationRequest{
|
||||
r, err := e.Converse(t.Context(), &conversation.ConversationRequest{
|
||||
Inputs: []conversation.ConversationInput{
|
||||
{
|
||||
Message: "hello",
|
||||
|
|
|
@ -402,15 +402,15 @@ func (k *keyvaultCrypto) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (keyvaultCrypto) SupportedEncryptionAlgorithms() []string {
|
||||
func (*keyvaultCrypto) SupportedEncryptionAlgorithms() []string {
|
||||
return encryptionAlgsList
|
||||
}
|
||||
|
||||
func (keyvaultCrypto) SupportedSignatureAlgorithms() []string {
|
||||
func (*keyvaultCrypto) SupportedSignatureAlgorithms() []string {
|
||||
return signatureAlgsList
|
||||
}
|
||||
|
||||
func (keyvaultCrypto) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) {
|
||||
func (*keyvaultCrypto) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) {
|
||||
metadataStruct := keyvaultMetadata{}
|
||||
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.CryptoType)
|
||||
return
|
||||
|
|
|
@ -144,12 +144,12 @@ func (k *kubeSecretsCrypto) parseKeyString(param string) (namespace string, secr
|
|||
return
|
||||
}
|
||||
|
||||
func (kubeSecretsCrypto) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
|
||||
func (*kubeSecretsCrypto) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
|
||||
metadataStruct := secretsMetadata{}
|
||||
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.CryptoType)
|
||||
return
|
||||
}
|
||||
|
||||
func (kubeSecretsCrypto) Close() error {
|
||||
func (*kubeSecretsCrypto) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ func (l *localStorageCrypto) retrieveKey(parentCtx context.Context, key string)
|
|||
return jwkObj, nil
|
||||
}
|
||||
|
||||
func (localStorageCrypto) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) {
|
||||
func (*localStorageCrypto) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) {
|
||||
metadataStruct := localStorageMetadata{}
|
||||
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.CryptoType)
|
||||
return
|
||||
|
|
|
@ -53,7 +53,7 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
}),
|
||||
ctx: kitctx.NewPool(),
|
||||
}
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey, result)
|
||||
})
|
||||
|
@ -76,11 +76,11 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
ctx: kitctx.NewPool(),
|
||||
}
|
||||
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey, result)
|
||||
|
||||
result, err = cache.GetKey(context.Background(), "another-key")
|
||||
result, err = cache.GetKey(t.Context(), "another-key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey2, result)
|
||||
})
|
||||
|
@ -95,7 +95,7 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey, result)
|
||||
assert.Equal(t, 1, called, "should be called once")
|
||||
|
@ -116,10 +116,10 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey, result)
|
||||
result, err = cache.GetKey(context.Background(), "another-key")
|
||||
result, err = cache.GetKey(t.Context(), "another-key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey2, result)
|
||||
|
||||
|
@ -137,7 +137,7 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
assert.Equal(t, 1, called, "should be called once")
|
||||
|
@ -159,7 +159,7 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
for range 10 {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey, result)
|
||||
}()
|
||||
|
@ -171,7 +171,7 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
|
||||
t.Run("calling get key and context is cancelled should return context error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithCancelCause(context.Background())
|
||||
ctx, cancel := context.WithCancelCause(t.Context())
|
||||
getKeyReturned := make(chan struct{})
|
||||
|
||||
cache := NewPubKeyCache(func(ctx context.Context, i string) func(resolve func(jwk.Key), reject func(error)) {
|
||||
|
@ -197,8 +197,8 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
|
||||
t.Run("only callers with cancelled contexts should return context error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx1, cancel1 := context.WithCancelCause(context.Background())
|
||||
ctx2 := context.Background()
|
||||
ctx1, cancel1 := context.WithCancelCause(t.Context())
|
||||
ctx2 := t.Context()
|
||||
|
||||
getKeyReturned := make(chan struct{})
|
||||
|
||||
|
@ -244,8 +244,8 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
|
||||
t.Run("if all callers give cancelled contexts, the underlying context should also be cancelled", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx1, cancel1 := context.WithCancelCause(context.Background())
|
||||
ctx2, cancel2 := context.WithCancelCause(context.Background())
|
||||
ctx1, cancel1 := context.WithCancelCause(t.Context())
|
||||
ctx2, cancel2 := context.WithCancelCause(t.Context())
|
||||
|
||||
getKeyReturned := make(chan struct{})
|
||||
|
||||
|
@ -312,7 +312,7 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
}, time.Second*5, time.Millisecond)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancelCause(context.Background())
|
||||
ctx, cancel := context.WithCancelCause(t.Context())
|
||||
|
||||
getKeyReturned := make(chan struct{})
|
||||
|
||||
|
@ -347,14 +347,14 @@ func TestPubKeyCacheGetKey(t *testing.T) {
|
|||
go func() {
|
||||
defer wg.Done()
|
||||
assertSize(1)
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey, result)
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
assertSize(2)
|
||||
result, err := cache.GetKey(context.Background(), "key")
|
||||
result, err := cache.GetKey(t.Context(), "key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testKey, result)
|
||||
}()
|
||||
|
|
6
go.mod
6
go.mod
|
@ -1,6 +1,6 @@
|
|||
module github.com/dapr/components-contrib
|
||||
|
||||
go 1.23.6
|
||||
go 1.24.1
|
||||
|
||||
require (
|
||||
cloud.google.com/go/datastore v1.15.0
|
||||
|
@ -126,7 +126,6 @@ require (
|
|||
go.uber.org/multierr v1.11.0
|
||||
go.uber.org/ratelimit v0.3.0
|
||||
golang.org/x/crypto v0.26.0
|
||||
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
|
||||
golang.org/x/mod v0.17.0
|
||||
golang.org/x/net v0.28.0
|
||||
golang.org/x/oauth2 v0.20.0
|
||||
|
@ -199,7 +198,7 @@ require (
|
|||
github.com/bytedance/gopkg v0.0.0-20240711085056-a03554c296f8 // indirect
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/choleraehyq/pid v0.0.19 // indirect
|
||||
github.com/choleraehyq/pid v0.0.20 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.5.6 // indirect
|
||||
github.com/cloudwego/fastpb v0.0.4-0.20230131074846-6fc453d58b96 // indirect
|
||||
github.com/cloudwego/frugal v0.2.0 // indirect
|
||||
|
@ -398,6 +397,7 @@ require (
|
|||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/arch v0.10.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.23.0 // indirect
|
||||
golang.org/x/term v0.23.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -369,8 +369,8 @@ github.com/choleraehyq/pid v0.0.12/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4T
|
|||
github.com/choleraehyq/pid v0.0.13/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
|
||||
github.com/choleraehyq/pid v0.0.15/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
|
||||
github.com/choleraehyq/pid v0.0.16/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
|
||||
github.com/choleraehyq/pid v0.0.19 h1:7lV897BV8V1OBFecw5cpbc0cChpE+HbQCFNE7E3bjQY=
|
||||
github.com/choleraehyq/pid v0.0.19/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
|
||||
github.com/choleraehyq/pid v0.0.20 h1:FSOci0vLLkM/38cDpokosFPcYLpoSxjeTzYiipiu7is=
|
||||
github.com/choleraehyq/pid v0.0.20/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
miniredis "github.com/alicebob/miniredis/v2"
|
||||
|
@ -42,7 +41,7 @@ func TestStandaloneRedisLock_InitError(t *testing.T) {
|
|||
cfg.Properties["redisPassword"] = ""
|
||||
|
||||
// init
|
||||
err := comp.InitLockStore(context.Background(), cfg)
|
||||
err := comp.InitLockStore(t.Context(), cfg)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
|
@ -58,7 +57,7 @@ func TestStandaloneRedisLock_InitError(t *testing.T) {
|
|||
cfg.Properties["redisPassword"] = ""
|
||||
|
||||
// init
|
||||
err := comp.InitLockStore(context.Background(), cfg)
|
||||
err := comp.InitLockStore(t.Context(), cfg)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
|
@ -75,7 +74,7 @@ func TestStandaloneRedisLock_InitError(t *testing.T) {
|
|||
cfg.Properties["maxRetries"] = "1 "
|
||||
|
||||
// init
|
||||
err := comp.InitLockStore(context.Background(), cfg)
|
||||
err := comp.InitLockStore(t.Context(), cfg)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -98,12 +97,12 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
|||
cfg.Properties["redisPassword"] = ""
|
||||
|
||||
// Init
|
||||
err = comp.InitLockStore(context.Background(), cfg)
|
||||
err = comp.InitLockStore(t.Context(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
// 1. client1 trylock
|
||||
ownerID1 := uuid.New().String()
|
||||
resp, err := comp.TryLock(context.Background(), &lock.TryLockRequest{
|
||||
resp, err := comp.TryLock(t.Context(), &lock.TryLockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: ownerID1,
|
||||
ExpiryInSeconds: 10,
|
||||
|
@ -113,7 +112,7 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
|||
|
||||
// 2. Client2 tryLock fail
|
||||
owner2 := uuid.New().String()
|
||||
resp, err = comp.TryLock(context.Background(), &lock.TryLockRequest{
|
||||
resp, err = comp.TryLock(t.Context(), &lock.TryLockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: owner2,
|
||||
ExpiryInSeconds: 10,
|
||||
|
@ -122,7 +121,7 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
|||
assert.False(t, resp.Success)
|
||||
|
||||
// 3. Client 1 unlock
|
||||
unlockResp, err := comp.Unlock(context.Background(), &lock.UnlockRequest{
|
||||
unlockResp, err := comp.Unlock(t.Context(), &lock.UnlockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: ownerID1,
|
||||
})
|
||||
|
@ -131,7 +130,7 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
|||
|
||||
// 4. Client 2 get lock
|
||||
owner2 = uuid.New().String()
|
||||
resp2, err2 := comp.TryLock(context.Background(), &lock.TryLockRequest{
|
||||
resp2, err2 := comp.TryLock(t.Context(), &lock.TryLockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: owner2,
|
||||
ExpiryInSeconds: 10,
|
||||
|
@ -140,7 +139,7 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
|||
assert.True(t, resp2.Success, "client2 failed to get lock?!")
|
||||
|
||||
// 5. client2 unlock
|
||||
unlockResp, err = comp.Unlock(context.Background(), &lock.UnlockRequest{
|
||||
unlockResp, err = comp.Unlock(t.Context(), &lock.UnlockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: owner2,
|
||||
})
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package oauth2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
@ -40,7 +39,7 @@ func TestOAuth2CreatesAuthorizationHeaderWhenInSessionState(t *testing.T) {
|
|||
}
|
||||
|
||||
log := logger.NewLogger("oauth2.test")
|
||||
handler, err := NewOAuth2Middleware(log).GetHandler(context.Background(), metadata)
|
||||
handler, err := NewOAuth2Middleware(log).GetHandler(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create request and recorder
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package oauth2clientcredentials
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
@ -46,7 +45,7 @@ func TestOAuth2ClientCredentialsMetadata(t *testing.T) {
|
|||
metadata.Properties = map[string]string{}
|
||||
|
||||
log := logger.NewLogger("oauth2clientcredentials.test")
|
||||
_, err := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(context.Background(), metadata)
|
||||
_, err := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(t.Context(), metadata)
|
||||
require.EqualError(t, err, "metadata errors: Parameter 'headerName' needs to be set. Parameter 'clientID' needs to be set. Parameter 'clientSecret' needs to be set. Parameter 'scopes' needs to be set. Parameter 'tokenURL' needs to be set. ")
|
||||
|
||||
// Invalid authStyle (non int)
|
||||
|
@ -58,17 +57,17 @@ func TestOAuth2ClientCredentialsMetadata(t *testing.T) {
|
|||
"headerName": "someHeader",
|
||||
"authStyle": "asdf", // This is the value to test
|
||||
}
|
||||
_, err2 := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(context.Background(), metadata)
|
||||
_, err2 := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(t.Context(), metadata)
|
||||
require.EqualError(t, err2, "metadata errors: 1 error(s) decoding:\n\n* cannot parse 'authStyle' as int: strconv.ParseInt: parsing \"asdf\": invalid syntax")
|
||||
|
||||
// Invalid authStyle (int > 2)
|
||||
metadata.Properties["authStyle"] = "3"
|
||||
_, err3 := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(context.Background(), metadata)
|
||||
_, err3 := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(t.Context(), metadata)
|
||||
require.EqualError(t, err3, "metadata errors: Parameter 'authStyle' can only have the values 0,1,2. Received: '3'. ")
|
||||
|
||||
// Invalid authStyle (int < 0)
|
||||
metadata.Properties["authStyle"] = "-1"
|
||||
_, err4 := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(context.Background(), metadata)
|
||||
_, err4 := NewOAuth2ClientCredentialsMiddleware(log).GetHandler(t.Context(), metadata)
|
||||
require.EqualError(t, err4, "metadata errors: Parameter 'authStyle' can only have the values 0,1,2. Received: '-1'. ")
|
||||
}
|
||||
|
||||
|
@ -110,7 +109,7 @@ func TestOAuth2ClientCredentialsToken(t *testing.T) {
|
|||
log := logger.NewLogger("oauth2clientcredentials.test")
|
||||
oauth2clientcredentialsMiddleware, _ := NewOAuth2ClientCredentialsMiddleware(log).(*Middleware)
|
||||
oauth2clientcredentialsMiddleware.SetTokenProvider(mockTokenProvider)
|
||||
handler, err := oauth2clientcredentialsMiddleware.GetHandler(context.Background(), metadata)
|
||||
handler, err := oauth2clientcredentialsMiddleware.GetHandler(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// First handler call should return abc Token
|
||||
|
@ -170,7 +169,7 @@ func TestOAuth2ClientCredentialsCache(t *testing.T) {
|
|||
log := logger.NewLogger("oauth2clientcredentials.test")
|
||||
oauth2clientcredentialsMiddleware, _ := NewOAuth2ClientCredentialsMiddleware(log).(*Middleware)
|
||||
oauth2clientcredentialsMiddleware.SetTokenProvider(mockTokenProvider)
|
||||
handler, err := oauth2clientcredentialsMiddleware.GetHandler(context.Background(), metadata)
|
||||
handler, err := oauth2clientcredentialsMiddleware.GetHandler(t.Context(), metadata)
|
||||
require.NoError(t, err)
|
||||
|
||||
// First handler call should return abc Token
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package opa
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -332,7 +331,7 @@ func TestOpaPolicy(t *testing.T) {
|
|||
t.Run(name, func(t *testing.T) {
|
||||
opaMiddleware := NewMiddleware(log)
|
||||
|
||||
handler, err := opaMiddleware.GetHandler(context.Background(), test.meta)
|
||||
handler, err := opaMiddleware.GetHandler(t.Context(), test.meta)
|
||||
if test.shouldHandlerError {
|
||||
require.Error(t, err)
|
||||
return
|
||||
|
@ -420,7 +419,7 @@ func TestStatus_UnmarshalJSON(t *testing.T) {
|
|||
var obj testObj
|
||||
err := json.Unmarshal(test.jsonBytes, &obj)
|
||||
if test.expectError {
|
||||
assert.NotEmpty(t, err)
|
||||
require.Error(t, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package routeralias
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -40,7 +39,7 @@ func TestRouterAlias(t *testing.T) {
|
|||
runTest := func(meta middleware.Metadata) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
ralias := NewMiddleware(logger.NewLogger("routeralias.test"))
|
||||
handler, err := ralias.GetHandler(context.Background(), meta)
|
||||
handler, err := ralias.GetHandler(t.Context(), meta)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("hit: change router with common request", func(t *testing.T) {
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package routerchecker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
@ -39,7 +38,7 @@ func TestRequestHandlerWithIllegalRouterRule(t *testing.T) {
|
|||
}}}
|
||||
log := logger.NewLogger("routerchecker.test")
|
||||
rchecker := NewMiddleware(log)
|
||||
handler, err := rchecker.GetHandler(context.Background(), meta)
|
||||
handler, err := rchecker.GetHandler(t.Context(), meta)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "http://localhost:5001/v1.0/invoke/qcg.default/method/%20cat%20password", nil)
|
||||
|
@ -56,7 +55,7 @@ func TestRequestHandlerWithLegalRouterRule(t *testing.T) {
|
|||
|
||||
log := logger.NewLogger("routerchecker.test")
|
||||
rchecker := NewMiddleware(log)
|
||||
handler, err := rchecker.GetHandler(context.Background(), meta)
|
||||
handler, err := rchecker.GetHandler(t.Context(), meta)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "http://localhost:5001/v1.0/invoke/qcg.default/method", nil)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package sentinel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
@ -50,7 +49,7 @@ func TestRequestHandlerWithFlowRules(t *testing.T) {
|
|||
|
||||
log := logger.NewLogger("sentinel.test")
|
||||
sentinel := NewMiddleware(log)
|
||||
handler, err := sentinel.GetHandler(context.Background(), meta)
|
||||
handler, err := sentinel.GetHandler(t.Context(), meta)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "http://localhost:5001/v1.0/nodeapp/healthz", nil)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package wasm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -58,7 +57,7 @@ func benchmarkMiddleware(b *testing.B, url string) {
|
|||
l := logger.NewLogger(b.Name())
|
||||
l.SetOutput(io.Discard)
|
||||
|
||||
handlerFn, err := NewMiddleware(l).GetHandler(context.Background(), dapr.Metadata{Base: md})
|
||||
handlerFn, err := NewMiddleware(l).GetHandler(b.Context(), dapr.Metadata{Base: md})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ func benchmark(
|
|||
b.Run(name, func(b *testing.B) {
|
||||
// We don't report allocations because memory allocations for TinyGo are
|
||||
// in wasm which isn't visible to the Go benchmark.
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
h.ServeHTTP(fakeResponseWriter{}, newRequest())
|
||||
}
|
||||
})
|
||||
|
|
|
@ -15,7 +15,6 @@ package wasm
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
_ "embed"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -46,7 +45,7 @@ func Test_middleware_log(t *testing.T) {
|
|||
|
||||
m := &middleware{logger: l}
|
||||
message := "alert"
|
||||
m.Log(context.Background(), api.LogLevelInfo, message)
|
||||
m.Log(t.Context(), api.LogLevelInfo, message)
|
||||
|
||||
require.Contains(t, buf.String(), `level=info msg=alert`)
|
||||
}
|
||||
|
@ -99,7 +98,7 @@ func Test_middleware_getHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
tc := tt
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
h, err := m.getHandler(context.Background(), dapr.Metadata{Base: tc.metadata})
|
||||
h, err := m.getHandler(t.Context(), dapr.Metadata{Base: tc.metadata})
|
||||
if tc.expectedErr == "" {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, h.mw)
|
||||
|
@ -120,7 +119,7 @@ func Test_Example(t *testing.T) {
|
|||
// tinygo build -o router.wasm -scheduler=none --no-debug -target=wasi router.go`
|
||||
"url": "file://example/router.wasm",
|
||||
}}
|
||||
handlerFn, err := NewMiddleware(l).GetHandler(context.Background(), dapr.Metadata{Base: meta})
|
||||
handlerFn, err := NewMiddleware(l).GetHandler(t.Context(), dapr.Metadata{Base: meta})
|
||||
require.NoError(t, err)
|
||||
|
||||
handler := handlerFn(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
|
|
|
@ -16,7 +16,6 @@ package internal_test
|
|||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -167,7 +166,7 @@ func Test_EndToEnd(t *testing.T) {
|
|||
meta.Properties[k] = v
|
||||
}
|
||||
}
|
||||
handlerFn, err := wasm.NewMiddleware(l).GetHandler(context.Background(), middleware.Metadata{Base: meta})
|
||||
handlerFn, err := wasm.NewMiddleware(l).GetHandler(t.Context(), middleware.Metadata{Base: meta})
|
||||
require.NoError(t, err)
|
||||
handler := handlerFn(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
tc.test(t, handler, &buf)
|
||||
|
@ -215,7 +214,7 @@ func Test_EndToEnd(t *testing.T) {
|
|||
meta.Properties[k] = v
|
||||
}
|
||||
}
|
||||
handlerFn, err := wasm.NewMiddleware(l).GetHandler(context.Background(), middleware.Metadata{Base: meta})
|
||||
handlerFn, err := wasm.NewMiddleware(l).GetHandler(t.Context(), middleware.Metadata{Base: meta})
|
||||
require.NoError(t, err)
|
||||
handler := handlerFn(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
tc.test(t, handler, &buf)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package consul
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
|
@ -198,7 +197,7 @@ func TestInit(t *testing.T) {
|
|||
var mock mockClient
|
||||
resolver := newResolver(logger.NewLogger("test"), resolverConfig{}, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
_ = resolver.Init(context.Background(), metadata)
|
||||
_ = resolver.Init(t.Context(), metadata)
|
||||
|
||||
assert.Equal(t, 1, mock.initClientCalled)
|
||||
assert.Equal(t, 0, mock.mockAgent.serviceRegisterCalled)
|
||||
|
@ -217,7 +216,7 @@ func TestInit(t *testing.T) {
|
|||
var mock mockClient
|
||||
resolver := newResolver(logger.NewLogger("test"), resolverConfig{}, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
_ = resolver.Init(context.Background(), metadata)
|
||||
_ = resolver.Init(t.Context(), metadata)
|
||||
|
||||
assert.Equal(t, 1, mock.initClientCalled)
|
||||
assert.Equal(t, 1, mock.mockAgent.serviceRegisterCalled)
|
||||
|
@ -237,7 +236,7 @@ func TestInit(t *testing.T) {
|
|||
var mock mockClient
|
||||
resolver := newResolver(logger.NewLogger("test"), resolverConfig{}, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
_ = resolver.Init(context.Background(), metadata)
|
||||
_ = resolver.Init(t.Context(), metadata)
|
||||
|
||||
assert.Equal(t, 1, mock.initClientCalled)
|
||||
assert.Equal(t, 1, mock.mockAgent.serviceRegisterCalled)
|
||||
|
@ -346,7 +345,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), cfg, mock, mockReg, make(chan struct{}))
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
// no apps in registry - cache miss, call agent directly
|
||||
assert.Equal(t, 1, mockReg.getCalled)
|
||||
|
@ -373,11 +372,11 @@ func TestResolveID(t *testing.T) {
|
|||
assert.Equal(t, int32(2), mockReg.addOrUpdateCalled.Load())
|
||||
|
||||
// resolve id should only hit cache now
|
||||
addr, _ = resolver.ResolveID(context.Background(), req)
|
||||
addr, _ = resolver.ResolveID(t.Context(), req)
|
||||
assert.Equal(t, "10.3.245.137:70007", addr)
|
||||
addr, _ = resolver.ResolveID(context.Background(), req)
|
||||
addr, _ = resolver.ResolveID(t.Context(), req)
|
||||
assert.Equal(t, "10.3.245.137:70007", addr)
|
||||
addr, _ = resolver.ResolveID(context.Background(), req)
|
||||
addr, _ = resolver.ResolveID(t.Context(), req)
|
||||
assert.Equal(t, "10.3.245.137:70007", addr)
|
||||
|
||||
assert.Equal(t, 2, mock.mockHealth.serviceCalled)
|
||||
|
@ -504,7 +503,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), cfg, &mock, mockReg, make(chan struct{}))
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
// no apps in registry - cache miss, call agent directly
|
||||
assert.Equal(t, 1, mockReg.getCalled)
|
||||
|
@ -532,9 +531,9 @@ func TestResolveID(t *testing.T) {
|
|||
assert.Equal(t, int32(2), mockReg.addOrUpdateCalled.Load())
|
||||
|
||||
// resolve id should only hit cache now
|
||||
_, _ = resolver.ResolveID(context.Background(), req)
|
||||
_, _ = resolver.ResolveID(context.Background(), req)
|
||||
_, _ = resolver.ResolveID(context.Background(), req)
|
||||
_, _ = resolver.ResolveID(t.Context(), req)
|
||||
_, _ = resolver.ResolveID(t.Context(), req)
|
||||
_, _ = resolver.ResolveID(t.Context(), req)
|
||||
assert.Equal(t, 2, mock.mockHealth.serviceCalled)
|
||||
|
||||
// change one check for node1 app to critical
|
||||
|
@ -649,7 +648,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), cfg, mock, mockReg, make(chan struct{}))
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
// Cache miss pass through
|
||||
assert.Equal(t, 1, mockReg.getCalled)
|
||||
|
@ -750,7 +749,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), cfg, mock, mockReg, make(chan struct{})).(*resolver)
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
// Cache miss pass through
|
||||
assert.Equal(t, 1, mockReg.getCalled)
|
||||
|
@ -785,7 +784,7 @@ func TestResolveID(t *testing.T) {
|
|||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
_, err := resolver.ResolveID(context.Background(), req)
|
||||
_, err := resolver.ResolveID(t.Context(), req)
|
||||
assert.Equal(t, 1, mock.mockHealth.serviceCalled)
|
||||
require.Error(t, err)
|
||||
},
|
||||
|
@ -813,7 +812,7 @@ func TestResolveID(t *testing.T) {
|
|||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
assert.Equal(t, "10.3.245.137:50005", addr)
|
||||
},
|
||||
|
@ -841,7 +840,7 @@ func TestResolveID(t *testing.T) {
|
|||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
assert.Equal(t, "[2001:db8:3333:4444:5555:6666:7777:8888]:50005", addr)
|
||||
},
|
||||
|
@ -870,7 +869,7 @@ func TestResolveID(t *testing.T) {
|
|||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
assert.Equal(t, "localhost:50005", addr)
|
||||
},
|
||||
|
@ -910,7 +909,7 @@ func TestResolveID(t *testing.T) {
|
|||
total1 := 0
|
||||
total2 := 0
|
||||
for range 100 {
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
if addr == "10.3.245.137:50005" {
|
||||
total1++
|
||||
|
@ -965,7 +964,7 @@ func TestResolveID(t *testing.T) {
|
|||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
addr, _ := resolver.ResolveID(context.Background(), req)
|
||||
addr, _ := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
assert.Equal(t, "10.3.245.137:50005", addr)
|
||||
},
|
||||
|
@ -993,7 +992,7 @@ func TestResolveID(t *testing.T) {
|
|||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
_, err := resolver.ResolveID(context.Background(), req)
|
||||
_, err := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
require.Error(t, err)
|
||||
},
|
||||
|
@ -1018,7 +1017,7 @@ func TestResolveID(t *testing.T) {
|
|||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, ®istry{}, make(chan struct{}))
|
||||
|
||||
_, err := resolver.ResolveID(context.Background(), req)
|
||||
_, err := resolver.ResolveID(t.Context(), req)
|
||||
|
||||
require.Error(t, err)
|
||||
},
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package kubernetes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -29,7 +28,7 @@ func TestResolve(t *testing.T) {
|
|||
request := nameresolution.ResolveRequest{ID: "myid", Namespace: "abc", Port: 1234}
|
||||
|
||||
const expect = "myid-dapr.abc.svc.cluster.local:1234"
|
||||
target, err := resolver.ResolveID(context.Background(), request)
|
||||
target, err := resolver.ResolveID(t.Context(), request)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expect, target)
|
||||
|
@ -37,7 +36,7 @@ func TestResolve(t *testing.T) {
|
|||
|
||||
func TestResolveWithCustomClusterDomain(t *testing.T) {
|
||||
resolver := NewResolver(logger.NewLogger("test"))
|
||||
_ = resolver.Init(context.Background(), nameresolution.Metadata{
|
||||
_ = resolver.Init(t.Context(), nameresolution.Metadata{
|
||||
Configuration: map[string]interface{}{
|
||||
"clusterDomain": "mydomain.com",
|
||||
},
|
||||
|
@ -45,7 +44,7 @@ func TestResolveWithCustomClusterDomain(t *testing.T) {
|
|||
request := nameresolution.ResolveRequest{ID: "myid", Namespace: "abc", Port: 1234}
|
||||
|
||||
const expect = "myid-dapr.abc.svc.mydomain.com:1234"
|
||||
target, err := resolver.ResolveID(context.Background(), request)
|
||||
target, err := resolver.ResolveID(t.Context(), request)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expect, target)
|
||||
|
@ -53,7 +52,7 @@ func TestResolveWithCustomClusterDomain(t *testing.T) {
|
|||
|
||||
func TestResolveWithTemplate(t *testing.T) {
|
||||
resolver := NewResolver(logger.NewLogger("test"))
|
||||
_ = resolver.Init(context.Background(), nameresolution.Metadata{
|
||||
_ = resolver.Init(t.Context(), nameresolution.Metadata{
|
||||
Configuration: map[string]interface{}{
|
||||
"template": "{{.ID}}-{{.Namespace}}.internal:{{.Port}}",
|
||||
},
|
||||
|
@ -61,7 +60,7 @@ func TestResolveWithTemplate(t *testing.T) {
|
|||
|
||||
request := nameresolution.ResolveRequest{ID: "myid", Namespace: "abc", Port: 1234}
|
||||
const expected = "myid-abc.internal:1234"
|
||||
target, err := resolver.ResolveID(context.Background(), request)
|
||||
target, err := resolver.ResolveID(t.Context(), request)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, target)
|
||||
|
@ -69,7 +68,7 @@ func TestResolveWithTemplate(t *testing.T) {
|
|||
|
||||
func TestResolveWithTemplateAndData(t *testing.T) {
|
||||
resolver := NewResolver(logger.NewLogger("test"))
|
||||
_ = resolver.Init(context.Background(), nameresolution.Metadata{
|
||||
_ = resolver.Init(t.Context(), nameresolution.Metadata{
|
||||
Configuration: map[string]interface{}{
|
||||
"template": "{{.ID}}-{{.Data.region}}.internal:{{.Port}}",
|
||||
},
|
||||
|
@ -84,7 +83,7 @@ func TestResolveWithTemplateAndData(t *testing.T) {
|
|||
},
|
||||
}
|
||||
const expected = "myid-myland.internal:1234"
|
||||
target, err := resolver.ResolveID(context.Background(), request)
|
||||
target, err := resolver.ResolveID(t.Context(), request)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, target)
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package mdns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"sync"
|
||||
|
@ -77,7 +76,7 @@ func TestInitMetadata(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.missingProp+" is missing", func(t *testing.T) {
|
||||
// act
|
||||
err := resolver.Init(context.Background(), nr.Metadata{Instance: tt.instance})
|
||||
err := resolver.Init(t.Context(), nr.Metadata{Instance: tt.instance})
|
||||
|
||||
// assert
|
||||
require.Error(t, err)
|
||||
|
@ -96,7 +95,7 @@ func TestInitRegister(t *testing.T) {
|
|||
}}
|
||||
|
||||
// act
|
||||
err := resolver.Init(context.Background(), md)
|
||||
err := resolver.Init(t.Context(), md)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -116,9 +115,9 @@ func TestInitRegisterDuplicate(t *testing.T) {
|
|||
}}
|
||||
|
||||
// act
|
||||
err := resolver.Init(context.Background(), md)
|
||||
err := resolver.Init(t.Context(), md)
|
||||
require.NoError(t, err)
|
||||
err = resolver.Init(context.Background(), md2)
|
||||
err = resolver.Init(t.Context(), md2)
|
||||
expectedError := "app id testAppID already registered for port 1234"
|
||||
require.EqualErrorf(t, err, expectedError, "Error should be: %v, got %v", expectedError, err)
|
||||
}
|
||||
|
@ -134,11 +133,11 @@ func TestResolver(t *testing.T) {
|
|||
}}
|
||||
|
||||
// act
|
||||
err := resolver.Init(context.Background(), md)
|
||||
err := resolver.Init(t.Context(), md)
|
||||
require.NoError(t, err)
|
||||
|
||||
request := nr.ResolveRequest{ID: "testAppID"}
|
||||
pt, err := resolver.ResolveID(context.Background(), request)
|
||||
pt, err := resolver.ResolveID(t.Context(), request)
|
||||
|
||||
// assert
|
||||
require.NoError(t, err)
|
||||
|
@ -155,11 +154,11 @@ func TestResolverClose(t *testing.T) {
|
|||
}}
|
||||
|
||||
// act
|
||||
err := resolver.Init(context.Background(), md)
|
||||
err := resolver.Init(t.Context(), md)
|
||||
require.NoError(t, err)
|
||||
|
||||
request := nr.ResolveRequest{ID: "testAppID"}
|
||||
pt, err := resolver.ResolveID(context.Background(), request)
|
||||
pt, err := resolver.ResolveID(t.Context(), request)
|
||||
|
||||
// assert
|
||||
require.NoError(t, err)
|
||||
|
@ -203,7 +202,7 @@ func TestResolverMultipleInstances(t *testing.T) {
|
|||
request := nr.ResolveRequest{ID: "testAppID"}
|
||||
|
||||
// first resolution will return the first responder's address and trigger a cache refresh.
|
||||
addr1, err := resolver.ResolveID(context.Background(), request)
|
||||
addr1, err := resolver.ResolveID(t.Context(), request)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, []string{instanceAPQDN, instanceBPQDN}, addr1)
|
||||
|
||||
|
@ -218,7 +217,7 @@ func TestResolverMultipleInstances(t *testing.T) {
|
|||
instanceACount := atomic.Uint32{}
|
||||
instanceBCount := atomic.Uint32{}
|
||||
for range 100 {
|
||||
addr, err := resolver.ResolveID(context.Background(), request)
|
||||
addr, err := resolver.ResolveID(t.Context(), request)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, []string{instanceAPQDN, instanceBPQDN}, addr)
|
||||
if addr == instanceAPQDN {
|
||||
|
@ -239,7 +238,7 @@ func TestResolverNotFound(t *testing.T) {
|
|||
|
||||
// act
|
||||
request := nr.ResolveRequest{ID: "testAppIDNotFound"}
|
||||
pt, err := resolver.ResolveID(context.Background(), request)
|
||||
pt, err := resolver.ResolveID(t.Context(), request)
|
||||
|
||||
// assert
|
||||
expectedError := "couldn't find service: testAppIDNotFound"
|
||||
|
@ -288,7 +287,7 @@ func ResolverConcurrencySubsriberClear(t *testing.T) {
|
|||
}}
|
||||
|
||||
// act
|
||||
err := resolver.Init(context.Background(), md)
|
||||
err := resolver.Init(t.Context(), md)
|
||||
require.NoError(t, err)
|
||||
|
||||
request := nr.ResolveRequest{ID: "testAppID"}
|
||||
|
@ -299,7 +298,7 @@ func ResolverConcurrencySubsriberClear(t *testing.T) {
|
|||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
pt, err := resolver.ResolveID(context.Background(), request)
|
||||
pt, err := resolver.ResolveID(t.Context(), request)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, localhost+":1234", pt)
|
||||
}()
|
||||
|
@ -371,7 +370,7 @@ func ResolverConcurrencyFound(t *testing.T) {
|
|||
request := nr.ResolveRequest{ID: appID}
|
||||
|
||||
start := time.Now()
|
||||
pt, err := resolver.ResolveID(context.Background(), request)
|
||||
pt, err := resolver.ResolveID(t.Context(), request)
|
||||
elapsed := time.Since(start)
|
||||
// assert
|
||||
require.NoError(t, err)
|
||||
|
@ -420,7 +419,7 @@ func ResolverConcurrencyNotFound(t *testing.T) {
|
|||
|
||||
// act
|
||||
start := time.Now()
|
||||
pt, err := resolver.ResolveID(context.Background(), request)
|
||||
pt, err := resolver.ResolveID(t.Context(), request)
|
||||
elapsed := time.Since(start)
|
||||
|
||||
// assert
|
||||
|
|
|
@ -101,7 +101,7 @@ func (m *sqliteMetadata) InitWithMetadata(meta nameresolution.Metadata) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m sqliteMetadata) GetAddress() string {
|
||||
func (m *sqliteMetadata) GetAddress() string {
|
||||
return net.JoinHostPort(m.hostAddress, strconv.Itoa(m.port))
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ limitations under the License.
|
|||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -28,7 +27,7 @@ func TestSqliteNameResolver(t *testing.T) {
|
|||
nr := NewResolver(logger.NewLogger("test")).(*resolver)
|
||||
|
||||
t.Run("Init", func(t *testing.T) {
|
||||
err := nr.Init(context.Background(), nameresolution.Metadata{
|
||||
err := nr.Init(t.Context(), nameresolution.Metadata{
|
||||
Instance: nameresolution.Instance{
|
||||
Address: "127.0.0.1",
|
||||
DaprInternalPort: 1234,
|
||||
|
@ -91,7 +90,7 @@ func TestSqliteNameResolver(t *testing.T) {
|
|||
for name, tc := range tt {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if len(tc.expectAny) == 0 {
|
||||
res, err := nr.ResolveID(context.Background(), nameresolution.ResolveRequest{ID: tc.appID})
|
||||
res, err := nr.ResolveID(t.Context(), nameresolution.ResolveRequest{ID: tc.appID})
|
||||
|
||||
if tc.expectEmpty {
|
||||
require.Error(t, err)
|
||||
|
@ -103,7 +102,7 @@ func TestSqliteNameResolver(t *testing.T) {
|
|||
}
|
||||
} else {
|
||||
for i := range 20 {
|
||||
res, err := nr.ResolveID(context.Background(), nameresolution.ResolveRequest{ID: tc.appID})
|
||||
res, err := nr.ResolveID(t.Context(), nameresolution.ResolveRequest{ID: tc.appID})
|
||||
require.NoErrorf(t, err, "Error on iteration %d", i)
|
||||
require.Contains(t, tc.expectAny, res)
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ func TestSqliteNameResolver(t *testing.T) {
|
|||
time.Sleep(time.Second)
|
||||
|
||||
// Renew
|
||||
err = nr.doRenewRegistration(context.Background(), addr)
|
||||
err = nr.doRenewRegistration(t.Context(), addr)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get updated last_update
|
||||
|
@ -140,7 +139,7 @@ func TestSqliteNameResolver(t *testing.T) {
|
|||
|
||||
t.Run("Lost registration", func(t *testing.T) {
|
||||
// Renew
|
||||
err := nr.doRenewRegistration(context.Background(), "fail")
|
||||
err := nr.doRenewRegistration(t.Context(), "fail")
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, errRegistrationLost)
|
||||
})
|
||||
|
|
|
@ -70,7 +70,7 @@ func testReadIotHubEvents(t *testing.T) {
|
|||
logger := kitLogger.NewLogger("pubsub.azure.eventhubs.integration.test")
|
||||
logger.SetOutputLevel(kitLogger.DebugLevel)
|
||||
eh := NewAzureEventHubs(logger).(*AzureEventHubs)
|
||||
err := eh.Init(context.Background(), createIotHubPubsubMetadata())
|
||||
err := eh.Init(t.Context(), createIotHubPubsubMetadata())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Invoke az CLI via bash script to send test IoT device events
|
||||
|
@ -94,7 +94,7 @@ func testReadIotHubEvents(t *testing.T) {
|
|||
"requireAllProperties": "true",
|
||||
},
|
||||
}
|
||||
err = eh.Subscribe(context.Background(), req, handler)
|
||||
err = eh.Subscribe(t.Context(), req, handler)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Note: azure-event-hubs-go SDK defaultLeasePersistenceInterval is 5s
|
||||
|
|
|
@ -26,32 +26,32 @@ import (
|
|||
|
||||
func TestNewInMemoryBus(t *testing.T) {
|
||||
bus := New(logger.NewLogger("test"))
|
||||
bus.Init(context.Background(), pubsub.Metadata{})
|
||||
bus.Init(t.Context(), pubsub.Metadata{})
|
||||
|
||||
ch := make(chan []byte)
|
||||
bus.Subscribe(context.Background(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
bus.Subscribe(t.Context(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
return publish(ch, msg)
|
||||
})
|
||||
|
||||
bus.Publish(context.Background(), &pubsub.PublishRequest{Data: []byte("ABCD"), Topic: "demo"})
|
||||
bus.Publish(t.Context(), &pubsub.PublishRequest{Data: []byte("ABCD"), Topic: "demo"})
|
||||
assert.Equal(t, "ABCD", string(<-ch))
|
||||
}
|
||||
|
||||
func TestMultipleSubscribers(t *testing.T) {
|
||||
bus := New(logger.NewLogger("test"))
|
||||
bus.Init(context.Background(), pubsub.Metadata{})
|
||||
bus.Init(t.Context(), pubsub.Metadata{})
|
||||
|
||||
ch1 := make(chan []byte)
|
||||
ch2 := make(chan []byte)
|
||||
bus.Subscribe(context.Background(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
bus.Subscribe(t.Context(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
return publish(ch1, msg)
|
||||
})
|
||||
|
||||
bus.Subscribe(context.Background(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
bus.Subscribe(t.Context(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
return publish(ch2, msg)
|
||||
})
|
||||
|
||||
bus.Publish(context.Background(), &pubsub.PublishRequest{Data: []byte("ABCD"), Topic: "demo"})
|
||||
bus.Publish(t.Context(), &pubsub.PublishRequest{Data: []byte("ABCD"), Topic: "demo"})
|
||||
|
||||
assert.Equal(t, "ABCD", string(<-ch1))
|
||||
assert.Equal(t, "ABCD", string(<-ch2))
|
||||
|
@ -59,36 +59,36 @@ func TestMultipleSubscribers(t *testing.T) {
|
|||
|
||||
func TestWildcards(t *testing.T) {
|
||||
bus := New(logger.NewLogger("test"))
|
||||
bus.Init(context.Background(), pubsub.Metadata{})
|
||||
bus.Init(t.Context(), pubsub.Metadata{})
|
||||
|
||||
ch1 := make(chan []byte)
|
||||
ch2 := make(chan []byte)
|
||||
bus.Subscribe(context.Background(), pubsub.SubscribeRequest{Topic: "mytopic"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
bus.Subscribe(t.Context(), pubsub.SubscribeRequest{Topic: "mytopic"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
return publish(ch1, msg)
|
||||
})
|
||||
|
||||
bus.Subscribe(context.Background(), pubsub.SubscribeRequest{Topic: "topic*"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
bus.Subscribe(t.Context(), pubsub.SubscribeRequest{Topic: "topic*"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
return publish(ch2, msg)
|
||||
})
|
||||
|
||||
bus.Publish(context.Background(), &pubsub.PublishRequest{Data: []byte("1"), Topic: "mytopic"})
|
||||
bus.Publish(t.Context(), &pubsub.PublishRequest{Data: []byte("1"), Topic: "mytopic"})
|
||||
assert.Equal(t, "1", string(<-ch1))
|
||||
|
||||
bus.Publish(context.Background(), &pubsub.PublishRequest{Data: []byte("2"), Topic: "topic1"})
|
||||
bus.Publish(t.Context(), &pubsub.PublishRequest{Data: []byte("2"), Topic: "topic1"})
|
||||
assert.Equal(t, "2", string(<-ch2))
|
||||
|
||||
bus.Publish(context.Background(), &pubsub.PublishRequest{Data: []byte("3"), Topic: "topicX"})
|
||||
bus.Publish(t.Context(), &pubsub.PublishRequest{Data: []byte("3"), Topic: "topicX"})
|
||||
assert.Equal(t, "3", string(<-ch2))
|
||||
}
|
||||
|
||||
func TestRetry(t *testing.T) {
|
||||
bus := New(logger.NewLogger("test"))
|
||||
bus.Init(context.Background(), pubsub.Metadata{})
|
||||
bus.Init(t.Context(), pubsub.Metadata{})
|
||||
|
||||
ch := make(chan []byte)
|
||||
i := -1
|
||||
|
||||
bus.Subscribe(context.Background(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
bus.Subscribe(t.Context(), pubsub.SubscribeRequest{Topic: "demo"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
i++
|
||||
if i < 5 {
|
||||
return errors.New("if at first you don't succeed")
|
||||
|
@ -97,7 +97,7 @@ func TestRetry(t *testing.T) {
|
|||
return publish(ch, msg)
|
||||
})
|
||||
|
||||
bus.Publish(context.Background(), &pubsub.PublishRequest{Data: []byte("ABCD"), Topic: "demo"})
|
||||
bus.Publish(t.Context(), &pubsub.PublishRequest{Data: []byte("ABCD"), Topic: "demo"})
|
||||
assert.Equal(t, "ABCD", string(<-ch))
|
||||
assert.Equal(t, 5, i)
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ func TestNewJetStream_EmphemeralPushConsumer(t *testing.T) {
|
|||
bus := NewJetStream(logger.NewLogger("test"))
|
||||
defer bus.Close()
|
||||
|
||||
err := bus.Init(context.Background(), pubsub.Metadata{
|
||||
err := bus.Init(t.Context(), pubsub.Metadata{
|
||||
Base: mdata.Base{
|
||||
Properties: map[string]string{
|
||||
"natsURL": ns.ClientURL(),
|
||||
|
@ -74,7 +74,7 @@ func TestNewJetStream_EmphemeralPushConsumer(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
ch := make(chan []byte, 1)
|
||||
|
||||
err = bus.Subscribe(ctx, pubsub.SubscribeRequest{Topic: "test"}, func(ctx context.Context, msg *pubsub.NewMessage) error {
|
||||
|
@ -108,7 +108,7 @@ func TestNewJetStream_DurableQueuePushConsumer(t *testing.T) {
|
|||
bus := NewJetStream(logger.NewLogger("test"))
|
||||
defer bus.Close()
|
||||
|
||||
err := bus.Init(context.Background(), pubsub.Metadata{
|
||||
err := bus.Init(t.Context(), pubsub.Metadata{
|
||||
Base: mdata.Base{
|
||||
Properties: map[string]string{
|
||||
"natsURL": ns.ClientURL(),
|
||||
|
@ -119,7 +119,7 @@ func TestNewJetStream_DurableQueuePushConsumer(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
ch := make(chan []byte, 2)
|
||||
|
||||
// Two subscriptions to the same queue group. If there is a config
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue