Skip to content

Commit 1281e02

Browse files
authored
Integration Tests: Subscriptions (dapr#7578)
* Adds operator informer v1 and v2 tests Signed-off-by: joshvanl <[email protected]> * Adds more v1alpha1 operator sub tests Signed-off-by: joshvanl <[email protected]> * int test subs dec v1alpha1 scopes Signed-off-by: joshvanl <[email protected]> * Complete v1alpha1 scope tests Signed-off-by: joshvanl <[email protected]> * wip v2alpha1 operator Signed-off-by: joshvanl <[email protected]> * Wire up v2alpha1 declarative subscription tests Signed-off-by: joshvanl <[email protected]> * Adds grpc programmatic subscription tests Signed-off-by: joshvanl <[email protected]> * Adds tests/integration/suite/daprd/subscriptions/programmatic/http/v1alpha1 Signed-off-by: joshvanl <[email protected]> * linting Signed-off-by: joshvanl <[email protected]> * Changes `Subset` checks for `Contains` Signed-off-by: joshvanl <[email protected]> * Adds subscriptions/programmatic/http/v2alpha1 Signed-off-by: joshvanl <[email protected]> * Adds subscriptions/programmatic/http/mixed Signed-off-by: joshvanl <[email protected]> * Adds tests/integration/suite/daprd/subscriptions/declarative/selfhosted/mixed Signed-off-by: joshvanl <[email protected]> * Adds tests/integration/suite/daprd/subscriptions/mixed Signed-off-by: joshvanl <[email protected]> * Set correct control plane trust domain in subscription int tests Signed-off-by: joshvanl <[email protected]> --------- Signed-off-by: joshvanl <[email protected]>
1 parent 37bfe27 commit 1281e02

File tree

129 files changed

+15953
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+15953
-5
lines changed

tests/integration/framework/process/grpc/app/app.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ limitations under the License.
1414
package app
1515

1616
import (
17+
"context"
1718
"testing"
1819

1920
"google.golang.org/grpc"
@@ -27,7 +28,7 @@ type Option func(*options)
2728

2829
// App is a wrapper around a grpc.Server that implements a Dapr App.
2930
type App struct {
30-
*procgrpc.GRPC
31+
grpc *procgrpc.GRPC
3132
}
3233

3334
func New(t *testing.T, fopts ...Option) *App {
@@ -39,7 +40,7 @@ func New(t *testing.T, fopts ...Option) *App {
3940
}
4041

4142
return &App{
42-
GRPC: procgrpc.New(t, append(opts.grpcopts, procgrpc.WithRegister(func(s *grpc.Server) {
43+
grpc: procgrpc.New(t, append(opts.grpcopts, procgrpc.WithRegister(func(s *grpc.Server) {
4344
srv := &server{
4445
onInvokeFn: opts.onInvokeFn,
4546
onTopicEventFn: opts.onTopicEventFn,
@@ -58,3 +59,15 @@ func New(t *testing.T, fopts ...Option) *App {
5859
}))...),
5960
}
6061
}
62+
63+
func (a *App) Run(t *testing.T, ctx context.Context) {
64+
a.grpc.Run(t, ctx)
65+
}
66+
67+
func (a *App) Cleanup(t *testing.T) {
68+
a.grpc.Cleanup(t)
69+
}
70+
71+
func (a *App) Port(t *testing.T) int {
72+
return a.grpc.Port(t)
73+
}

tests/integration/framework/process/grpc/app/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424
procgrpc "github.com/dapr/dapr/tests/integration/framework/process/grpc"
2525
)
2626

27-
// options contains the options for running a GRPC server in integration tests.
27+
// options contains the options for running a GRPC server app in integration
28+
// tests.
2829
type options struct {
2930
grpcopts []procgrpc.Option
3031
withRegister func(s *grpc.Server)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2024 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package subscriber
15+
16+
type (
17+
SubscriptionJSON struct {
18+
PubsubName string `json:"pubsubname"`
19+
Topic string `json:"topic"`
20+
DeadLetterTopic string `json:"deadLetterTopic"`
21+
Metadata map[string]string `json:"metadata,omitempty"`
22+
Route string `json:"route"` // Single route from v1alpha1
23+
Routes RoutesJSON `json:"routes"` // Multiple routes from v2alpha1
24+
BulkSubscribe BulkSubscribeJSON `json:"bulkSubscribe,omitempty"`
25+
}
26+
27+
RoutesJSON struct {
28+
Rules []*RuleJSON `json:"rules,omitempty"`
29+
Default string `json:"default,omitempty"`
30+
}
31+
32+
BulkSubscribeJSON struct {
33+
Enabled bool `json:"enabled"`
34+
MaxMessagesCount int32 `json:"maxMessagesCount,omitempty"`
35+
MaxAwaitDurationMs int32 `json:"maxAwaitDurationMs,omitempty"`
36+
}
37+
38+
RuleJSON struct {
39+
Match string `json:"match"`
40+
Path string `json:"path"`
41+
}
42+
)

tests/integration/framework/process/http/subscriber/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type options struct {
2323
routes []string
2424
bulkRoutes []string
2525
handlerFuncs []app.Option
26+
progSubs *[]SubscriptionJSON
2627
}
2728

2829
func WithRoutes(routes ...string) Option {
@@ -42,3 +43,12 @@ func WithHandlerFunc(path string, fn http.HandlerFunc) Option {
4243
o.handlerFuncs = append(o.handlerFuncs, app.WithHandlerFunc(path, fn))
4344
}
4445
}
46+
47+
func WithProgrammaticSubscriptions(subs ...SubscriptionJSON) Option {
48+
return func(o *options) {
49+
if o.progSubs == nil {
50+
o.progSubs = new([]SubscriptionJSON)
51+
}
52+
*o.progSubs = append(*o.progSubs, subs...)
53+
}
54+
}

tests/integration/framework/process/http/subscriber/subscriber.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ func New(t *testing.T, fopts ...Option) *Subscriber {
119119
}))
120120
}
121121

122+
if opts.progSubs != nil {
123+
appOpts = append(appOpts, app.WithHandlerFunc("/dapr/subscribe", func(w http.ResponseWriter, r *http.Request) {
124+
require.NoError(t, json.NewEncoder(w).Encode(*opts.progSubs))
125+
}))
126+
}
127+
122128
appOpts = append(appOpts, opts.handlerFuncs...)
123129

124130
return &Subscriber{

tests/integration/framework/process/kubernetes/options.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import (
3131
configapi "github.com/dapr/dapr/pkg/apis/configuration/v1alpha1"
3232
httpendapi "github.com/dapr/dapr/pkg/apis/httpEndpoint/v1alpha1"
3333
resapi "github.com/dapr/dapr/pkg/apis/resiliency/v1alpha1"
34-
subapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
34+
subv1api "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1"
35+
subv2api "github.com/dapr/dapr/pkg/apis/subscriptions/v2alpha1"
3536
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes/store"
3637
)
3738

@@ -54,7 +55,17 @@ func WithClusterDaprResiliencyList(t *testing.T, res *resapi.ResiliencyList) Opt
5455
return handleClusterListResource(t, "/apis/dapr.io/v1alpha1/resiliencies", res)
5556
}
5657

57-
func WithClusterDaprSubscriptionList(t *testing.T, subs *subapi.SubscriptionList) Option {
58+
func WithClusterDaprSubscriptionList(t *testing.T, subs *subv1api.SubscriptionList) Option {
59+
subv2List := new(subv2api.SubscriptionList)
60+
for _, s := range subs.Items {
61+
subv2 := new(subv2api.Subscription)
62+
require.NoError(t, subv2.ConvertFrom(s.DeepCopy()))
63+
subv2List.Items = append(subv2List.Items, *subv2)
64+
}
65+
return handleClusterListResource(t, "/apis/dapr.io/v2alpha1/subscriptions", subv2List)
66+
}
67+
68+
func WithClusterDaprSubscriptionListV2(t *testing.T, subs *subv2api.SubscriptionList) Option {
5869
return handleClusterListResource(t, "/apis/dapr.io/v2alpha1/subscriptions", subs)
5970
}
6071

@@ -66,6 +77,10 @@ func WithClusterDaprComponentListFromStore(t *testing.T, store *store.Store) Opt
6677
return handleClusterListResourceFromStore(t, "/apis/dapr.io/v1alpha1/components", store)
6778
}
6879

80+
func WithClusterDaprSubscriptionListFromStore(t *testing.T, store *store.Store) Option {
81+
return handleClusterListResourceFromStore(t, "/apis/dapr.io/v1alpha1/subscriptions", store)
82+
}
83+
6984
func WithClusterDaprHTTPEndpointList(t *testing.T, endpoints *httpendapi.HTTPEndpointList) Option {
7085
return handleClusterListResource(t, "/apis/dapr.io/v1alpha1/httpendpoints", endpoints)
7186
}

tests/integration/suite/daprd/daprd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ import (
3131
_ "github.com/dapr/dapr/tests/integration/suite/daprd/serviceinvocation"
3232
_ "github.com/dapr/dapr/tests/integration/suite/daprd/shutdown"
3333
_ "github.com/dapr/dapr/tests/integration/suite/daprd/state"
34+
_ "github.com/dapr/dapr/tests/integration/suite/daprd/subscriptions"
3435
_ "github.com/dapr/dapr/tests/integration/suite/daprd/workflow"
3536
)

tests/integration/suite/daprd/pubsub/pubsub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ import (
1717
_ "github.com/dapr/dapr/tests/integration/suite/daprd/pubsub/contentlength"
1818
_ "github.com/dapr/dapr/tests/integration/suite/daprd/pubsub/grpc"
1919
_ "github.com/dapr/dapr/tests/integration/suite/daprd/pubsub/http"
20+
_ "github.com/dapr/dapr/tests/integration/suite/daprd/pubsub/scopes"
2021
)

0 commit comments

Comments
 (0)