code
stringlengths 0
56.1M
| repo_name
stringclasses 515
values | path
stringlengths 2
147
| language
stringclasses 447
values | license
stringclasses 7
values | size
int64 0
56.8M
|
---|---|---|---|---|---|
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"fmt"
"runtime"
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc"
grpcCodes "google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"github.com/dapr/components-contrib/state"
apierrors "github.com/dapr/dapr/pkg/api/errors"
commonv1 "github.com/dapr/dapr/pkg/proto/common/v1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/statestore"
"github.com/dapr/dapr/tests/integration/framework/process/statestore/inmemory"
"github.com/dapr/dapr/tests/integration/framework/socket"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(errors))
}
type errors struct {
daprd *procdaprd.Daprd
queryErr func(*testing.T) error
}
func (e *errors) Setup(t *testing.T) []framework.Option {
if runtime.GOOS == "windows" {
t.Skip("skipping unix socket based test on windows")
}
socket := socket.New(t)
e.queryErr = func(t *testing.T) error {
require.FailNow(t, "query should not be called")
return nil
}
storeWithNoTransactional := statestore.New(t,
statestore.WithSocket(socket),
statestore.WithStateStore(inmemory.New(t,
inmemory.WithFeatures(),
)),
)
storeWithQuerier := statestore.New(t,
statestore.WithSocket(socket),
statestore.WithStateStore(inmemory.NewQuerier(t,
inmemory.WithQueryFn(func(context.Context, *state.QueryRequest) (*state.QueryResponse, error) {
return nil, e.queryErr(t)
}),
)),
)
storeWithMultiMaxSize := statestore.New(t,
statestore.WithSocket(socket),
statestore.WithStateStore(inmemory.NewTransactionalMultiMaxSize(t,
inmemory.WithTransactionalStoreMultiMaxSizeFn(func() int {
return 1
}),
)),
)
e.daprd = procdaprd.New(t, procdaprd.WithResourceFiles(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore
spec:
type: state.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore-non-transactional
spec:
type: state.%s
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore-pluggable-querier
spec:
type: state.%s
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore-pluggable-multimaxsize
spec:
type: state.%s
version: v1
`, storeWithNoTransactional.SocketName(), storeWithQuerier.SocketName(), storeWithMultiMaxSize.SocketName())),
procdaprd.WithSocket(t, socket),
)
return []framework.Option{
framework.WithProcesses(storeWithNoTransactional, storeWithQuerier, storeWithMultiMaxSize, e.daprd),
}
}
func (e *errors) Run(t *testing.T, ctx context.Context) {
e.daprd.WaitUntilRunning(t, ctx)
client := e.daprd.GRPCClient(t, ctx)
// Covers errutils.StateStoreNotFound()
t.Run("state store doesn't exist", func(t *testing.T) {
req := &rtv1.SaveStateRequest{
StoreName: "mystore-doesnt-exist",
States: []*commonv1.StateItem{{Value: []byte("value1")}},
}
_, err := client.SaveState(ctx, req)
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, grpcCodes.InvalidArgument, s.Code())
require.Equal(t, fmt.Sprintf("state store %s is not found", "mystore-doesnt-exist"), s.Message())
// Check status details
require.Len(t, s.Details(), 1)
var errInfo *errdetails.ErrorInfo
errInfo, ok = s.Details()[0].(*errdetails.ErrorInfo)
require.True(t, ok)
require.Equal(t, "DAPR_STATE_NOT_FOUND", errInfo.GetReason())
require.Equal(t, "dapr.io", errInfo.GetDomain())
require.Nil(t, errInfo.GetMetadata())
})
// Covers errutils.StateStoreInvalidKeyName()
t.Run("invalid key name", func(t *testing.T) {
keyName := "invalid||key"
req := &rtv1.SaveStateRequest{
StoreName: "mystore",
States: []*commonv1.StateItem{{Key: keyName, Value: []byte("value1")}},
}
_, err := client.SaveState(ctx, req)
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, grpcCodes.InvalidArgument, s.Code())
require.Equal(t, fmt.Sprintf("input key/keyPrefix '%s' can't contain '||'", keyName), s.Message())
// Check status details
require.Len(t, s.Details(), 3)
var errInfo *errdetails.ErrorInfo
var resInfo *errdetails.ResourceInfo
var badRequest *errdetails.BadRequest
for _, detail := range s.Details() {
switch d := detail.(type) {
case *errdetails.ErrorInfo:
errInfo = d
case *errdetails.ResourceInfo:
resInfo = d
case *errdetails.BadRequest:
badRequest = d
default:
require.FailNow(t, "unexpected status detail")
}
}
require.NotNil(t, errInfo, "ErrorInfo should be present")
require.Equal(t, "DAPR_STATE_ILLEGAL_KEY", errInfo.GetReason())
require.Equal(t, "dapr.io", errInfo.GetDomain())
require.Nil(t, errInfo.GetMetadata())
require.NotNil(t, resInfo, "ResourceInfo should be present")
require.Equal(t, "state", resInfo.GetResourceType())
require.Equal(t, "mystore", resInfo.GetResourceName())
require.Empty(t, resInfo.GetOwner())
require.Empty(t, resInfo.GetDescription())
require.NotNil(t, badRequest, "BadRequest_FieldViolation should be present")
require.Equal(t, keyName, badRequest.GetFieldViolations()[0].GetField())
require.Equal(t, fmt.Sprintf("input key/keyPrefix '%s' can't contain '||'", keyName), badRequest.GetFieldViolations()[0].GetDescription())
})
// Covers errutils.StateStoreNotConfigured()
t.Run("state store not configured", func(t *testing.T) {
// Start a new daprd without state store
daprdNoStateStore := procdaprd.New(t, procdaprd.WithAppID("daprd_no_state_store"))
daprdNoStateStore.Run(t, ctx)
daprdNoStateStore.WaitUntilRunning(t, ctx)
defer daprdNoStateStore.Cleanup(t)
connNoStateStore, err := grpc.DialContext(ctx, fmt.Sprintf("localhost:%d", daprdNoStateStore.GRPCPort()), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, connNoStateStore.Close()) })
clientNoStateStore := rtv1.NewDaprClient(connNoStateStore)
storeName := "mystore"
req := &rtv1.SaveStateRequest{
StoreName: storeName,
States: []*commonv1.StateItem{{Value: []byte("value1")}},
}
_, err = clientNoStateStore.SaveState(ctx, req)
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, grpcCodes.FailedPrecondition, s.Code())
require.Equal(t, fmt.Sprintf("state store %s is not configured", storeName), s.Message())
// Check status details
require.Len(t, s.Details(), 1)
errInfo := s.Details()[0]
require.IsType(t, &errdetails.ErrorInfo{}, errInfo)
require.Equal(t, "DAPR_STATE_NOT_CONFIGURED", errInfo.(*errdetails.ErrorInfo).GetReason())
require.Equal(t, "dapr.io", errInfo.(*errdetails.ErrorInfo).GetDomain())
require.Nil(t, errInfo.(*errdetails.ErrorInfo).GetMetadata())
})
// Covers errors.StateStoreQueryUnsupported()
t.Run("state store doesn't support query api", func(t *testing.T) {
req := &rtv1.QueryStateRequest{
StoreName: "mystore",
Query: `{"filter":{"EQ":{"state":"CA"}},"sort":[{"key":"person.id","order":"DESC"}]}`,
}
_, err := client.QueryStateAlpha1(ctx, req)
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, grpcCodes.Internal, s.Code())
require.Equal(t, "state store does not support querying", s.Message())
// Check status details
require.Len(t, s.Details(), 2)
var errInfo *errdetails.ErrorInfo
var resInfo *errdetails.ResourceInfo
for _, detail := range s.Details() {
switch d := detail.(type) {
case *errdetails.ErrorInfo:
errInfo = d
case *errdetails.ResourceInfo:
resInfo = d
default:
require.FailNow(t, "unexpected status detail")
}
}
require.NotNil(t, errInfo, "ErrorInfo should be present")
require.Equal(t, "DAPR_STATE_QUERYING_NOT_SUPPORTED", errInfo.GetReason())
require.Equal(t, "dapr.io", errInfo.GetDomain())
require.Nil(t, errInfo.GetMetadata())
require.NotNil(t, resInfo, "ResourceInfo should be present")
require.Equal(t, "state", resInfo.GetResourceType())
require.Equal(t, "mystore", resInfo.GetResourceName())
require.Empty(t, resInfo.GetOwner())
require.Empty(t, resInfo.GetDescription())
})
// Covers errutils.NewErrStateStoreQueryFailed()
t.Run("state store query failed", func(t *testing.T) {
stateStoreName := "mystore-pluggable-querier"
t.Cleanup(func() {
e.queryErr = func(t *testing.T) error {
require.FailNow(t, "query should not be called")
return nil
}
})
e.queryErr = func(*testing.T) error {
return apierrors.StateStore(stateStoreName).QueryFailed("this is a custom error string")
}
req := &rtv1.QueryStateRequest{
StoreName: stateStoreName,
Query: `{"filter":{"EQ":{"state":"CA"}},"sort":[{"key":"person.id","order":"DESC"}]}`,
}
_, err := client.QueryStateAlpha1(ctx, req)
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, grpcCodes.Internal, s.Code())
require.Contains(t, s.Message(), fmt.Sprintf("state store %s query failed: this is a custom error string", stateStoreName))
// Check status details
require.Len(t, s.Details(), 2)
var errInfo *errdetails.ErrorInfo
var resInfo *errdetails.ResourceInfo
for _, detail := range s.Details() {
switch d := detail.(type) {
case *errdetails.ErrorInfo:
errInfo = d
case *errdetails.ResourceInfo:
resInfo = d
default:
require.FailNow(t, "unexpected status detail")
}
}
require.NotNil(t, errInfo, "ErrorInfo should be present")
require.Equal(t, "DAPR_STATE_QUERY_FAILED", errInfo.GetReason())
require.Equal(t, "dapr.io", errInfo.GetDomain())
require.Nil(t, errInfo.GetMetadata())
require.NotNil(t, resInfo, "ResourceInfo should be present")
require.Equal(t, "state", resInfo.GetResourceType())
require.Equal(t, stateStoreName, resInfo.GetResourceName())
require.Empty(t, resInfo.GetOwner())
require.Empty(t, resInfo.GetDescription())
})
// Covers errutils.StateStoreTooManyTransactionalOps()
t.Run("state store too many transactional operations", func(t *testing.T) {
stateStoreName := "mystore-pluggable-multimaxsize"
ops := make([]*rtv1.TransactionalStateOperation, 0)
ops = append(ops, &rtv1.TransactionalStateOperation{
OperationType: "upsert",
Request: &commonv1.StateItem{
Key: "key1",
Value: []byte("val1"),
},
},
&rtv1.TransactionalStateOperation{
OperationType: "delete",
Request: &commonv1.StateItem{
Key: "key2",
},
})
req := &rtv1.ExecuteStateTransactionRequest{
StoreName: stateStoreName,
Operations: ops,
}
_, err := client.ExecuteStateTransaction(ctx, req)
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, grpcCodes.InvalidArgument, s.Code())
require.Equal(t, fmt.Sprintf("the transaction contains %d operations, which is more than what the state store supports: %d", 2, 1), s.Message())
// Check status details
require.Len(t, s.Details(), 2)
var errInfo *errdetails.ErrorInfo
var resInfo *errdetails.ResourceInfo
for _, detail := range s.Details() {
switch d := detail.(type) {
case *errdetails.ErrorInfo:
errInfo = d
case *errdetails.ResourceInfo:
resInfo = d
default:
require.FailNow(t, "unexpected status detail")
}
}
require.NotNil(t, errInfo, "ErrorInfo should be present")
require.Equal(t, "DAPR_STATE_TOO_MANY_TRANSACTIONS", errInfo.GetReason())
require.Equal(t, "dapr.io", errInfo.GetDomain())
require.Equal(t, map[string]string{
"currentOpsTransaction": "2", "maxOpsPerTransaction": "1",
}, errInfo.GetMetadata())
require.NotNil(t, resInfo, "ResourceInfo should be present")
require.Equal(t, "state", resInfo.GetResourceType())
require.Equal(t, stateStoreName, resInfo.GetResourceName())
require.Empty(t, resInfo.GetOwner())
require.Empty(t, resInfo.GetDescription())
})
// Covers errutils.StateStoreTransactionsNotSupported()
t.Run("state transactions not supported", func(t *testing.T) {
stateStoreName := "mystore-non-transactional"
ops := make([]*rtv1.TransactionalStateOperation, 0)
ops = append(ops, &rtv1.TransactionalStateOperation{
OperationType: "upsert",
Request: &commonv1.StateItem{
Key: "key1",
Value: []byte("val1"),
},
},
&rtv1.TransactionalStateOperation{
OperationType: "delete",
Request: &commonv1.StateItem{
Key: "key2",
},
})
req := &rtv1.ExecuteStateTransactionRequest{
StoreName: stateStoreName,
Operations: ops,
}
_, err := client.ExecuteStateTransaction(ctx, req)
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, grpcCodes.Unimplemented, s.Code())
require.Equal(t, fmt.Sprintf("state store %s doesn't support transactions", "mystore-non-transactional"), s.Message())
// Check status details
require.Len(t, s.Details(), 3)
var errInfo *errdetails.ErrorInfo
var resInfo *errdetails.ResourceInfo
var help *errdetails.Help
for _, detail := range s.Details() {
switch d := detail.(type) {
case *errdetails.ErrorInfo:
errInfo = d
case *errdetails.ResourceInfo:
resInfo = d
case *errdetails.Help:
help = d
default:
require.FailNow(t, "unexpected status detail")
}
}
require.NotNil(t, errInfo, "ErrorInfo should be present")
require.Equal(t, "DAPR_STATE_TRANSACTIONS_NOT_SUPPORTED", errInfo.GetReason())
require.Equal(t, "dapr.io", errInfo.GetDomain())
require.NotNil(t, resInfo, "ResourceInfo should be present")
require.Equal(t, "state", resInfo.GetResourceType())
require.Equal(t, stateStoreName, resInfo.GetResourceName())
require.Empty(t, resInfo.GetOwner())
require.Empty(t, resInfo.GetDescription())
require.NotNil(t, help, "Help links should be present")
require.Equal(t, "https://docs.dapr.io/reference/components-reference/supported-state-stores/", help.GetLinks()[0].GetUrl())
require.Equal(t, "Check the list of state stores and the features they support", help.GetLinks()[0].GetDescription())
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/grpc/errors.go
|
GO
|
mit
| 14,909 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"sync"
"testing"
"time"
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/validation/path"
commonv1 "github.com/dapr/dapr/pkg/proto/common/v1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(fuzzstate))
}
type saveReqBinary struct {
Key string `json:"key"`
Value []byte `json:"value"`
}
type saveReqString struct {
Key string `json:"key"`
Value string `json:"value"`
}
type fuzzstate struct {
daprd *procdaprd.Daprd
storeName string
getFuzzKeys []string
saveReqBinaries [][]*commonv1.StateItem
saveReqBinariesHTTP [][]*commonv1.StateItem
saveReqStrings [][]*commonv1.StateItem
}
func (f *fuzzstate) Setup(t *testing.T) []framework.Option {
const numTests = 1000
var takenKeys sync.Map
fuzzFuncs := []any{
func(s *saveReqBinary, c fuzz.Continue) {
var ok bool
for len(s.Key) == 0 || strings.Contains(s.Key, "||") || ok {
s.Key = c.RandString()
_, ok = takenKeys.LoadOrStore(s.Key, true)
}
for len(s.Value) == 0 {
c.Fuzz(&s.Value)
}
},
func(s *saveReqString, c fuzz.Continue) {
var ok bool
for len(s.Key) == 0 || strings.Contains(s.Key, "||") || ok {
s.Key = c.RandString()
_, ok = takenKeys.LoadOrStore(s.Key, true)
}
for len(s.Value) == 0 {
s.Value = c.RandString()
}
},
func(s *string, c fuzz.Continue) {
var ok bool
for len(*s) == 0 || ok {
*s = c.RandString()
_, ok = takenKeys.LoadOrStore(*s, true)
}
},
}
f.storeName = util.RandomString(t, 10)
f.daprd = procdaprd.New(t, procdaprd.WithResourceFiles(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: '%s'
spec:
type: state.in-memory
version: v1
`, strings.ReplaceAll(f.storeName, "'", "''"))))
f.getFuzzKeys = make([]string, numTests)
f.saveReqBinaries = make([][]*commonv1.StateItem, numTests)
f.saveReqBinariesHTTP = make([][]*commonv1.StateItem, numTests)
f.saveReqStrings = make([][]*commonv1.StateItem, numTests)
fz := fuzz.New().Funcs(fuzzFuncs...)
for i := 0; i < numTests; i++ {
fz.Fuzz(&f.getFuzzKeys[i])
if strings.Contains(f.getFuzzKeys[i], "||") || len(path.IsValidPathSegmentName(f.getFuzzKeys[i])) > 0 {
f.getFuzzKeys[i] = ""
i--
}
}
for i := 0; i < numTests; i++ {
var (
srb []saveReqBinary
srbHTTP []saveReqBinary
srs []saveReqString
)
fz.Fuzz(&srb)
fz.Fuzz(&srbHTTP)
fz.Fuzz(&srs)
for j := range srb {
f.saveReqBinaries[i] = append(f.saveReqBinaries[i], &commonv1.StateItem{
Key: srb[j].Key,
Value: srb[j].Value,
})
}
for j := range srbHTTP {
f.saveReqBinariesHTTP[i] = append(f.saveReqBinariesHTTP[i], &commonv1.StateItem{
Key: srbHTTP[j].Key,
Value: srbHTTP[j].Value,
})
}
for j := range srs {
f.saveReqStrings[i] = append(f.saveReqStrings[i], &commonv1.StateItem{
Key: srs[j].Key,
Value: []byte(srs[j].Value),
})
}
}
return []framework.Option{
framework.WithProcesses(f.daprd),
}
}
func (f *fuzzstate) Run(t *testing.T, ctx context.Context) {
f.daprd.WaitUntilRunning(t, ctx)
assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.Len(c, util.GetMetaComponents(c, ctx, util.HTTPClient(t), f.daprd.HTTPPort()), 1)
}, time.Second*20, time.Millisecond*10)
client := f.daprd.GRPCClient(t, ctx)
t.Run("get", func(t *testing.T) {
pt := util.NewParallel(t)
for i := range f.getFuzzKeys {
i := i
pt.Add(func(t *assert.CollectT) {
resp, err := client.GetState(ctx, &rtv1.GetStateRequest{
StoreName: f.storeName,
Key: f.getFuzzKeys[i],
})
require.NoError(t, err)
assert.Empty(t, resp.GetData(), "key: %s", f.getFuzzKeys[i])
})
}
})
httpClient := util.HTTPClient(t)
pt := util.NewParallel(t)
for i := 0; i < len(f.getFuzzKeys); i++ {
i := i
pt.Add(func(t *assert.CollectT) {
for _, req := range [][]*commonv1.StateItem{f.saveReqBinaries[i], f.saveReqStrings[i]} {
_, err := client.SaveState(ctx, &rtv1.SaveStateRequest{
StoreName: f.storeName,
States: req,
})
require.NoError(t, err)
}
postURL := fmt.Sprintf("http://localhost:%d/v1.0/state/%s", f.daprd.HTTPPort(), url.QueryEscape(f.storeName))
b := new(bytes.Buffer)
require.NoError(t, json.NewEncoder(b).Encode(f.saveReqBinariesHTTP[i]))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, b)
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equalf(t, http.StatusNoContent, resp.StatusCode, "key: %s", url.QueryEscape(f.storeName))
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Empty(t, string(respBody))
for _, s := range append(f.saveReqStrings[i], f.saveReqBinaries[i]...) {
resp, err := client.GetState(ctx, &rtv1.GetStateRequest{
StoreName: f.storeName,
Key: s.GetKey(),
})
require.NoError(t, err)
assert.Equalf(t, s.GetValue(), resp.GetData(), "orig=%s got=%s", s.GetValue(), resp.GetData())
}
for _, s := range f.saveReqBinariesHTTP[i] {
resp, err := client.GetState(ctx, &rtv1.GetStateRequest{
StoreName: f.storeName,
Key: s.GetKey(),
})
require.NoError(t, err)
// TODO: Even though we are getting gRPC, the binary data was stored
// with HTTP, so it was base64 encoded.
val := `"` + base64.StdEncoding.EncodeToString(s.GetValue()) + `"`
assert.Equalf(t, val, string(resp.GetData()), "orig=%s got=%s", val, resp.GetData())
}
})
// TODO: Delete, eTag & Bulk APIs
}
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/grpc/fuzz.go
|
GO
|
mit
| 6,589 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
commonv1 "github.com/dapr/dapr/pkg/proto/common/v1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(ttl))
}
type ttl struct {
daprd *procdaprd.Daprd
}
func (l *ttl) Setup(t *testing.T) []framework.Option {
l.daprd = procdaprd.New(t, procdaprd.WithInMemoryActorStateStore("mystore"))
return []framework.Option{
framework.WithProcesses(l.daprd),
}
}
func (l *ttl) Run(t *testing.T, ctx context.Context) {
l.daprd.WaitUntilRunning(t, ctx)
client := l.daprd.GRPCClient(t, ctx)
now := time.Now()
_, err := client.SaveState(ctx, &rtv1.SaveStateRequest{
StoreName: "mystore",
States: []*commonv1.StateItem{
{Key: "key1", Value: []byte("value1"), Metadata: map[string]string{"ttlInSeconds": "3"}},
},
})
require.NoError(t, err)
t.Run("ensure key returns ttlExpireTime", func(t *testing.T) {
resp, err := client.GetState(ctx, &rtv1.GetStateRequest{
StoreName: "mystore", Key: "key1",
})
require.NoError(t, err)
assert.Equal(t, "value1", string(resp.GetData()))
ttlExpireTime, err := time.Parse(time.RFC3339, resp.GetMetadata()["ttlExpireTime"])
require.NoError(t, err)
assert.InDelta(t, now.Add(3*time.Second).Unix(), ttlExpireTime.Unix(), 1)
})
t.Run("ensure key is deleted after ttl", func(t *testing.T) {
assert.EventuallyWithT(t, func(c *assert.CollectT) {
resp, err := client.GetState(ctx, &rtv1.GetStateRequest{
StoreName: "mystore", Key: "key1",
})
require.NoError(c, err)
assert.Empty(c, resp.GetData())
}, 5*time.Second, 10*time.Millisecond)
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/grpc/ttl.go
|
GO
|
mit
| 2,426 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(basic))
}
type basic struct {
daprd *procdaprd.Daprd
}
func (b *basic) Setup(t *testing.T) []framework.Option {
b.daprd = procdaprd.New(t, procdaprd.WithInMemoryActorStateStore("mystore"))
return []framework.Option{
framework.WithProcesses(b.daprd),
}
}
func (b *basic) Run(t *testing.T, ctx context.Context) {
b.daprd.WaitUntilRunning(t, ctx)
postURL := fmt.Sprintf("http://localhost:%d/v1.0/state/mystore", b.daprd.HTTPPort())
httpClient := util.HTTPClient(t)
t.Run("bad json", func(t *testing.T) {
for _, body := range []string{
"",
"{}",
`foobar`,
"[{}]",
`[{"key": "ke||y1", "value": "value1"}]`,
`[{"key": "key1", "value": "value1"},]`,
`[{"key": "key1", "value": "value1"},{"key": "key2", "value": "value1"},]`,
`[{"key": "key1", "value": "value1", "etag": 123}]`,
`[{"ey": "key0", "value": "value1"}]`,
} {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, strings.NewReader(body))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Contains(t, string(body), "ERR_MALFORMED_REQUEST")
}
})
t.Run("good json", func(t *testing.T) {
for _, body := range []string{
"[]",
`[{"key": "key1", "vae": "value1"}]`,
`[{"key": "key1", "value": "value1"}]`,
`[{"key": "key1", "value": "value1"},{"key": "key2", "value": "value1"}]`,
`[{"key": "key1", "value": "value1"},{"key": "key2", "value": "value1"}, {"key": "key1", "value": "value1"},{"key": "key2", "value": "value1"}]`,
} {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, strings.NewReader(body))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Empty(t, string(body))
}
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/http/basic.go
|
GO
|
mit
| 3,071 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"fmt"
"io"
"net/http"
"net/url"
"regexp"
"strings"
"testing"
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/validation/path"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(componentName))
}
type componentName struct {
daprd *procdaprd.Daprd
storeNames []string
}
func (c *componentName) Setup(t *testing.T) []framework.Option {
const numTests = 1000
takenNames := make(map[string]bool)
reg, err := regexp.Compile("^([a-zA-Z].*)$")
require.NoError(t, err)
fz := fuzz.New().Funcs(func(s *string, c fuzz.Continue) {
for *s == "" ||
takenNames[*s] ||
len(path.IsValidPathSegmentName(*s)) > 0 ||
!reg.MatchString(*s) {
*s = c.RandString()
}
takenNames[*s] = true
})
c.storeNames = make([]string, numTests)
files := make([]string, numTests)
for i := 0; i < numTests; i++ {
fz.Fuzz(&c.storeNames[i])
files[i] = fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: '%s'
spec:
type: state.in-memory
version: v1
`,
// Escape single quotes in the store name.
strings.ReplaceAll(c.storeNames[i], "'", "''"))
}
c.daprd = procdaprd.New(t, procdaprd.WithResourceFiles(files...))
return []framework.Option{
framework.WithProcesses(c.daprd),
}
}
func (c *componentName) Run(t *testing.T, ctx context.Context) {
c.daprd.WaitUntilRunning(t, ctx)
httpClient := util.HTTPClient(t)
pt := util.NewParallel(t)
for _, storeName := range c.storeNames {
storeName := storeName
pt.Add(func(t *assert.CollectT) {
reqURL := fmt.Sprintf("http://localhost:%d/v1.0/state/%s", c.daprd.HTTPPort(), url.QueryEscape(storeName))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, strings.NewReader(`[{"key": "key1", "value": "value1"}]`))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode, reqURL)
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Empty(t, string(respBody))
getURL := fmt.Sprintf("http://localhost:%d/v1.0/state/%s/key1", c.daprd.HTTPPort(), url.QueryEscape(storeName))
req, err = http.NewRequestWithContext(ctx, http.MethodGet, getURL, nil)
require.NoError(t, err)
resp, err = httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
respBody, err = io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Equal(t, `"value1"`, string(respBody))
})
}
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/http/compname.go
|
GO
|
mit
| 3,438 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(encryption))
}
type encryption struct {
daprd *daprd.Daprd
}
func SHA256(data []byte) []byte {
h := sha256.New()
h.Write(data)
return h.Sum(nil)
}
func generateAesRandom(keyword string) (key []byte) {
data := []byte(keyword)
hashs := SHA256(SHA256(data))
key = hashs[0:16]
return key
}
func (e *encryption) Setup(t *testing.T) []framework.Option {
tmp := t.TempDir()
secretsFile := filepath.Join(tmp, "secrets.json")
scr := generateAesRandom(strings.Repeat("a", 128))
key := hex.EncodeToString(scr)
secretsJSON := fmt.Sprintf(`{ "key": "%s"}`, key)
secretStore := fmt.Sprintf(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: secretstore
spec:
type: secretstores.local.file
version: v1
metadata:
- name: secretsFile
value: '%s'
`, secretsFile)
stateStore := `apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore
spec:
type: state.in-memory
version: v1
metadata:
- name: primaryEncryptionKey
secretKeyRef:
name: key
auth:
secretStore: secretstore
`
require.NoError(t, os.WriteFile(secretsFile, []byte(secretsJSON), 0o600))
e.daprd = daprd.New(t, daprd.WithResourceFiles(secretStore, stateStore))
return []framework.Option{
framework.WithProcesses(e.daprd),
}
}
func (e *encryption) Run(t *testing.T, ctx context.Context) {
e.daprd.WaitUntilRunning(t, ctx)
httpClient := util.HTTPClient(t)
postURL := fmt.Sprintf("http://localhost:%d/v1.0/state/mystore", e.daprd.HTTPPort())
getURL := fmt.Sprintf("http://localhost:%d/v1.0/state/mystore/key1", e.daprd.HTTPPort())
t.Run("valid encrypted save", func(t *testing.T) {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, strings.NewReader(`[{"key": "key1", "value": "value1"}]`))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Empty(t, string(body))
})
t.Run("valid encrypted get", func(t *testing.T) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, getURL, nil)
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
assert.Equal(t, "value1", string(body))
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/http/encryption.go
|
GO
|
mit
| 3,484 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"runtime"
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/dapr/components-contrib/state"
apierrors "github.com/dapr/dapr/pkg/api/errors"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/statestore"
"github.com/dapr/dapr/tests/integration/framework/process/statestore/inmemory"
"github.com/dapr/dapr/tests/integration/framework/socket"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(errors))
}
type errors struct {
daprd *procdaprd.Daprd
queryErr func(*testing.T) error
}
const (
ErrInfoType = "type.googleapis.com/google.rpc.ErrorInfo"
ResourceInfoType = "type.googleapis.com/google.rpc.ResourceInfo"
BadRequestType = "type.googleapis.com/google.rpc.BadRequest"
HelpType = "type.googleapis.com/google.rpc.Help"
)
func (e *errors) Setup(t *testing.T) []framework.Option {
if runtime.GOOS == "windows" {
t.Skip("skipping unix socket based test on windows")
}
socket := socket.New(t)
e.queryErr = func(t *testing.T) error {
require.FailNow(t, "query should not be called")
return nil
}
storeWithNoTransactional := statestore.New(t,
statestore.WithSocket(socket),
statestore.WithStateStore(inmemory.New(t,
inmemory.WithFeatures(),
)),
)
storeWithQuerier := statestore.New(t,
statestore.WithSocket(socket),
statestore.WithStateStore(inmemory.NewQuerier(t,
inmemory.WithQueryFn(func(context.Context, *state.QueryRequest) (*state.QueryResponse, error) {
return nil, e.queryErr(t)
}),
)),
)
storeWithMultiMaxSize := statestore.New(t,
statestore.WithSocket(socket),
statestore.WithStateStore(inmemory.NewTransactionalMultiMaxSize(t,
inmemory.WithTransactionalStoreMultiMaxSizeFn(func() int {
return 1
}),
)),
)
e.daprd = procdaprd.New(t, procdaprd.WithResourceFiles(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore
spec:
type: state.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore-non-transactional
spec:
type: state.%s
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore-pluggable-querier
spec:
type: state.%s
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mystore-pluggable-multimaxsize
spec:
type: state.%s
version: v1
`, storeWithNoTransactional.SocketName(), storeWithQuerier.SocketName(), storeWithMultiMaxSize.SocketName())),
procdaprd.WithSocket(t, socket),
)
return []framework.Option{
framework.WithProcesses(storeWithNoTransactional, storeWithQuerier, storeWithMultiMaxSize, e.daprd),
}
}
func (e *errors) Run(t *testing.T, ctx context.Context) {
e.daprd.WaitUntilRunning(t, ctx)
httpClient := util.HTTPClient(t)
// Covers errutils.StateStoreNotFound()
t.Run("state store doesn't exist", func(t *testing.T) {
storeName := "mystore-doesnt-exist"
endpoint := fmt.Sprintf("http://localhost:%d/v1.0/state/%s", e.daprd.HTTPPort(), storeName)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, strings.NewReader(""))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
var data map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &data)
require.NoError(t, err)
// Confirm that the 'errorCode' field exists and contains the correct error code
errCode, exists := data["errorCode"]
require.True(t, exists)
require.Equal(t, "ERR_STATE_STORE_NOT_FOUND", errCode)
// Confirm that the 'message' field exists and contains the correct error message
errMsg, exists := data["message"]
require.True(t, exists)
require.Equal(t, fmt.Sprintf("state store %s is not found", storeName), errMsg)
// Confirm that the 'details' field exists and has one element
details, exists := data["details"]
require.True(t, exists)
detailsArray, ok := details.([]interface{})
require.True(t, ok)
require.Len(t, detailsArray, 1)
// Confirm that the first element of the 'details' array has the correct ErrorInfo details
detailsObject, ok := detailsArray[0].(map[string]interface{})
require.True(t, ok)
require.Equal(t, "dapr.io", detailsObject["domain"])
require.Equal(t, "DAPR_STATE_NOT_FOUND", detailsObject["reason"])
require.Equal(t, ErrInfoType, detailsObject["@type"])
})
// Covers errutils.StateStoreInvalidKeyName()
t.Run("invalid key name", func(t *testing.T) {
storeName := "mystore"
endpoint := fmt.Sprintf("http://localhost:%d/v1.0/state/%s", e.daprd.HTTPPort(), storeName)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, strings.NewReader(`[{"key": "ke||y1", "value": "value1"}]`))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
var data map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &data)
require.NoError(t, err)
// Confirm that the 'errorCode' field exists and contains the correct error code
errCode, exists := data["errorCode"]
require.True(t, exists)
require.Equal(t, "ERR_MALFORMED_REQUEST", errCode)
// Confirm that the 'message' field exists and contains the correct error message
errMsg, exists := data["message"]
require.True(t, exists)
require.Contains(t, errMsg, fmt.Sprintf("input key/keyPrefix '%s' can't contain '%s'", "ke||y1", "||"))
// Confirm that the 'details' field exists and has three elements
details, exists := data["details"]
require.True(t, exists)
detailsArray, ok := details.([]interface{})
require.True(t, ok)
require.Len(t, detailsArray, 3)
var errInfo map[string]interface{}
var resInfo map[string]interface{}
var badRequest map[string]interface{}
for _, detail := range detailsArray {
d, innerOK := detail.(map[string]interface{})
require.True(t, innerOK)
switch d["@type"] {
case ErrInfoType:
errInfo = d
case ResourceInfoType:
resInfo = d
case BadRequestType:
badRequest = d
default:
require.FailNow(t, "unexpected status detail")
}
}
// Confirm that the ErrorInfo details are correct
require.Equal(t, "dapr.io", errInfo["domain"])
require.Equal(t, "DAPR_STATE_ILLEGAL_KEY", errInfo["reason"])
// Confirm that the ResourceInfo details are correct
require.Equal(t, "state", resInfo["resource_type"])
require.Equal(t, storeName, resInfo["resource_name"])
// Confirm that the BadRequest details are correct
fieldViolationsArray, ok := badRequest["field_violations"].([]interface{})
require.True(t, ok)
fieldViolations, ok := fieldViolationsArray[0].(map[string]interface{})
require.True(t, ok)
require.Len(t, fieldViolationsArray, 1)
require.Equal(t, "ke||y1", fieldViolations["field"])
require.Contains(t, fmt.Sprintf("input key/keyPrefix '%s' can't contain '%s'", "ke||y1", "||"), fieldViolations["field"])
})
// Covers errutils.StateStoreNotConfigured()
t.Run("state store not configured", func(t *testing.T) {
// Start a new daprd without state store
daprdNoStateStore := procdaprd.New(t, procdaprd.WithAppID("daprd_no_state_store"))
daprdNoStateStore.Run(t, ctx)
daprdNoStateStore.WaitUntilRunning(t, ctx)
defer daprdNoStateStore.Cleanup(t)
storeName := "mystore"
endpoint := fmt.Sprintf("http://localhost:%d/v1.0/state/%s", daprdNoStateStore.HTTPPort(), storeName)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, strings.NewReader(""))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
var data map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &data)
require.NoError(t, err)
// Confirm that the 'errorCode' field exists and contains the correct error code
errCode, exists := data["errorCode"]
require.True(t, exists)
require.Equal(t, "ERR_STATE_STORE_NOT_CONFIGURED", errCode)
// Confirm that the 'message' field exists and contains the correct error message
errMsg, exists := data["message"]
require.True(t, exists)
require.Equal(t, fmt.Sprintf("state store %s is not configured", storeName), errMsg)
// Confirm that the 'details' field exists and has one element
details, exists := data["details"]
require.True(t, exists)
detailsArray, ok := details.([]interface{})
require.True(t, ok)
require.Len(t, detailsArray, 1)
// Confirm that the first element of the 'details' array has the correct ErrorInfo details
detailsObject, ok := detailsArray[0].(map[string]interface{})
require.True(t, ok)
require.Equal(t, "dapr.io", detailsObject["domain"])
require.Equal(t, "DAPR_STATE_NOT_CONFIGURED", detailsObject["reason"])
require.Equal(t, ErrInfoType, detailsObject["@type"])
})
t.Run("state store doesn't support query api", func(t *testing.T) {
storeName := "mystore"
endpoint := fmt.Sprintf("http://localhost:%d/v1.0-alpha1/state/%s/query", e.daprd.HTTPPort(), storeName)
payload := `{"filter":{"EQ":{"state":"CA"}},"sort":[{"key":"person.id","order":"DESC"}]}`
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, strings.NewReader(payload))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
var data map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &data)
require.NoError(t, err)
// Confirm that the 'errorCode' field exists and contains the correct error code
errCode, exists := data["errorCode"]
require.True(t, exists)
require.Equal(t, "ERR_STATE_STORE_NOT_SUPPORTED", errCode)
// Confirm that the 'message' field exists and contains the correct error message
errMsg, exists := data["message"]
require.True(t, exists)
require.Contains(t, errMsg, "state store does not support querying")
// Confirm that the 'details' field exists and has two elements
details, exists := data["details"]
require.True(t, exists)
detailsArray, ok := details.([]interface{})
require.True(t, ok)
require.Len(t, detailsArray, 2)
// Parse the json into go objects
var errInfo map[string]interface{}
var resInfo map[string]interface{}
for _, detail := range detailsArray {
d, ok := detail.(map[string]interface{})
require.True(t, ok)
switch d["@type"] {
case ErrInfoType:
errInfo = d
case ResourceInfoType:
resInfo = d
default:
require.FailNow(t, "unexpected status detail")
}
}
// Confirm that the ErrorInfo details are correct
require.NotEmptyf(t, errInfo, "ErrorInfo not found in %+v", detailsArray)
require.Equal(t, "dapr.io", errInfo["domain"])
require.Equal(t, "DAPR_STATE_QUERYING_NOT_SUPPORTED", errInfo["reason"])
// Confirm that the ResourceInfo details are correct
require.NotEmptyf(t, resInfo, "ResourceInfo not found in %+v", detailsArray)
require.Equal(t, "state", resInfo["resource_type"])
require.Equal(t, storeName, resInfo["resource_name"])
})
t.Run("state store query failed", func(t *testing.T) {
storeName := "mystore-pluggable-querier"
e.queryErr = func(*testing.T) error {
return apierrors.StateStore(storeName).QueryFailed("this is a custom error string")
}
endpoint := fmt.Sprintf("http://localhost:%d/v1.0-alpha1/state/%s/query", e.daprd.HTTPPort(), storeName)
payload := `{"filter":{"EQ":{"state":"CA"}},"sort":[{"key":"person.id","order":"DESC"}]}`
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, strings.NewReader(payload))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
var data map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &data)
require.NoError(t, err)
// Confirm that the 'errorCode' field exists and contains the correct error code
errCode, exists := data["errorCode"]
require.True(t, exists)
require.Equal(t, "ERR_STATE_QUERY", errCode)
// Confirm that the 'message' field exists and contains the correct error message
errMsg, exists := data["message"]
require.True(t, exists)
require.Contains(t, errMsg, fmt.Sprintf("state store %s query failed: %s", storeName, "this is a custom error string"))
// Confirm that the 'details' field exists and has two elements
details, exists := data["details"]
require.True(t, exists)
detailsArray, ok := details.([]interface{})
require.True(t, ok)
require.Len(t, detailsArray, 2)
// Parse the json into go objects
var errInfo map[string]interface{}
var resInfo map[string]interface{}
for _, detail := range detailsArray {
d, ok := detail.(map[string]interface{})
require.True(t, ok)
switch d["@type"] {
case ErrInfoType:
errInfo = d
case ResourceInfoType:
resInfo = d
default:
require.FailNow(t, "unexpected status detail")
}
}
// Confirm that the ErrorInfo details are correct
require.NotEmptyf(t, errInfo, "ErrorInfo not found in %+v", detailsArray)
require.Equal(t, "dapr.io", errInfo["domain"])
require.Equal(t, "DAPR_STATE_QUERY_FAILED", errInfo["reason"])
// Confirm that the ResourceInfo details are correct
require.NotEmptyf(t, resInfo, "ResourceInfo not found in %+v", detailsArray)
require.Equal(t, "state", resInfo["resource_type"])
require.Equal(t, storeName, resInfo["resource_name"])
})
t.Run("state store too many transactional operations", func(t *testing.T) {
storeName := "mystore-pluggable-multimaxsize"
endpoint := fmt.Sprintf("http://localhost:%d/v1.0/state/%s/transaction", e.daprd.HTTPPort(), storeName)
payload := `{"operations": [{"operation": "upsert","request": {"key": "key1","value": "val1"}},{"operation": "delete","request": {"key": "key2"}}],"metadata": {"partitionKey": "key2"}}`
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, strings.NewReader(payload))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
var data map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &data)
require.NoError(t, err)
// Confirm that the 'errorCode' field exists and contains the correct error code
errCode, exists := data["errorCode"]
require.True(t, exists)
require.Equal(t, "ERR_STATE_STORE_TOO_MANY_TRANSACTIONS", errCode)
// Confirm that the 'message' field exists and contains the correct error message
errMsg, exists := data["message"]
require.True(t, exists)
require.Contains(t, errMsg, fmt.Sprintf("the transaction contains %d operations, which is more than what the state store supports: %d", 2, 1))
// Confirm that the 'details' field exists and has two elements
details, exists := data["details"]
require.True(t, exists)
detailsArray, ok := details.([]interface{})
require.True(t, ok)
require.Len(t, detailsArray, 2)
// Parse the json into go objects
var errInfo map[string]interface{}
var resInfo map[string]interface{}
for _, detail := range detailsArray {
d, ok := detail.(map[string]interface{})
require.True(t, ok)
switch d["@type"] {
case ErrInfoType:
errInfo = d
case ResourceInfoType:
resInfo = d
default:
require.FailNow(t, "unexpected status detail")
}
}
// Confirm that the ErrorInfo details are correct
require.NotEmptyf(t, errInfo, "ErrorInfo not found in %+v", detailsArray)
require.Equal(t, "dapr.io", errInfo["domain"])
require.Equal(t, "DAPR_STATE_TOO_MANY_TRANSACTIONS", errInfo["reason"])
require.Equal(t, map[string]interface{}{
"currentOpsTransaction": "2", "maxOpsPerTransaction": "1",
}, errInfo["metadata"])
// Confirm that the ResourceInfo details are correct
require.NotEmptyf(t, resInfo, "ResourceInfo not found in %+v", detailsArray)
require.Equal(t, "state", resInfo["resource_type"])
require.Equal(t, storeName, resInfo["resource_name"])
})
t.Run("state transactions not supported", func(t *testing.T) {
storeName := "mystore-non-transactional"
endpoint := fmt.Sprintf("http://localhost:%d/v1.0/state/%s/transaction", e.daprd.HTTPPort(), storeName)
payload := `{"operations": [{"operation": "upsert","request": {"key": "key1","value": "val1"}},{"operation": "delete","request": {"key": "key2"}}],"metadata": {"partitionKey": "key2"}}`
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, strings.NewReader(payload))
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
var data map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &data)
require.NoError(t, err)
// Confirm that the 'errorCode' field exists and contains the correct error code
errCode, exists := data["errorCode"]
require.True(t, exists)
require.Equal(t, "ERR_STATE_STORE_NOT_SUPPORTED", errCode)
// Confirm that the 'message' field exists and contains the correct error message
errMsg, exists := data["message"]
require.True(t, exists)
require.Equal(t, fmt.Sprintf("state store %s doesn't support transactions", "mystore-non-transactional"), errMsg)
// Confirm that the 'details' field exists and has two elements
details, exists := data["details"]
require.True(t, exists)
detailsArray, ok := details.([]interface{})
require.True(t, ok)
require.Len(t, detailsArray, 3)
// Parse the json into go objects
var errInfo map[string]interface{}
var resInfo map[string]interface{}
var help map[string]interface{}
for _, detail := range detailsArray {
d, innerOK := detail.(map[string]interface{})
require.True(t, innerOK)
switch d["@type"] {
case ErrInfoType:
errInfo = d
case ResourceInfoType:
resInfo = d
case HelpType:
help = d
default:
require.FailNow(t, "unexpected status detail")
}
}
// Confirm that the ErrorInfo details are correct
require.NotEmptyf(t, errInfo, "ErrorInfo not found in %+v", detailsArray)
require.Equal(t, "dapr.io", errInfo["domain"])
require.Equal(t, "DAPR_STATE_TRANSACTIONS_NOT_SUPPORTED", errInfo["reason"])
// Confirm that the ResourceInfo details are correct
require.NotEmptyf(t, resInfo, "ResourceInfo not found in %+v", detailsArray)
require.Equal(t, "state", resInfo["resource_type"])
require.Equal(t, storeName, resInfo["resource_name"])
// Confirm that the Help details are correct
helpLinks, ok := help["links"].([]interface{})
require.True(t, ok, "Failed to assert Help links as an array")
require.NotEmpty(t, helpLinks, "Help links array is empty")
link, ok := helpLinks[0].(map[string]interface{})
require.True(t, ok, "Failed to assert link as a map")
linkURL, ok := link["url"].(string)
require.True(t, ok, "Failed to assert link URL as a string")
require.Equal(t, "https://docs.dapr.io/reference/components-reference/supported-state-stores/", linkURL)
linkDescription, ok := link["description"].(string)
require.True(t, ok, "Failed to assert link description as a string")
require.Equal(t, "Check the list of state stores and the features they support", linkDescription)
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/http/errors.go
|
GO
|
mit
| 21,253 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"sync"
"testing"
"time"
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/validation/path"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(fuzzstate))
}
type saveReqBinary struct {
Key string `json:"key"`
Value []byte `json:"value"`
}
type saveReqString struct {
Key string `json:"key"`
Value string `json:"value"`
}
type saveReqAny struct {
Key string `json:"key"`
Value any `json:"value"`
}
type fuzzstate struct {
daprd *procdaprd.Daprd
storeName string
getFuzzKeys []string
saveReqBinaries [][]saveReqBinary
saveReqStrings [][]saveReqString
saveReqAnys [][]saveReqAny
}
func (f *fuzzstate) Setup(t *testing.T) []framework.Option {
const numTests = 1000
var takenKeys sync.Map
fuzzFuncs := []any{
func(s *saveReqBinary, c fuzz.Continue) {
var ok bool
for len(s.Key) == 0 || strings.Contains(s.Key, "||") || s.Key == "." || ok {
s.Key = c.RandString()
_, ok = takenKeys.LoadOrStore(s.Key, true)
}
for len(s.Value) == 0 {
c.Fuzz(&s.Value)
}
},
func(s *saveReqString, c fuzz.Continue) {
var ok bool
for len(s.Key) == 0 || strings.Contains(s.Key, "||") || s.Key == "." || ok {
s.Key = c.RandString()
_, ok = takenKeys.LoadOrStore(s.Key, true)
}
for len(s.Value) == 0 {
s.Value = c.RandString()
}
},
func(s *saveReqAny, c fuzz.Continue) {
var ok bool
for len(s.Key) == 0 || strings.Contains(s.Key, "||") || s.Key == "." || ok {
s.Key = c.RandString()
_, ok = takenKeys.LoadOrStore(s.Key, true)
}
},
func(s *string, c fuzz.Continue) {
var ok bool
for len(*s) == 0 || ok {
*s = c.RandString()
_, ok = takenKeys.LoadOrStore(*s, true)
}
},
}
f.storeName = util.RandomString(t, 10)
f.daprd = procdaprd.New(t, procdaprd.WithResourceFiles(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: '%s'
spec:
type: state.in-memory
version: v1
`, strings.ReplaceAll(f.storeName, "'", "''"))))
f.getFuzzKeys = make([]string, numTests)
f.saveReqBinaries = make([][]saveReqBinary, numTests)
f.saveReqStrings = make([][]saveReqString, numTests)
f.saveReqAnys = make([][]saveReqAny, numTests)
fz := fuzz.New().Funcs(fuzzFuncs...)
for i := 0; i < numTests; i++ {
fz.Fuzz(&f.getFuzzKeys[i])
// Prevent invalid names
if strings.Contains(f.getFuzzKeys[i], "||") || f.getFuzzKeys[i] == "." || len(path.IsValidPathSegmentName(f.getFuzzKeys[i])) > 0 {
f.getFuzzKeys[i] = ""
i--
}
}
for i := 0; i < numTests; i++ {
fz.Fuzz(&f.saveReqBinaries[i])
fz.Fuzz(&f.saveReqStrings[i])
fz.Fuzz(&f.saveReqAnys[i])
}
return []framework.Option{
framework.WithProcesses(f.daprd),
}
}
func (f *fuzzstate) Run(t *testing.T, ctx context.Context) {
f.daprd.WaitUntilRunning(t, ctx)
httpClient := util.HTTPClient(t)
assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.Len(c, util.GetMetaComponents(c, ctx, httpClient, f.daprd.HTTPPort()), 1)
}, time.Second*20, time.Millisecond*10)
t.Run("get", func(t *testing.T) {
pt := util.NewParallel(t)
for i := range f.getFuzzKeys {
i := i
pt.Add(func(t *assert.CollectT) {
getURL := fmt.Sprintf("http://localhost:%d/v1.0/state/%s/%s", f.daprd.HTTPPort(), url.QueryEscape(f.storeName), url.QueryEscape(f.getFuzzKeys[i]))
// t.Log("URL", getURL)
// t.Log("State store name", f.storeName, hex.EncodeToString([]byte(f.storeName)), printRunes(f.storeName))
// t.Log("Key", f.getFuzzKeys[i], printRunes(f.getFuzzKeys[i]))
req, err := http.NewRequestWithContext(ctx, http.MethodGet, getURL, nil)
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Empty(t, string(respBody), "key: %s", f.getFuzzKeys[i])
})
}
})
pt := util.NewParallel(t)
for i := 0; i < len(f.getFuzzKeys); i++ {
i := i
pt.Add(func(t *assert.CollectT) {
for _, req := range []any{f.saveReqBinaries[i], f.saveReqStrings[i]} {
postURL := fmt.Sprintf("http://localhost:%d/v1.0/state/%s", f.daprd.HTTPPort(), url.QueryEscape(f.storeName))
b := new(bytes.Buffer)
require.NoError(t, json.NewEncoder(b).Encode(req))
// t.Log("URL", postURL)
// t.Log("State store name", f.storeName, hex.EncodeToString([]byte(f.storeName)), printRunes(f.storeName))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, b)
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equalf(t, http.StatusNoContent, resp.StatusCode, "key: %s", url.QueryEscape(f.storeName))
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Empty(t, string(respBody))
}
for _, s := range f.saveReqBinaries[i] {
getURL := fmt.Sprintf("http://localhost:%d/v1.0/state/%s/%s", f.daprd.HTTPPort(), url.QueryEscape(f.storeName), url.QueryEscape(s.Key))
// t.Log("URL", getURL)
// t.Log("State store name", f.storeName, hex.EncodeToString([]byte(f.storeName)), printRunes(f.storeName))
// t.Log("Key", s.Key, hex.EncodeToString([]byte(s.Key)), printRunes(s.Key))
req, err := http.NewRequestWithContext(ctx, http.MethodGet, getURL, nil)
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
// TODO: @joshvanl: document the fact that saving binary state will HTTP will be base64
// encoded.
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
val := `"` + base64.StdEncoding.EncodeToString(s.Value) + `"`
assert.Equalf(t, val, string(respBody), "key: %s, %s", s.Key, req.URL.String())
}
for _, s := range f.saveReqStrings[i] {
getURL := fmt.Sprintf("http://localhost:%d/v1.0/state/%s/%s", f.daprd.HTTPPort(), url.QueryEscape(f.storeName), url.QueryEscape(s.Key))
// t.Log("URL", getURL)
// t.Log("State store name", f.storeName, hex.EncodeToString([]byte(f.storeName)), printRunes(f.storeName))
// t.Log("Key", s.Key, hex.EncodeToString([]byte(s.Key)), printRunes(s.Key))
req, err := http.NewRequestWithContext(ctx, http.MethodGet, getURL, nil)
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
// Some state stores (such as in-memory that we are using here) mangle
// the string by HTML escaping it, which changes specifical characters
// such as <, >, &, to \u003c, \u003e, \u0026, etc. This is not the
// case for other state stores.
// https://pkg.go.dev/encoding/json#HTMLEscape
js, err := json.Marshal(s.Value)
require.NoError(t, err)
var orig bytes.Buffer
json.HTMLEscape(&orig, js)
assert.Equalf(t, orig.Bytes(), respBody, "orig=%s got=%s", orig, respBody)
}
})
// TODO: Delete, eTag & Bulk APIs
}
}
/*
func printRunes(str string) []string {
result := make([]string, 0, len(str))
for _, r := range str {
result = append(result, strconv.Itoa(int(r)))
}
return result
}
*/
|
mikeee/dapr
|
tests/integration/suite/daprd/state/http/fuzz.go
|
GO
|
mit
| 8,335 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/dapr/dapr/tests/integration/framework"
procdaprd "github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(ttl))
}
type ttl struct {
daprd *procdaprd.Daprd
}
func (l *ttl) Setup(t *testing.T) []framework.Option {
l.daprd = procdaprd.New(t, procdaprd.WithInMemoryActorStateStore("mystore"))
return []framework.Option{
framework.WithProcesses(l.daprd),
}
}
func (l *ttl) Run(t *testing.T, ctx context.Context) {
l.daprd.WaitUntilRunning(t, ctx)
postURL := fmt.Sprintf("http://localhost:%d/v1.0/state/mystore", l.daprd.HTTPPort())
client := util.HTTPClient(t)
now := time.Now()
t.Run("set key with ttl", func(t *testing.T) {
reqBody := `[{"key": "key1", "value": "value1", "metadata": {"ttlInSeconds": "3"}}]`
req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, strings.NewReader(reqBody))
require.NoError(t, err)
resp, err := client.Do(req)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
})
t.Run("ensure key return ttlExpireTime", func(t *testing.T) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, postURL+"/key1", nil)
require.NoError(t, err)
resp, err := client.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
assert.Equal(t, `"value1"`, string(body))
ttlExpireTimeStr := resp.Header.Get("metadata.ttlExpireTime")
require.NotEmpty(t, ttlExpireTimeStr)
ttlExpireTime, err := time.Parse(time.RFC3339, ttlExpireTimeStr)
require.NoError(t, err)
assert.InDelta(t, now.Add(3*time.Second).Unix(), ttlExpireTime.Unix(), 1)
})
t.Run("ensure key is deleted after ttl", func(t *testing.T) {
assert.EventuallyWithT(t, func(c *assert.CollectT) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, postURL+"/key1", nil)
require.NoError(c, err)
resp, err := client.Do(req)
require.NoError(c, err)
require.NoError(t, resp.Body.Close())
assert.Equal(c, http.StatusNoContent, resp.StatusCode)
}, 5*time.Second, 10*time.Millisecond)
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/state/http/ttl.go
|
GO
|
mit
| 3,043 |
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package state
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/state/grpc"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/state/http"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/state/state.go
|
GO
|
mit
| 721 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package declarative
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/declarative.go
|
GO
|
mit
| 777 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package operator
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/operator.go
|
GO
|
mit
| 790 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Route: "/a",
},
}},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
require.Len(t, meta.GetSubscriptions(), 1)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.JSONEq(t, `{"status": "completed"}`, string(resp.GetData()))
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Empty(t, resp.GetData())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "foo/bar", resp.GetDataContentType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "foo", string(resp.GetData()))
assert.Equal(t, "text/plain", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/basic/grpc.go
|
GO
|
mit
| 5,232 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Route: "/a",
},
}},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/json", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "foo/bar", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "foo", string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/basic/http.go
|
GO
|
mit
| 5,807 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
BulkSubscribe: subapi.BulkSubscribe{
Enabled: true,
MaxMessagesCount: 100,
MaxAwaitDurationMs: 40,
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "nobulk", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/b",
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
resp, err := client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "a",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.AssertBulkEventChanLen(t, 0)
resp, err = client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "b",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.AssertBulkEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/bulk/grpc.go
|
GO
|
mit
| 5,295 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithBulkRoutes("/a", "/b"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
BulkSubscribe: subapi.BulkSubscribe{
Enabled: true,
MaxMessagesCount: 100,
MaxAwaitDurationMs: 40,
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "nobulk", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/b",
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/bulk/http.go
|
GO
|
mit
| 4,983 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
"errors"
"testing"
"time"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/app"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
app *app.App
inCh chan *rtv1.TopicEventRequest
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.inCh = make(chan *rtv1.TopicEventRequest)
g.app = app.New(t,
app.WithOnTopicEventFn(func(ctx context.Context, in *rtv1.TopicEventRequest) (*rtv1.TopicEventResponse, error) {
if in.GetTopic() == "a" {
return nil, errors.New("my error")
}
g.inCh <- in
return new(rtv1.TopicEventResponse), nil
}),
)
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
DeadLetterTopic: "mydead",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "anothersub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "mydead",
Route: "/b",
DeadLetterTopic: "mydead",
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.app.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.app, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
ctx, cancel := context.WithTimeout(ctx, time.Second)
t.Cleanup(cancel)
select {
case <-ctx.Done():
assert.Fail(t, "timeout waiting for event")
case in := <-g.inCh:
assert.Equal(t, "mydead", in.GetTopic())
assert.Equal(t, "/b", in.GetPath())
}
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/deadletter/grpc.go
|
GO
|
mit
| 4,720 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
nethttp "net/http"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/b"),
subscriber.WithHandlerFunc("/a", func(w nethttp.ResponseWriter, r *nethttp.Request) {
w.WriteHeader(nethttp.StatusServiceUnavailable)
}),
)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
DeadLetterTopic: "mydead",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "anothersub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "mydead",
Route: "/b",
DeadLetterTopic: "mydead",
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/b", resp.Route)
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, `{"status": "completed"}`, string(resp.Data()))
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/deadletter/http.go
|
GO
|
mit
| 4,295 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package informer
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Route: "/a",
},
}},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
require.Len(t, meta.GetSubscriptions(), 1)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.JSONEq(t, `{"status": "completed"}`, string(resp.GetData()))
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/informer/grpc.go
|
GO
|
mit
| 4,243 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package informer
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Route: "/a",
},
}},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/informer/http.go
|
GO
|
mit
| 4,019 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.sub = subscriber.New(t)
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "anotherpub",
Topic: "a",
Route: "/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "c",
Route: "/c",
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
g.sub.ExpectPublishError(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "anotherpub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "b", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "c", Data: []byte(`{"status": "completed"}`),
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/missing/grpc.go
|
GO
|
mit
| 4,429 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a", "/b", "/c"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "anotherpub",
Topic: "a",
Route: "/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "c",
Route: "/c",
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
meta, err := h.daprd.GRPCClient(t, ctx).GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
h.sub.ExpectPublishError(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "anotherpub",
Topic: "a",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishNoReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "c",
Data: `{"status": "completed"}`,
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/missing/http.go
|
GO
|
mit
| 4,515 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/dapr/components-contrib/pubsub"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.sub = subscriber.New(t)
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
Metadata: map[string]string{
"rawPayload": "true",
},
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["datacontenttype"] = "foo/bar"
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/rawpayload/grpc.go
|
GO
|
mit
| 6,501 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/dapr/components-contrib/pubsub"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
Metadata: map[string]string{
"rawPayload": "true",
},
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "text/plain", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "foo/bar"
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/rawpayload/http.go
|
GO
|
mit
| 7,492 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package route
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.sub = subscriber.New(t)
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a/b/c/d",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/d/c/b/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub5", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/a/b/c/d",
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetSubscriptions(), 2)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "a",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Contains(t, []string{"/a", "/a/b/c/d"}, resp.GetPath())
assert.Empty(t, resp.GetData())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "b",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Contains(t, []string{"/a", "/a/b/c/d", "/d/c/b/a"}, resp.GetPath())
assert.Empty(t, resp.GetData())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/route/grpc.go
|
GO
|
mit
| 5,078 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package route
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a", "/d/c/b/a", "/a/b/c/d"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a/b/c/d",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Route: "/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/d/c/b/a",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub5", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Route: "/a/b/c/d",
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
})
resp := h.sub.Receive(t, ctx)
assert.Contains(t, []string{"/a", "/a/b/c/d"}, resp.Route)
assert.Empty(t, resp.Data())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
})
resp = h.sub.Receive(t, ctx)
assert.Contains(t, []string{"/a", "/a/b/c/d", "/d/c/b/a"}, resp.Route)
assert.Empty(t, resp.Data())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/route/http.go
|
GO
|
mit
| 5,028 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.sub = subscriber.New(t)
appid1 := uuid.New().String()
appid2 := uuid.New().String()
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "sub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "all",
Route: "/all",
},
Scopes: nil,
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "allempty",
Route: "/allempty",
},
Scopes: []string{},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only1",
Route: "/only1",
},
Scopes: []string{appid1},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only2",
Route: "/only2",
},
Scopes: []string{appid2},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub5", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "both",
Route: "/both",
},
Scopes: []string{appid1, appid2},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
daprdOpts := []daprd.Option{
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
}
g.daprd1 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid1))...)
g.daprd2 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid2))...)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd1, g.daprd2),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd1.WaitUntilRunning(t, ctx)
g.daprd2.WaitUntilRunning(t, ctx)
client1 := g.daprd1.GRPCClient(t, ctx)
client2 := g.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(topic string) *rtv1.PublishEventRequest {
return &rtv1.PublishEventRequest{PubsubName: "mypub", Topic: topic, Data: []byte(`{"status": "completed"}`)}
}
reqAll := newReq("all")
reqEmpty := newReq("allempty")
reqOnly1 := newReq("only1")
reqOnly2 := newReq("only2")
reqBoth := newReq("both")
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqEmpty)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqOnly1)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd1, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqBoth)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqEmpty)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd2, reqOnly1)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqBoth)
g.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/scopes/grpc.go
|
GO
|
mit
| 7,328 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/all", "/allempty", "/only1", "/only2", "/both",
))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
appid1 := uuid.New().String()
appid2 := uuid.New().String()
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionList(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "sub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "all",
Route: "/all",
},
Scopes: nil,
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "allempty",
Route: "/allempty",
},
Scopes: []string{},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only1",
Route: "/only1",
},
Scopes: []string{appid1},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only2",
Route: "/only2",
},
Scopes: []string{appid2},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub5", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "both",
Route: "/both",
},
Scopes: []string{appid1, appid2},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
daprdOpts := []daprd.Option{
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
}
h.daprd1 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid1))...)
h.daprd2 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid2))...)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd1, h.daprd2),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd1.WaitUntilRunning(t, ctx)
h.daprd2.WaitUntilRunning(t, ctx)
client1 := h.daprd1.GRPCClient(t, ctx)
client2 := h.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(daprd *daprd.Daprd, topic string) subscriber.PublishRequest {
return subscriber.PublishRequest{
Daprd: daprd,
PubSubName: "mypub",
Topic: topic,
Data: `{"status": "completed"}`,
}
}
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "allempty"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "only1"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd1, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "both"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "allempty"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd2, "only1"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "both"))
h.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/scopes/http.go
|
GO
|
mit
| 7,399 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/basic"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/bulk"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/deadletter"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/informer"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/missing"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/rawpayload"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/route"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/scopes"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v1alpha1/v1alpha1.go
|
GO
|
mit
| 1,453 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
}},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
require.Len(t, meta.GetSubscriptions(), 1)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.JSONEq(t, `{"status": "completed"}`, string(resp.GetData()))
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Empty(t, resp.GetData())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "foo/bar", resp.GetDataContentType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "foo", string(resp.GetData()))
assert.Equal(t, "text/plain", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/basic/grpc.go
|
GO
|
mit
| 5,268 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
}},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/json", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "foo/bar", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "foo", string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/basic/http.go
|
GO
|
mit
| 5,843 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
BulkSubscribe: subapi.BulkSubscribe{
Enabled: true,
MaxMessagesCount: 100,
MaxAwaitDurationMs: 40,
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "nobulk", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Routes: subapi.Routes{
Default: "/b",
},
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
resp, err := client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "a",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.AssertBulkEventChanLen(t, 0)
resp, err = client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "b",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.AssertBulkEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/bulk/grpc.go
|
GO
|
mit
| 5,369 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithBulkRoutes("/a", "/b"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
BulkSubscribe: subapi.BulkSubscribe{
Enabled: true,
MaxMessagesCount: 100,
MaxAwaitDurationMs: 40,
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "nobulk", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Routes: subapi.Routes{
Default: "/b",
},
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/bulk/http.go
|
GO
|
mit
| 5,057 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
"errors"
"testing"
"time"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/app"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
app *app.App
inCh chan *rtv1.TopicEventRequest
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.inCh = make(chan *rtv1.TopicEventRequest)
g.app = app.New(t,
app.WithOnTopicEventFn(func(ctx context.Context, in *rtv1.TopicEventRequest) (*rtv1.TopicEventResponse, error) {
if in.GetTopic() == "a" {
return nil, errors.New("my error")
}
g.inCh <- in
return new(rtv1.TopicEventResponse), nil
}),
)
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
DeadLetterTopic: "mydead",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "anothersub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "mydead",
Routes: subapi.Routes{
Default: "/b",
},
DeadLetterTopic: "mydead",
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.app.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.app, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
ctx, cancel := context.WithTimeout(ctx, time.Second)
t.Cleanup(cancel)
select {
case <-ctx.Done():
assert.Fail(t, "timeout waiting for event")
case in := <-g.inCh:
assert.Equal(t, "mydead", in.GetTopic())
assert.Equal(t, "/b", in.GetPath())
}
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/deadletter/grpc.go
|
GO
|
mit
| 4,764 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
nethttp "net/http"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/b"),
subscriber.WithHandlerFunc("/a", func(w nethttp.ResponseWriter, r *nethttp.Request) {
w.WriteHeader(nethttp.StatusServiceUnavailable)
}),
)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
DeadLetterTopic: "mydead",
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "anothersub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "mydead",
Routes: subapi.Routes{
Default: "/b",
},
DeadLetterTopic: "mydead",
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/b", resp.Route)
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, `{"status": "completed"}`, string(resp.Data()))
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/deadletter/http.go
|
GO
|
mit
| 4,339 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
}},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
require.Len(t, meta.GetSubscriptions(), 1)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypubsub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.JSONEq(t, `{"status": "completed"}`, string(resp.GetData()))
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypubsub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/informer/grpc.go
|
GO
|
mit
| 4,275 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypubsub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypubsub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
}},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypubsub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypubsub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/informer/http.go
|
GO
|
mit
| 4,051 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.sub = subscriber.New(t)
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "anotherpub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "c",
Routes: subapi.Routes{
Default: "/c",
},
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
g.sub.ExpectPublishError(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "anotherpub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "b", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "c", Data: []byte(`{"status": "completed"}`),
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/missing/grpc.go
|
GO
|
mit
| 4,503 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a", "/b", "/c"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "anotherpub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "c",
Routes: subapi.Routes{
Default: "/c",
},
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
meta, err := h.daprd.GRPCClient(t, ctx).GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
h.sub.ExpectPublishError(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "anotherpub",
Topic: "a",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishNoReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "c",
Data: `{"status": "completed"}`,
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/missing/http.go
|
GO
|
mit
| 4,589 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/dapr/components-contrib/pubsub"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.sub = subscriber.New(t)
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
Metadata: map[string]string{
"rawPayload": "true",
},
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["datacontenttype"] = "foo/bar"
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/rawpayload/grpc.go
|
GO
|
mit
| 6,539 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/dapr/components-contrib/pubsub"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a"))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
Metadata: map[string]string{
"rawPayload": "true",
},
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "text/plain", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "foo/bar"
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/rawpayload/http.go
|
GO
|
mit
| 7,530 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package defaultroute
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a/b/c/d",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Routes: subapi.Routes{
Default: "/b",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Routes: subapi.Routes{
Default: "/a/b/c/d",
},
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "a",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Contains(t, []string{"/a", "/a/b/c/d"}, resp.GetPath())
assert.Empty(t, resp.GetData())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "b",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Contains(t, []string{"/b", "/a/b/c/d"}, resp.GetPath())
assert.Empty(t, resp.GetData())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/defaultroute/grpc.go
|
GO
|
mit
| 4,872 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package defaultroute
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/a/b/c/d", "/a", "/b", "/d/c/b/a",
))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a/b/c/d",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "a",
Routes: subapi.Routes{
Default: "/a",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Routes: subapi.Routes{
Default: "/b",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "mysub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "b",
Routes: subapi.Routes{
Default: "/a/b/c/d",
},
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
})
resp := h.sub.Receive(t, ctx)
assert.Contains(t, []string{"/a", "/a/b/c/d"}, resp.Route)
assert.Empty(t, resp.Data())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
})
resp = h.sub.Receive(t, ctx)
assert.Contains(t, []string{"/b", "/a/b/c/d"}, resp.Route)
assert.Empty(t, resp.Data())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/defaultroute/http.go
|
GO
|
mit
| 4,765 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package emptymatch
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "justpath", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "justpath",
Routes: subapi.Routes{
Rules: []subapi.Rule{
{Path: "/justpath", Match: ""},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "defaultandpath", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "defaultandpath",
Routes: subapi.Routes{
Default: "/abc",
Rules: []subapi.Rule{
{Path: "/123", Match: ""},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "multipaths", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "multipaths",
Routes: subapi.Routes{
Rules: []subapi.Rule{
{Path: "/xyz", Match: ""},
{Path: "/456", Match: ""},
{Path: "/789", Match: ""},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "defaultandpaths", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "defaultandpaths",
Routes: subapi.Routes{
Default: "/def",
Rules: []subapi.Rule{
{Path: "/zyz", Match: ""},
{Path: "/aaa", Match: ""},
{Path: "/bbb", Match: ""},
},
},
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "justpath",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/justpath", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "defaultandpath",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "multipaths",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/xyz", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "defaultandpaths",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/zyz", resp.GetPath())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/emptymatch/grpc.go
|
GO
|
mit
| 5,671 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package emptymatch
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/justpath", "/abc", "/123", "/def", "/zyz",
"/aaa", "/bbb", "/xyz", "/456", "/789",
))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "justpath", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "justpath",
Routes: subapi.Routes{
Rules: []subapi.Rule{
{Path: "/justpath", Match: ""},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "defaultandpath", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "defaultandpath",
Routes: subapi.Routes{
Default: "/abc",
Rules: []subapi.Rule{
{Path: "/123", Match: ""},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "multipaths", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "multipaths",
Routes: subapi.Routes{
Rules: []subapi.Rule{
{Path: "/xyz", Match: ""},
{Path: "/456", Match: ""},
{Path: "/789", Match: ""},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "defaultandpaths", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "defaultandpaths",
Routes: subapi.Routes{
Default: "/def",
Rules: []subapi.Rule{
{Path: "/zyz", Match: ""},
{Path: "/aaa", Match: ""},
{Path: "/bbb", Match: ""},
},
},
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "justpath",
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/justpath", resp.Route)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "defaultandpath",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.Route)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "multipaths",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/xyz", resp.Route)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "defaultandpaths",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/zyz", resp.Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/emptymatch/http.go
|
GO
|
mit
| 5,585 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package match
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "type", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "type",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/type", Match: `event.type == "com.dapr.event.sent"`},
{Path: "/foo", Match: ""},
{Path: "/bar", Match: `event.type == "com.dapr.event.recv"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order1",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/type", Match: `event.type == "com.dapr.event.sent"`},
{Path: "/topic", Match: `event.topic == "order1"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order2",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/topic", Match: `event.topic == "order2"`},
{Path: "/type", Match: `event.type == "com.dapr.event.sent"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order3",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/123", Match: `event.topic == "order3"`},
{Path: "/456", Match: `event.topic == "order3"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order4",
Routes: subapi.Routes{
Rules: []subapi.Rule{
{Path: "/123", Match: `event.topic == "order5"`},
{Path: "/456", Match: `event.topic == "order6"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order7", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order7",
Routes: subapi.Routes{
Default: "/order7def",
Rules: []subapi.Rule{
{Path: "/order7rule", Match: ""},
},
},
},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
g.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "type",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order1",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order2",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/topic", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order3",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.GetPath())
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order4",
})
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order7",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/order7rule", resp.GetPath())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/match/grpc.go
|
GO
|
mit
| 6,964 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package match
import (
"context"
"testing"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/aaa", "/type", "/foo", "/bar", "/topic", "/123", "/456", "/order7def", "/order7rule",
))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "type", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "type",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/type", Match: `event.type == "com.dapr.event.sent"`},
{Path: "/foo", Match: ""},
{Path: "/bar", Match: `event.type == "com.dapr.event.recv"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order1",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/type", Match: `event.type == "com.dapr.event.sent"`},
{Path: "/topic", Match: `event.topic == "order1"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order2",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/topic", Match: `event.topic == "order2"`},
{Path: "/type", Match: `event.type == "com.dapr.event.sent"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order3",
Routes: subapi.Routes{
Default: "/aaa",
Rules: []subapi.Rule{
{Path: "/123", Match: `event.topic == "order3"`},
{Path: "/456", Match: `event.topic == "order3"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order4",
Routes: subapi.Routes{
Rules: []subapi.Rule{
{Path: "/123", Match: `event.topic == "order5"`},
{Path: "/456", Match: `event.topic == "order6"`},
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "order7", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "order7",
Routes: subapi.Routes{
Default: "/order7def",
Rules: []subapi.Rule{
{Path: "/order7rule", Match: ""},
},
},
},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
h.daprd = daprd.New(t,
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd.WaitUntilRunning(t, ctx)
client := h.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "type",
})
require.NoError(t, err)
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.Route)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order1",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.Route)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order2",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/topic", resp.Route)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order3",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.Route)
h.sub.ExpectPublishNoReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "order4",
})
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order7",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/order7rule", resp.Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/match/http.go
|
GO
|
mit
| 7,073 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2alpha1
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/defaultroute"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/emptymatch"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/match"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes/routes.go
|
GO
|
mit
| 941 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
g.sub = subscriber.New(t)
appid1 := uuid.New().String()
appid2 := uuid.New().String()
g.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "sub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "all",
Routes: subapi.Routes{
Default: "/all",
},
},
Scopes: nil,
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "allempty",
Routes: subapi.Routes{
Default: "/allempty",
},
},
Scopes: []string{},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only1",
Routes: subapi.Routes{
Default: "/only1",
},
},
Scopes: []string{appid1},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only2",
Routes: subapi.Routes{
Default: "/only2",
},
},
Scopes: []string{appid2},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub5", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "both",
Routes: subapi.Routes{
Default: "/both",
},
},
Scopes: []string{appid1, appid2},
},
},
}),
)
g.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(g.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
daprdOpts := []daprd.Option{
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(g.operator.Address()),
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
}
g.daprd1 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid1))...)
g.daprd2 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid2))...)
return []framework.Option{
framework.WithProcesses(sentry, g.sub, g.kubeapi, g.operator, g.daprd1, g.daprd2),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.operator.WaitUntilRunning(t, ctx)
g.daprd1.WaitUntilRunning(t, ctx)
g.daprd2.WaitUntilRunning(t, ctx)
client1 := g.daprd1.GRPCClient(t, ctx)
client2 := g.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(topic string) *rtv1.PublishEventRequest {
return &rtv1.PublishEventRequest{PubsubName: "mypub", Topic: topic, Data: []byte(`{"status": "completed"}`)}
}
reqAll := newReq("all")
reqEmpty := newReq("allempty")
reqOnly1 := newReq("only1")
reqOnly2 := newReq("only2")
reqBoth := newReq("both")
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqEmpty)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqOnly1)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd1, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqBoth)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqEmpty)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd2, reqOnly1)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqBoth)
g.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/scopes/grpc.go
|
GO
|
mit
| 7,510 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
compapi "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/operator"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
kubeapi *kubernetes.Kubernetes
operator *operator.Operator
sub *subscriber.Subscriber
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/all", "/allempty", "/only1", "/only2", "/both",
))
sentry := sentry.New(t, sentry.WithTrustDomain("integration.test.dapr.io"))
appid1 := uuid.New().String()
appid2 := uuid.New().String()
h.kubeapi = kubernetes.New(t,
kubernetes.WithBaseOperatorAPI(t,
spiffeid.RequireTrustDomainFromString("integration.test.dapr.io"),
"default",
sentry.Port(),
),
kubernetes.WithClusterDaprComponentList(t, &compapi.ComponentList{
Items: []compapi.Component{{
ObjectMeta: metav1.ObjectMeta{Name: "mypub", Namespace: "default"},
Spec: compapi.ComponentSpec{
Type: "pubsub.in-memory", Version: "v1",
},
}},
}),
kubernetes.WithClusterDaprSubscriptionListV2(t, &subapi.SubscriptionList{
Items: []subapi.Subscription{
{
ObjectMeta: metav1.ObjectMeta{Name: "sub1", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "all",
Routes: subapi.Routes{
Default: "/all",
},
},
Scopes: nil,
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub2", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "allempty",
Routes: subapi.Routes{
Default: "/allempty",
},
},
Scopes: []string{},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub3", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only1",
Routes: subapi.Routes{
Default: "/only1",
},
},
Scopes: []string{appid1},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub4", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "only2",
Routes: subapi.Routes{
Default: "/only2",
},
},
Scopes: []string{appid2},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "sub5", Namespace: "default"},
Spec: subapi.SubscriptionSpec{
Pubsubname: "mypub",
Topic: "both",
Routes: subapi.Routes{
Default: "/both",
},
},
Scopes: []string{appid1, appid2},
},
},
}),
)
h.operator = operator.New(t,
operator.WithNamespace("default"),
operator.WithKubeconfigPath(h.kubeapi.KubeconfigPath(t)),
operator.WithTrustAnchorsFile(sentry.TrustAnchorsFile(t)),
)
daprdOpts := []daprd.Option{
daprd.WithMode("kubernetes"),
daprd.WithSentryAddress(sentry.Address()),
daprd.WithControlPlaneAddress(h.operator.Address()),
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithDisableK8sSecretStore(true),
daprd.WithEnableMTLS(true),
daprd.WithNamespace("default"),
daprd.WithControlPlaneTrustDomain("integration.test.dapr.io"),
daprd.WithExecOptions(exec.WithEnvVars(t,
"DAPR_TRUST_ANCHORS", string(sentry.CABundle().TrustAnchors),
)),
}
h.daprd1 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid1))...)
h.daprd2 = daprd.New(t, append(daprdOpts, daprd.WithAppID(appid2))...)
return []framework.Option{
framework.WithProcesses(sentry, h.sub, h.kubeapi, h.operator, h.daprd1, h.daprd2),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.operator.WaitUntilRunning(t, ctx)
h.daprd1.WaitUntilRunning(t, ctx)
h.daprd2.WaitUntilRunning(t, ctx)
client1 := h.daprd1.GRPCClient(t, ctx)
client2 := h.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.ElementsMatch(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(daprd *daprd.Daprd, topic string) subscriber.PublishRequest {
return subscriber.PublishRequest{
Daprd: daprd,
PubSubName: "mypub",
Topic: topic,
Data: `{"status": "completed"}`,
}
}
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "allempty"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "only1"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd1, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "both"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "allempty"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd2, "only1"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "both"))
h.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/scopes/http.go
|
GO
|
mit
| 7,581 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2alpha1
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/basic"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/bulk"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/deadletter"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/informer"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/missing"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/rawpayload"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/routes"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/scopes"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/operator/v2alpha1/v2alpha1.go
|
GO
|
mit
| 1,454 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package mixed
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(defaultroute))
}
type defaultroute struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (d *defaultroute) Setup(t *testing.T) []framework.Option {
d.sub = subscriber.New(t, subscriber.WithRoutes("/123", "/456", "/zyx", "/xyz"))
d.daprd = daprd.New(t,
daprd.WithAppPort(d.sub.Port()),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
route: /123
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: a
routes:
default: /456
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub3
spec:
pubsubname: mypub
topic: b
routes:
default: /xyz
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub4
spec:
pubsubname: mypub
topic: b
route: /zyx
`))
return []framework.Option{
framework.WithProcesses(d.sub, d.daprd),
}
}
func (d *defaultroute) Run(t *testing.T, ctx context.Context) {
d.daprd.WaitUntilRunning(t, ctx)
d.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: d.daprd,
PubSubName: "mypub",
Topic: "a",
})
assert.Equal(t, "/123", d.sub.Receive(t, ctx).Route)
d.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: d.daprd,
PubSubName: "mypub",
Topic: "b",
})
assert.Equal(t, "/xyz", d.sub.Receive(t, ctx).Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/mixed/defaultroute.go
|
GO
|
mit
| 2,413 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package mixed
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(emptyroute))
}
type emptyroute struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (e *emptyroute) Setup(t *testing.T) []framework.Option {
e.sub = subscriber.New(t, subscriber.WithRoutes("/a/b/c/d", "/123"))
e.daprd = daprd.New(t,
daprd.WithAppPort(e.sub.Port()),
daprd.WithResourceFiles(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
route: /a/b/c/d
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: a
routes:
rules:
- path: /123
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub3
spec:
pubsubname: mypub
topic: b
routes:
rules:
- path: /123
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub4
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(e.sub, e.daprd),
}
}
func (e *emptyroute) Run(t *testing.T, ctx context.Context) {
e.daprd.WaitUntilRunning(t, ctx)
e.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: e.daprd,
PubSubName: "mypub",
Topic: "a",
})
assert.Equal(t, "/a/b/c/d", e.sub.Receive(t, ctx).Route)
e.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: e.daprd,
PubSubName: "mypub",
Topic: "b",
})
assert.Equal(t, "/123", e.sub.Receive(t, ctx).Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/mixed/emptyroute.go
|
GO
|
mit
| 2,418 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package mixed
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(match))
}
type match struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (m *match) Setup(t *testing.T) []framework.Option {
m.sub = subscriber.New(t, subscriber.WithRoutes("/a/b/c/d", "/123"))
m.daprd = daprd.New(t,
daprd.WithAppPort(m.sub.Port()),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
route: /a/b/c/d
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: a
routes:
rules:
- path: /123
match: event.topic == "a"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub3
spec:
pubsubname: mypub
topic: b
routes:
rules:
- path: /123
match: event.topic == "b"
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub4
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(m.sub, m.daprd),
}
}
func (m *match) Run(t *testing.T, ctx context.Context) {
m.daprd.WaitUntilRunning(t, ctx)
m.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: m.daprd,
PubSubName: "mypub",
Topic: "a",
})
assert.Equal(t, "/a/b/c/d", m.sub.Receive(t, ctx).Route)
m.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: m.daprd,
PubSubName: "mypub",
Topic: "b",
})
assert.Equal(t, "/123", m.sub.Receive(t, ctx).Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/mixed/match.go
|
GO
|
mit
| 2,460 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package selfhosted
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/mixed"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/selfhosted.go
|
GO
|
mit
| 895 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
route: /a
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.JSONEq(t, `{"status": "completed"}`, string(resp.GetData()))
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Empty(t, resp.GetData())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "foo/bar", resp.GetDataContentType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "foo", string(resp.GetData()))
assert.Equal(t, "text/plain", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/basic/grpc.go
|
GO
|
mit
| 3,274 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/a"),
)
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
route: /a
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/json", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "foo/bar", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "foo", string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/basic/http.go
|
GO
|
mit
| 3,985 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
route: /a
bulkSubscribe:
enabled: true
maxMessagesCount: 100
maxAwaitDurationMs: 40
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: nobulk
spec:
pubsubname: mypub
topic: b
route: /b
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
resp, err := client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "a",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.AssertBulkEventChanLen(t, 0)
resp, err = client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "b",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.AssertBulkEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/bulk/grpc.go
|
GO
|
mit
| 3,324 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithBulkRoutes("/a", "/b"))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
route: /a
bulkSubscribe:
enabled: true
maxMessagesCount: 100
maxAwaitDurationMs: 40
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: nobulk
spec:
pubsubname: mypub
topic: b
route: /b
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/bulk/http.go
|
GO
|
mit
| 3,048 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/app"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
app *app.App
inCh chan *rtv1.TopicEventRequest
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.inCh = make(chan *rtv1.TopicEventRequest)
g.app = app.New(t,
app.WithOnTopicEventFn(func(ctx context.Context, in *rtv1.TopicEventRequest) (*rtv1.TopicEventResponse, error) {
if in.GetTopic() == "a" {
return nil, errors.New("my error")
}
g.inCh <- in
return new(rtv1.TopicEventResponse), nil
}),
)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.app.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
route: /a
deadLetterTopic: mydead
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: anothermysub
spec:
pubsubname: mypub
topic: mydead
route: /b
deadLetterTopic: mydead
`))
return []framework.Option{
framework.WithProcesses(g.app, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
ctx, cancel := context.WithTimeout(ctx, time.Second)
t.Cleanup(cancel)
select {
case <-ctx.Done():
assert.Fail(t, "timeout waiting for event")
case in := <-g.inCh:
assert.Equal(t, "mydead", in.GetTopic())
assert.Equal(t, "/b", in.GetPath())
}
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/deadletter/grpc.go
|
GO
|
mit
| 2,769 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
nethttp "net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/b"),
subscriber.WithHandlerFunc("/a", func(w nethttp.ResponseWriter, r *nethttp.Request) {
w.WriteHeader(nethttp.StatusServiceUnavailable)
}),
)
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: mypub
topic: a
route: /a
deadLetterTopic: mydead
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: mydead
route: /b
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/b", resp.Route)
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, `{"status": "completed"}`, string(resp.Data()))
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/deadletter/http.go
|
GO
|
mit
| 2,317 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: anotherpub
topic: a
route: /a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: c
route: /c
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
g.sub.ExpectPublishError(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "anotherpub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "b", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "c", Data: []byte(`{"status": "completed"}`),
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/missing/grpc.go
|
GO
|
mit
| 2,525 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a", "/b", "/c"))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: anotherpub
topic: a
route: /a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: c
route: /c
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
meta, err := h.daprd.GRPCClient(t, ctx).GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
h.sub.ExpectPublishError(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "anotherpub",
Topic: "a",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishNoReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "c",
Data: `{"status": "completed"}`,
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/missing/http.go
|
GO
|
mit
| 2,611 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/dapr/components-contrib/pubsub"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
route: /a
metadata:
rawPayload: "true"
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["datacontenttype"] = "foo/bar"
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/rawpayload/grpc.go
|
GO
|
mit
| 4,639 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/dapr/components-contrib/pubsub"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/a"),
)
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
route: /a
metadata:
rawPayload: "true"
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "text/plain", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "foo/bar"
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/rawpayload/http.go
|
GO
|
mit
| 5,635 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package route
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: mypub
topic: a
route: /a/b/c/d
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: a
route: /a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub3
spec:
pubsubname: mypub
topic: b
route: /a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub4
spec:
pubsubname: mypub
topic: b
route: /d/c/b/a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub5
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "a",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a/b/c/d", resp.GetPath())
assert.Empty(t, resp.GetData())
// Uses the first defined route for a topic when two declared routes match
// the topic.
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "b",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Empty(t, resp.GetData())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/route/grpc.go
|
GO
|
mit
| 2,846 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package route
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a", "/d/c/b/a", "/a/b/c/d"))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: mypub
topic: a
route: /a/b/c/d
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: a
route: /a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub3
spec:
pubsubname: mypub
topic: b
route: /a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub5
spec:
pubsubname: mypub
topic: b
route: /d/c/b/a
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: mysub6
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a/b/c/d", resp.Route)
assert.Empty(t, resp.Data())
// Uses the first defined route for a topic when two declared routes match
// the topic.
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Empty(t, resp.Data())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/route/http.go
|
GO
|
mit
| 2,728 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
resDir := t.TempDir()
g.daprd1 = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourcesDir(resDir),
)
g.daprd2 = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourcesDir(resDir),
)
require.NoError(t, os.WriteFile(filepath.Join(resDir, "sub.yaml"),
[]byte(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: all
route: /all
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: allempty
route: /allempty
scopes: []
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub3
spec:
pubsubname: mypub
topic: only1
route: /only1
scopes:
- %[1]s
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub4
spec:
pubsubname: mypub
topic: only2
route: /only2
scopes:
- %[2]s
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub5
spec:
pubsubname: mypub
topic: both
route: /both
scopes:
- %[1]s
- %[2]s
`, g.daprd1.AppID(), g.daprd2.AppID())), 0o600))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd1, g.daprd2),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd1.WaitUntilRunning(t, ctx)
g.daprd2.WaitUntilRunning(t, ctx)
client1 := g.daprd1.GRPCClient(t, ctx)
client2 := g.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(topic string) *rtv1.PublishEventRequest {
return &rtv1.PublishEventRequest{PubsubName: "mypub", Topic: topic, Data: []byte(`{"status": "completed"}`)}
}
reqAll := newReq("all")
reqEmpty := newReq("allempty")
reqOnly1 := newReq("only1")
reqOnly2 := newReq("only2")
reqBoth := newReq("both")
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqEmpty)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqOnly1)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd1, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqBoth)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqEmpty)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd2, reqOnly1)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqBoth)
g.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/scopes/grpc.go
|
GO
|
mit
| 5,199 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/all", "/allempty", "/only1", "/only2", "/both",
))
resDir := t.TempDir()
h.daprd1 = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourcesDir(resDir),
)
h.daprd2 = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourcesDir(resDir),
)
require.NoError(t, os.WriteFile(filepath.Join(resDir, "sub.yaml"),
[]byte(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: all
route: /all
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: allempty
route: /allempty
scopes: []
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub3
spec:
pubsubname: mypub
topic: only1
route: /only1
scopes:
- %[1]s
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub4
spec:
pubsubname: mypub
topic: only2
route: /only2
scopes:
- %[2]s
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub5
spec:
pubsubname: mypub
topic: both
route: /both
scopes:
- %[1]s
- %[2]s
`, h.daprd1.AppID(), h.daprd2.AppID())), 0o600))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd1, h.daprd2),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd1.WaitUntilRunning(t, ctx)
h.daprd2.WaitUntilRunning(t, ctx)
client1 := h.daprd1.GRPCClient(t, ctx)
client2 := h.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(daprd *daprd.Daprd, topic string) subscriber.PublishRequest {
return subscriber.PublishRequest{
Daprd: daprd,
PubSubName: "mypub",
Topic: topic,
Data: `{"status": "completed"}`,
}
}
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "allempty"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "only1"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd1, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "both"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "allempty"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd2, "only1"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "both"))
h.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/scopes/http.go
|
GO
|
mit
| 5,268 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/basic"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/bulk"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/deadletter"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/missing"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/rawpayload"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/route"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/scopes"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v1alpha1/v1alpha1.go
|
GO
|
mit
| 1,358 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
routes:
default: /a
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.JSONEq(t, `{"status": "completed"}`, string(resp.GetData()))
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Empty(t, resp.GetData())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "foo/bar", resp.GetDataContentType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "foo", string(resp.GetData()))
assert.Equal(t, "text/plain", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/basic/grpc.go
|
GO
|
mit
| 3,288 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/a"),
)
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
routes:
default: /a
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/json", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.JSONEq(t, `{"status": "completed"}`, string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "foo/bar", resp.DataContentType())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "foo", string(resp.Data()))
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "text/plain", resp.DataContentType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/basic/http.go
|
GO
|
mit
| 3,999 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
routes:
default: /a
bulkSubscribe:
enabled: true
maxMessagesCount: 100
maxAwaitDurationMs: 40
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: nobulk
spec:
pubsubname: mypub
topic: b
routes:
default: /b
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
resp, err := client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "a",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.ReceiveBulk(t, ctx)
g.sub.AssertBulkEventChanLen(t, 0)
resp, err = client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "b",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
g.sub.AssertBulkEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/bulk/grpc.go
|
GO
|
mit
| 3,348 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bulk
import (
"context"
"testing"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithBulkRoutes("/a", "/b"))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
routes:
default: /a
bulkSubscribe:
enabled: true
maxMessagesCount: 100
maxAwaitDurationMs: 40
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: nobulk
spec:
pubsubname: mypub
topic: b
routes:
default: /b
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.PublishBulk(t, ctx, subscriber.PublishBulkRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Entries: []subscriber.PublishBulkRequestEntry{
{EntryID: "1", Event: `{"id": 1}`, ContentType: "application/json"},
{EntryID: "2", Event: `{"id": 2}`, ContentType: "application/json"},
{EntryID: "3", Event: `{"id": 3}`, ContentType: "application/json"},
{EntryID: "4", Event: `{"id": 4}`, ContentType: "application/json"},
},
})
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
h.sub.ReceiveBulk(t, ctx)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/bulk/http.go
|
GO
|
mit
| 3,072 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/app"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
app *app.App
inCh chan *rtv1.TopicEventRequest
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.inCh = make(chan *rtv1.TopicEventRequest)
g.app = app.New(t,
app.WithOnTopicEventFn(func(ctx context.Context, in *rtv1.TopicEventRequest) (*rtv1.TopicEventResponse, error) {
if in.GetTopic() == "a" {
return nil, errors.New("my error")
}
g.inCh <- in
return new(rtv1.TopicEventResponse), nil
}),
)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.app.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: mypub
topic: a
routes:
default: /a
deadLetterTopic: mydead
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: mydead
routes:
default: /b
deadLetterTopic: mydead
`))
return []framework.Option{
framework.WithProcesses(g.app, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
ctx, cancel := context.WithTimeout(ctx, time.Second)
t.Cleanup(cancel)
select {
case <-ctx.Done():
assert.Fail(t, "timeout waiting for event")
case in := <-g.inCh:
assert.Equal(t, "mydead", in.GetTopic())
assert.Equal(t, "/b", in.GetPath())
}
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/deadletter/grpc.go
|
GO
|
mit
| 2,788 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deadletter
import (
"context"
nethttp "net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/b"),
subscriber.WithHandlerFunc("/a", func(w nethttp.ResponseWriter, r *nethttp.Request) {
w.WriteHeader(nethttp.StatusServiceUnavailable)
}),
)
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: mypub
topic: a
routes:
default: /a
deadLetterTopic: mydead
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: mydead
routes:
default: /b
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/b", resp.Route)
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, `{"status": "completed"}`, string(resp.Data()))
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/deadletter/http.go
|
GO
|
mit
| 2,341 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: anotherpub
topic: a
routes:
default: /a
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: c
routes:
default: /c
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
meta, err := client.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
g.sub.ExpectPublishError(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "anotherpub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "b", Data: []byte(`{"status": "completed"}`),
})
g.sub.ExpectPublishReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "c", Data: []byte(`{"status": "completed"}`),
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/missing/grpc.go
|
GO
|
mit
| 2,549 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package missing
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes("/a", "/b", "/c"))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: anotherpub
topic: a
routes:
default: /a
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: c
routes:
default: /c
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
meta, err := h.daprd.GRPCClient(t, ctx).GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Len(t, meta.GetRegisteredComponents(), 1)
assert.Len(t, meta.GetSubscriptions(), 2)
h.sub.ExpectPublishError(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "anotherpub",
Topic: "a",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishNoReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
Data: `{"status": "completed"}`,
})
h.sub.ExpectPublishReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "c",
Data: `{"status": "completed"}`,
})
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/missing/http.go
|
GO
|
mit
| 2,635 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/dapr/components-contrib/pubsub"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
routes:
default: /a
metadata:
rawPayload: "true"
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["datacontenttype"] = "foo/bar"
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "application/octet-stream", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.GetData())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/rawpayload/grpc.go
|
GO
|
mit
| 4,651 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rawpayload
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/dapr/components-contrib/pubsub"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
"github.com/dapr/kit/ptr"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t,
subscriber.WithRoutes("/a"),
)
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub
spec:
pubsubname: mypub
topic: a
routes:
default: /a
metadata:
rawPayload: "true"
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
var ce map[string]any
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp := pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "text/plain", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("application/json"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte(`{"status": "completed"}`), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: `{"status": "completed"}`,
DataContentType: ptr.Of("foo/bar"),
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", nil, "", "")
exp["id"] = ce["id"]
exp["data"] = `{"status": "completed"}`
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "foo/bar"
assert.Equal(t, exp, ce)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
Data: "foo",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.Route)
assert.Equal(t, "1.0", resp.SpecVersion())
assert.Equal(t, "mypub", resp.Extensions()["pubsubname"])
assert.Equal(t, "a", resp.Extensions()["topic"])
assert.Equal(t, "com.dapr.event.sent", resp.Type())
assert.Equal(t, "application/octet-stream", resp.DataContentType())
require.NoError(t, json.NewDecoder(bytes.NewReader(resp.Data())).Decode(&ce))
exp = pubsub.NewCloudEventsEnvelope("", "", "com.dapr.event.sent", "", "a", "mypub", "application/json", []byte("foo"), "", "")
exp["id"] = ce["id"]
exp["source"] = ce["source"]
exp["time"] = ce["time"]
exp["traceid"] = ce["traceid"]
exp["traceparent"] = ce["traceparent"]
exp["datacontenttype"] = "text/plain"
assert.Equal(t, exp, ce)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/rawpayload/http.go
|
GO
|
mit
| 5,647 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package defaultroute
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: mypub
topic: a
routes:
default: /a/b/c/d
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: a
routes:
default: /a
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub3
spec:
pubsubname: mypub
topic: b
routes:
default: /a
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub4
spec:
pubsubname: mypub
topic: b
routes:
default: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "a",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/a/b/c/d", resp.GetPath())
assert.Empty(t, resp.GetData())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "b",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Empty(t, resp.GetData())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/defaultroute/grpc.go
|
GO
|
mit
| 2,659 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package defaultroute
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/a/b/c/d", "/a", "/b", "/d/c/b/a",
))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub1
spec:
pubsubname: mypub
topic: a
routes:
default: /a/b/c/d
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub2
spec:
pubsubname: mypub
topic: a
routes:
default: /a
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub3
spec:
pubsubname: mypub
topic: b
routes:
default: /b
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysub4
spec:
pubsubname: mypub
topic: b
routes:
default: /d/c/b/a
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "a",
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/a/b/c/d", resp.Route)
assert.Empty(t, resp.Data())
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "b",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/b", resp.Route)
assert.Empty(t, resp.Data())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/defaultroute/http.go
|
GO
|
mit
| 2,553 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package emptymatch
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: justpath
spec:
pubsubname: mypub
topic: justpath
routes:
rules:
- path: /justpath
match: ""
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: defaultandpath
spec:
pubsubname: mypub
topic: defaultandpath
routes:
default: /abc
rules:
- path: /123
match: ""
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: multipaths
spec:
pubsubname: mypub
topic: multipaths
routes:
rules:
- path: /xyz
match: ""
- path: /456
match: ""
- path: /789
match: ""
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: defaultandpaths
spec:
pubsubname: mypub
topic: defaultandpaths
routes:
default: /def
rules:
- path: /zyz
match: ""
- path: /aaa
match: ""
- path: /bbb
match: ""
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "justpath",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/justpath", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "defaultandpath",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "multipaths",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/xyz", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "defaultandpaths",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/zyz", resp.GetPath())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/emptymatch/grpc.go
|
GO
|
mit
| 3,351 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package emptymatch
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/justpath", "/abc", "/123", "/def", "/zyz",
"/aaa", "/bbb", "/xyz", "/456", "/789",
))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: justpath
spec:
pubsubname: mypub
topic: justpath
routes:
rules:
- path: /justpath
match: ""
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: defaultandpath
spec:
pubsubname: mypub
topic: defaultandpath
routes:
default: /abc
rules:
- path: /123
match: ""
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: multipaths
spec:
pubsubname: mypub
topic: multipaths
routes:
rules:
- path: /xyz
match: ""
- path: /456
match: ""
- path: /789
match: ""
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: defaultandpaths
spec:
pubsubname: mypub
topic: defaultandpaths
routes:
default: /def
rules:
- path: /zyz
match: ""
- path: /aaa
match: ""
- path: /bbb
match: ""
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "justpath",
})
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/justpath", resp.Route)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "defaultandpath",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.Route)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "multipaths",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/xyz", resp.Route)
h.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "defaultandpaths",
})
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/zyz", resp.Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/emptymatch/http.go
|
GO
|
mit
| 3,294 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package match
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
g.daprd = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: type
spec:
pubsubname: mypub
topic: type
routes:
default: /aaa
rules:
- path: /type
match: event.type == "com.dapr.event.sent"
- path: /foo
match: ""
- path: /bar
match: event.type == "com.dapr.event.recv"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order1
spec:
pubsubname: mypub
topic: order1
routes:
default: /aaa
rules:
- path: /type
match: event.type == "com.dapr.event.sent"
- path: /topic
match: event.topic == "order1"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order2
spec:
pubsubname: mypub
topic: order2
routes:
default: /aaa
rules:
- path: /topic
match: event.topic == "order2"
- path: /type
match: event.type == "com.dapr.event.sent"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order3
spec:
pubsubname: mypub
topic: order3
routes:
default: /aaa
rules:
- path: /123
match: event.topic == "order3"
- path: /456
match: event.topic == "order3"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order4
spec:
pubsubname: mypub
topic: order4
routes:
rules:
- path: /123
match: event.topic == "order5"
- path: /456
match: event.topic == "order6"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order7
spec:
pubsubname: mypub
topic: order7
default: /order7def
routes:
rules:
- path: /order7rule
match: ""
`))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd.WaitUntilRunning(t, ctx)
client := g.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "type",
})
require.NoError(t, err)
resp := g.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order1",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order2",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/topic", resp.GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order3",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.GetPath())
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order4",
})
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order7",
})
require.NoError(t, err)
resp = g.sub.Receive(t, ctx)
assert.Equal(t, "/order7rule", resp.GetPath())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/match/grpc.go
|
GO
|
mit
| 4,317 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package match
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/aaa", "/type", "/foo", "/bar", "/topic",
"/123", "/456", "/order7def", "/order7rule",
))
h.daprd = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourceFiles(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: type
spec:
pubsubname: mypub
topic: type
routes:
default: /aaa
rules:
- path: /type
match: event.type == "com.dapr.event.sent"
- path: /foo
match: ""
- path: /bar
match: event.type == "com.dapr.event.recv"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order1
spec:
pubsubname: mypub
topic: order1
routes:
default: /aaa
rules:
- path: /type
match: event.type == "com.dapr.event.sent"
- path: /topic
match: event.topic == "order1"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order2
spec:
pubsubname: mypub
topic: order2
routes:
default: /aaa
rules:
- path: /topic
match: event.topic == "order2"
- path: /type
match: event.type == "com.dapr.event.sent"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order3
spec:
pubsubname: mypub
topic: order3
routes:
default: /aaa
rules:
- path: /123
match: event.topic == "order3"
- path: /456
match: event.topic == "order3"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order4
spec:
pubsubname: mypub
topic: order4
routes:
rules:
- path: /123
match: event.topic == "order5"
- path: /456
match: event.topic == "order6"
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: order7
spec:
pubsubname: mypub
topic: order7
default: /order7def
routes:
rules:
- path: /order7rule
match: ""
`))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd.WaitUntilRunning(t, ctx)
client := h.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "type",
})
require.NoError(t, err)
resp := h.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.Route)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order1",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/type", resp.Route)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order2",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/topic", resp.Route)
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order3",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/123", resp.Route)
h.sub.ExpectPublishNoReceive(t, ctx, subscriber.PublishRequest{
Daprd: h.daprd,
PubSubName: "mypub",
Topic: "order4",
})
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub",
Topic: "order7",
})
require.NoError(t, err)
resp = h.sub.Receive(t, ctx)
assert.Equal(t, "/order7rule", resp.Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/match/http.go
|
GO
|
mit
| 4,429 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2alpha1
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/defaultroute"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/emptymatch"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/match"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes/routes.go
|
GO
|
mit
| 947 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(grpc))
}
type grpc struct {
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
sub *subscriber.Subscriber
}
func (g *grpc) Setup(t *testing.T) []framework.Option {
g.sub = subscriber.New(t)
resDir := t.TempDir()
g.daprd1 = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourcesDir(resDir),
)
g.daprd2 = daprd.New(t,
daprd.WithAppPort(g.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourcesDir(resDir),
)
require.NoError(t, os.WriteFile(filepath.Join(resDir, "sub.yaml"),
[]byte(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: all
routes:
default: /all
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: allempty
routes:
default: /allempty
scopes: []
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub3
spec:
pubsubname: mypub
topic: only1
routes:
default: /only1
scopes:
- %[1]s
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub4
spec:
pubsubname: mypub
topic: only2
routes:
default: /only2
scopes:
- %[2]s
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub5
spec:
pubsubname: mypub
topic: both
routes:
default: /both
scopes:
- %[1]s
- %[2]s
`, g.daprd1.AppID(), g.daprd2.AppID())), 0o600))
return []framework.Option{
framework.WithProcesses(g.sub, g.daprd1, g.daprd2),
}
}
func (g *grpc) Run(t *testing.T, ctx context.Context) {
g.daprd1.WaitUntilRunning(t, ctx)
g.daprd2.WaitUntilRunning(t, ctx)
client1 := g.daprd1.GRPCClient(t, ctx)
client2 := g.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(topic string) *rtv1.PublishEventRequest {
return &rtv1.PublishEventRequest{PubsubName: "mypub", Topic: topic, Data: []byte(`{"status": "completed"}`)}
}
reqAll := newReq("all")
reqEmpty := newReq("allempty")
reqOnly1 := newReq("only1")
reqOnly2 := newReq("only2")
reqBoth := newReq("both")
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqEmpty)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqOnly1)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd1, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd1, reqBoth)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqAll)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqEmpty)
g.sub.ExpectPublishNoReceive(t, ctx, g.daprd2, reqOnly1)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqOnly2)
g.sub.ExpectPublishReceive(t, ctx, g.daprd2, reqBoth)
g.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/scopes/grpc.go
|
GO
|
mit
| 5,269 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scopes
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(http))
}
type http struct {
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
sub *subscriber.Subscriber
}
func (h *http) Setup(t *testing.T) []framework.Option {
h.sub = subscriber.New(t, subscriber.WithRoutes(
"/all", "/allempty", "/only1", "/only2", "/both",
))
resDir := t.TempDir()
h.daprd1 = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourcesDir(resDir),
)
h.daprd2 = daprd.New(t,
daprd.WithAppPort(h.sub.Port()),
daprd.WithAppProtocol("http"),
daprd.WithResourcesDir(resDir),
)
require.NoError(t, os.WriteFile(filepath.Join(resDir, "sub.yaml"),
[]byte(fmt.Sprintf(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: all
routes:
default: /all
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: allempty
routes:
default: /allempty
scopes: []
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub3
spec:
pubsubname: mypub
topic: only1
routes:
default: /only1
scopes:
- %[1]s
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub4
spec:
pubsubname: mypub
topic: only2
routes:
default: /only2
scopes:
- %[2]s
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub5
spec:
pubsubname: mypub
topic: both
routes:
default: /both
scopes:
- %[1]s
- %[2]s
`, h.daprd1.AppID(), h.daprd2.AppID())), 0o600))
return []framework.Option{
framework.WithProcesses(h.sub, h.daprd1, h.daprd2),
}
}
func (h *http) Run(t *testing.T, ctx context.Context) {
h.daprd1.WaitUntilRunning(t, ctx)
h.daprd2.WaitUntilRunning(t, ctx)
client1 := h.daprd1.GRPCClient(t, ctx)
client2 := h.daprd2.GRPCClient(t, ctx)
meta, err := client1.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only1", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only1"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
meta, err = client2.GetMetadata(ctx, new(rtv1.GetMetadataRequest))
require.NoError(t, err)
assert.Equal(t, []*rtv1.PubsubSubscription{
{PubsubName: "mypub", Topic: "all", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/all"}},
}},
{PubsubName: "mypub", Topic: "allempty", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/allempty"}},
}},
{PubsubName: "mypub", Topic: "only2", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/only2"}},
}},
{PubsubName: "mypub", Topic: "both", Rules: &rtv1.PubsubSubscriptionRules{
Rules: []*rtv1.PubsubSubscriptionRule{{Path: "/both"}},
}},
}, meta.GetSubscriptions())
newReq := func(daprd *daprd.Daprd, topic string) subscriber.PublishRequest {
return subscriber.PublishRequest{
Daprd: daprd,
PubSubName: "mypub",
Topic: topic,
Data: `{"status": "completed"}`,
}
}
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "allempty"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "only1"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd1, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd1, "both"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "all"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "allempty"))
h.sub.ExpectPublishNoReceive(t, ctx, newReq(h.daprd2, "only1"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "only2"))
h.sub.ExpectPublishReceive(t, ctx, newReq(h.daprd2, "both"))
h.sub.AssertEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/scopes/http.go
|
GO
|
mit
| 5,338 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2alpha1
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/basic"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/bulk"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/deadletter"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/missing"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/rawpayload"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/routes"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/scopes"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/declarative/selfhosted/v2alpha1/v2alpha1.go
|
GO
|
mit
| 1,359 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/emptypb"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(defaultroute))
}
type defaultroute struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (d *defaultroute) Setup(t *testing.T) []framework.Option {
d.sub = subscriber.New(t,
subscriber.WithListTopicSubscriptions(func(context.Context, *emptypb.Empty) (*rtv1.ListTopicSubscriptionsResponse, error) {
return &rtv1.ListTopicSubscriptionsResponse{
Subscriptions: []*rtv1.TopicSubscription{
{
PubsubName: "mypub",
Topic: "a",
Routes: &rtv1.TopicRoutes{
Default: "/123",
},
},
{
PubsubName: "mypub",
Topic: "b",
Routes: &rtv1.TopicRoutes{
Default: "/xyz",
},
},
},
}, nil
}),
)
d.daprd = daprd.New(t,
daprd.WithAppPort(d.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
routes:
default: /456
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: b
route: /zyx
`))
return []framework.Option{
framework.WithProcesses(d.sub, d.daprd),
}
}
func (d *defaultroute) Run(t *testing.T, ctx context.Context) {
d.daprd.WaitUntilRunning(t, ctx)
client := d.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
require.NoError(t, err)
assert.Equal(t, "/123", d.sub.Receive(t, ctx).GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
require.NoError(t, err)
assert.Equal(t, "/123", d.sub.Receive(t, ctx).GetPath())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/mixed/grpc/defaultroute.go
|
GO
|
mit
| 2,926 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/emptypb"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(emptyroute))
}
type emptyroute struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (e *emptyroute) Setup(t *testing.T) []framework.Option {
e.sub = subscriber.New(t,
subscriber.WithListTopicSubscriptions(func(context.Context, *emptypb.Empty) (*rtv1.ListTopicSubscriptionsResponse, error) {
return &rtv1.ListTopicSubscriptionsResponse{
Subscriptions: []*rtv1.TopicSubscription{
{
PubsubName: "mypub",
Topic: "a",
Routes: &rtv1.TopicRoutes{
Default: "/a/b/c/d",
},
},
{
PubsubName: "mypub",
Topic: "b",
Routes: &rtv1.TopicRoutes{
Rules: []*rtv1.TopicRule{
{Path: "/123"},
},
},
},
},
}, nil
}),
)
e.daprd = daprd.New(t,
daprd.WithAppPort(e.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
routes:
rules:
- path: /123
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(e.sub, e.daprd),
}
}
func (e *emptyroute) Run(t *testing.T, ctx context.Context) {
e.daprd.WaitUntilRunning(t, ctx)
client := e.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
require.NoError(t, err)
assert.Equal(t, "/a/b/c/d", e.sub.Receive(t, ctx).GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
require.NoError(t, err)
assert.Equal(t, "/a/b/c/d", e.sub.Receive(t, ctx).GetPath())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/mixed/grpc/emptyroute.go
|
GO
|
mit
| 3,011 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/emptypb"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(match))
}
type match struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (e *match) Setup(t *testing.T) []framework.Option {
e.sub = subscriber.New(t,
subscriber.WithListTopicSubscriptions(func(context.Context, *emptypb.Empty) (*rtv1.ListTopicSubscriptionsResponse, error) {
return &rtv1.ListTopicSubscriptionsResponse{
Subscriptions: []*rtv1.TopicSubscription{
{
PubsubName: "mypub",
Topic: "a",
Routes: &rtv1.TopicRoutes{
Default: "/a/b/c/d",
},
},
{
PubsubName: "mypub",
Topic: "b",
Routes: &rtv1.TopicRoutes{
Rules: []*rtv1.TopicRule{
{Path: "/123", Match: `event.topic == "b"`},
},
},
},
},
}, nil
}),
)
e.daprd = daprd.New(t,
daprd.WithAppPort(e.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
routes:
rules:
- path: /123
match: event.topic == "a"
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(e.sub, e.daprd),
}
}
func (e *match) Run(t *testing.T, ctx context.Context) {
e.daprd.WaitUntilRunning(t, ctx)
client := e.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
require.NoError(t, err)
assert.Equal(t, "/a/b/c/d", e.sub.Receive(t, ctx).GetPath())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
})
require.NoError(t, err)
assert.Equal(t, "/a/b/c/d", e.sub.Receive(t, ctx).GetPath())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/mixed/grpc/match.go
|
GO
|
mit
| 3,024 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(defaultroute))
}
type defaultroute struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (d *defaultroute) Setup(t *testing.T) []framework.Option {
d.sub = subscriber.New(t,
subscriber.WithRoutes("/123", "/456", "/zyx", "/xyz"),
subscriber.WithProgrammaticSubscriptions(
subscriber.SubscriptionJSON{
PubsubName: "mypub",
Topic: "a",
Route: "/123",
},
subscriber.SubscriptionJSON{
PubsubName: "mypub",
Topic: "b",
Routes: subscriber.RoutesJSON{
Default: "/xyz",
},
},
),
)
d.daprd = daprd.New(t,
daprd.WithAppPort(d.sub.Port()),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
routes:
default: /456
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: b
route: /zyx
`))
return []framework.Option{
framework.WithProcesses(d.sub, d.daprd),
}
}
func (d *defaultroute) Run(t *testing.T, ctx context.Context) {
d.daprd.WaitUntilRunning(t, ctx)
d.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: d.daprd,
PubSubName: "mypub",
Topic: "a",
})
assert.Equal(t, "/123", d.sub.Receive(t, ctx).Route)
d.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: d.daprd,
PubSubName: "mypub",
Topic: "b",
})
assert.Equal(t, "/xyz", d.sub.Receive(t, ctx).Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/mixed/http/defaultroute.go
|
GO
|
mit
| 2,466 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(emptyroute))
}
type emptyroute struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (e *emptyroute) Setup(t *testing.T) []framework.Option {
e.sub = subscriber.New(t,
subscriber.WithRoutes("/a/b/c/d", "/123"),
subscriber.WithProgrammaticSubscriptions(
subscriber.SubscriptionJSON{
PubsubName: "mypub",
Topic: "a",
Route: "/a/b/c/d",
},
subscriber.SubscriptionJSON{
PubsubName: "mypub",
Topic: "b",
Routes: subscriber.RoutesJSON{
Rules: []*subscriber.RuleJSON{
{Path: "/123"},
},
},
},
),
)
e.daprd = daprd.New(t,
daprd.WithAppPort(e.sub.Port()),
daprd.WithResourceFiles(`
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
Kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
routes:
rules:
- path: /123
---
apiVersion: dapr.io/v1alpha1
Kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(e.sub, e.daprd),
}
}
func (e *emptyroute) Run(t *testing.T, ctx context.Context) {
e.daprd.WaitUntilRunning(t, ctx)
e.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: e.daprd,
PubSubName: "mypub",
Topic: "a",
})
assert.Equal(t, "/a/b/c/d", e.sub.Receive(t, ctx).Route)
e.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: e.daprd,
PubSubName: "mypub",
Topic: "b",
})
assert.Equal(t, "/123", e.sub.Receive(t, ctx).Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/mixed/http/emptyroute.go
|
GO
|
mit
| 2,507 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package http
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(match))
}
type match struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (m *match) Setup(t *testing.T) []framework.Option {
m.sub = subscriber.New(t,
subscriber.WithRoutes("/a/b/c/d", "/123"),
subscriber.WithProgrammaticSubscriptions(
subscriber.SubscriptionJSON{
PubsubName: "mypub",
Topic: "a",
Route: "/a/b/c/d",
},
subscriber.SubscriptionJSON{
PubsubName: "mypub",
Topic: "b",
Routes: subscriber.RoutesJSON{
Rules: []*subscriber.RuleJSON{
{
Path: "/123",
Match: `event.topic == "b"`,
},
},
},
},
),
)
m.daprd = daprd.New(t,
daprd.WithAppPort(m.sub.Port()),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
---
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: sub1
spec:
pubsubname: mypub
topic: a
routes:
rules:
- path: /123
match: event.topic == "a"
---
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: sub2
spec:
pubsubname: mypub
topic: b
route: /a/b/c/d
`))
return []framework.Option{
framework.WithProcesses(m.sub, m.daprd),
}
}
func (m *match) Run(t *testing.T, ctx context.Context) {
m.daprd.WaitUntilRunning(t, ctx)
m.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: m.daprd,
PubSubName: "mypub",
Topic: "a",
})
assert.Equal(t, "/a/b/c/d", m.sub.Receive(t, ctx).Route)
m.sub.Publish(t, ctx, subscriber.PublishRequest{
Daprd: m.daprd,
PubSubName: "mypub",
Topic: "b",
})
assert.Equal(t, "/123", m.sub.Receive(t, ctx).Route)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/mixed/http/match.go
|
GO
|
mit
| 2,573 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package subscriptions
import (
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/mixed/grpc"
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions/mixed/http"
)
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/mixed/mixed.go
|
GO
|
mit
| 757 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/emptypb"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(basic))
}
type basic struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (b *basic) Setup(t *testing.T) []framework.Option {
b.sub = subscriber.New(t,
subscriber.WithListTopicSubscriptions(func(context.Context, *emptypb.Empty) (*rtv1.ListTopicSubscriptionsResponse, error) {
return &rtv1.ListTopicSubscriptionsResponse{
Subscriptions: []*rtv1.TopicSubscription{
{
PubsubName: "mypub",
Topic: "a",
Routes: &rtv1.TopicRoutes{
Default: "/a",
},
},
},
}, nil
}),
)
b.daprd = daprd.New(t,
daprd.WithAppPort(b.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
`))
return []framework.Option{
framework.WithProcesses(b.sub, b.daprd),
}
}
func (b *basic) Run(t *testing.T, ctx context.Context) {
b.daprd.WaitUntilRunning(t, ctx)
client := b.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
resp := b.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.JSONEq(t, `{"status": "completed"}`, string(resp.GetData()))
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a",
Data: []byte(`{"status": "completed"}`), DataContentType: "foo/bar",
})
require.NoError(t, err)
resp = b.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Empty(t, resp.GetData())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
assert.Equal(t, "foo/bar", resp.GetDataContentType())
_, err = client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte("foo"),
})
require.NoError(t, err)
resp = b.sub.Receive(t, ctx)
assert.Equal(t, "/a", resp.GetPath())
assert.Equal(t, "foo", string(resp.GetData()))
assert.Equal(t, "text/plain", resp.GetDataContentType())
assert.Equal(t, "1.0", resp.GetSpecVersion())
assert.Equal(t, "mypub", resp.GetPubsubName())
assert.Equal(t, "com.dapr.event.sent", resp.GetType())
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/programmatic/grpc/basic.go
|
GO
|
mit
| 3,577 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/emptypb"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/subscriber"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(bulk))
}
type bulk struct {
daprd *daprd.Daprd
sub *subscriber.Subscriber
}
func (b *bulk) Setup(t *testing.T) []framework.Option {
b.sub = subscriber.New(t,
subscriber.WithListTopicSubscriptions(func(context.Context, *emptypb.Empty) (*rtv1.ListTopicSubscriptionsResponse, error) {
return &rtv1.ListTopicSubscriptionsResponse{
Subscriptions: []*rtv1.TopicSubscription{
{
PubsubName: "mypub",
Topic: "a",
Routes: &rtv1.TopicRoutes{
Default: "/a",
},
BulkSubscribe: &rtv1.BulkSubscribeConfig{
Enabled: true,
MaxMessagesCount: 100,
MaxAwaitDurationMs: 40,
},
},
{
PubsubName: "mypub",
Topic: "b",
Routes: &rtv1.TopicRoutes{
Default: "/b",
},
},
},
}, nil
}),
)
b.daprd = daprd.New(t,
daprd.WithAppPort(b.sub.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
`))
return []framework.Option{
framework.WithProcesses(b.sub, b.daprd),
}
}
func (b *bulk) Run(t *testing.T, ctx context.Context) {
b.daprd.WaitUntilRunning(t, ctx)
client := b.daprd.GRPCClient(t, ctx)
// TODO: @joshvanl: add support for bulk publish to in-memory pubsub.
resp, err := client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "a",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
b.sub.ReceiveBulk(t, ctx)
b.sub.ReceiveBulk(t, ctx)
b.sub.ReceiveBulk(t, ctx)
b.sub.ReceiveBulk(t, ctx)
b.sub.AssertBulkEventChanLen(t, 0)
resp, err = client.BulkPublishEventAlpha1(ctx, &rtv1.BulkPublishRequest{
PubsubName: "mypub",
Topic: "b",
Entries: []*rtv1.BulkPublishRequestEntry{
{EntryId: "1", Event: []byte(`{"id": 1}`), ContentType: "application/json"},
{EntryId: "2", Event: []byte(`{"id": 2}`), ContentType: "application/json"},
{EntryId: "3", Event: []byte(`{"id": 3}`), ContentType: "application/json"},
{EntryId: "4", Event: []byte(`{"id": 4}`), ContentType: "application/json"},
},
})
require.NoError(t, err)
assert.Empty(t, len(resp.GetFailedEntries()))
b.sub.AssertBulkEventChanLen(t, 0)
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/programmatic/grpc/bulk.go
|
GO
|
mit
| 3,710 |
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package grpc
import (
"context"
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/emptypb"
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/grpc/app"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(deadletter))
}
type deadletter struct {
daprd *daprd.Daprd
app *app.App
inCh chan *rtv1.TopicEventRequest
}
func (d *deadletter) Setup(t *testing.T) []framework.Option {
d.inCh = make(chan *rtv1.TopicEventRequest)
d.app = app.New(t,
app.WithListTopicSubscriptions(func(context.Context, *emptypb.Empty) (*rtv1.ListTopicSubscriptionsResponse, error) {
return &rtv1.ListTopicSubscriptionsResponse{
Subscriptions: []*rtv1.TopicSubscription{
{
PubsubName: "mypub",
Topic: "a",
Routes: &rtv1.TopicRoutes{
Default: "/a",
},
DeadLetterTopic: "mydead",
},
{
PubsubName: "mypub",
Topic: "mydead",
Routes: &rtv1.TopicRoutes{
Default: "/b",
},
DeadLetterTopic: "mydead",
},
},
}, nil
}),
app.WithOnTopicEventFn(func(ctx context.Context, in *rtv1.TopicEventRequest) (*rtv1.TopicEventResponse, error) {
if in.GetTopic() == "a" {
return nil, errors.New("my error")
}
d.inCh <- in
return new(rtv1.TopicEventResponse), nil
}),
)
d.daprd = daprd.New(t,
daprd.WithAppPort(d.app.Port(t)),
daprd.WithAppProtocol("grpc"),
daprd.WithResourceFiles(`apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: mypub
spec:
type: pubsub.in-memory
version: v1
`))
return []framework.Option{
framework.WithProcesses(d.app, d.daprd),
}
}
func (d *deadletter) Run(t *testing.T, ctx context.Context) {
d.daprd.WaitUntilRunning(t, ctx)
client := d.daprd.GRPCClient(t, ctx)
_, err := client.PublishEvent(ctx, &rtv1.PublishEventRequest{
PubsubName: "mypub", Topic: "a", Data: []byte(`{"status": "completed"}`),
Metadata: map[string]string{"foo": "bar"}, DataContentType: "application/json",
})
require.NoError(t, err)
ctx, cancel := context.WithTimeout(ctx, time.Second)
t.Cleanup(cancel)
select {
case <-ctx.Done():
assert.Fail(t, "timeout waiting for event")
case in := <-d.inCh:
assert.Equal(t, "mydead", in.GetTopic())
assert.Equal(t, "/b", in.GetPath())
}
}
|
mikeee/dapr
|
tests/integration/suite/daprd/subscriptions/programmatic/grpc/deadletter.go
|
GO
|
mit
| 3,101 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.