Skip to content

Commit d26894e

Browse files
JoshVanLdapr-bot
andauthored
Test Integration: Component checks with scopes (dapr#7597)
Adds Hot Reloading integration test to ensure that the Hot Reloading reconciler correctly updates/creates/deletes Components when they have scopes defined. Signed-off-by: joshvanl <[email protected]> Co-authored-by: Dapr Bot <[email protected]>
1 parent b3c6fc5 commit d26894e

File tree

1 file changed

+147
-0
lines changed
  • tests/integration/suite/daprd/hotreload/selfhosted

1 file changed

+147
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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 implieh.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package selfhosted
15+
16+
import (
17+
"context"
18+
"fmt"
19+
"os"
20+
"path/filepath"
21+
"testing"
22+
"time"
23+
24+
"github.com/stretchr/testify/assert"
25+
"github.com/stretchr/testify/require"
26+
27+
"github.com/dapr/dapr/tests/integration/framework"
28+
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
29+
"github.com/dapr/dapr/tests/integration/framework/util"
30+
"github.com/dapr/dapr/tests/integration/suite"
31+
)
32+
33+
func init() {
34+
suite.Register(new(scopes))
35+
}
36+
37+
type scopes struct {
38+
daprd *daprd.Daprd
39+
40+
resDir string
41+
}
42+
43+
func (s *scopes) Setup(t *testing.T) []framework.Option {
44+
configFile := filepath.Join(t.TempDir(), "config.yaml")
45+
require.NoError(t, os.WriteFile(configFile, []byte(`
46+
apiVersion: dapr.io/v1alpha1
47+
kind: Configuration
48+
metadata:
49+
name: hotreloading
50+
spec:
51+
features:
52+
- name: HotReload
53+
enabled: true
54+
`), 0o600))
55+
56+
s.resDir = t.TempDir()
57+
58+
s.daprd = daprd.New(t,
59+
daprd.WithConfigs(configFile),
60+
daprd.WithResourcesDir(s.resDir),
61+
)
62+
63+
return []framework.Option{
64+
framework.WithProcesses(s.daprd),
65+
}
66+
}
67+
68+
func (s *scopes) Run(t *testing.T, ctx context.Context) {
69+
s.daprd.WaitUntilRunning(t, ctx)
70+
71+
client := util.HTTPClient(t)
72+
73+
assert.Empty(t, util.GetMetaComponents(t, ctx, client, s.daprd.HTTPPort()))
74+
75+
require.NoError(t, os.WriteFile(filepath.Join(s.resDir, "1.yaml"), []byte(`
76+
apiVersion: dapr.io/v1alpha1
77+
kind: Component
78+
metadata:
79+
name: '123'
80+
spec:
81+
type: state.in-memory
82+
version: v1
83+
`), 0o600))
84+
require.EventuallyWithT(t, func(c *assert.CollectT) {
85+
assert.Len(c, util.GetMetaComponents(c, ctx, client, s.daprd.HTTPPort()), 1)
86+
}, time.Second*5, time.Millisecond*10)
87+
88+
require.NoError(t, os.WriteFile(filepath.Join(s.resDir, "1.yaml"), []byte(`
89+
apiVersion: dapr.io/v1alpha1
90+
kind: Component
91+
metadata:
92+
name: '123'
93+
spec:
94+
type: state.in-memory
95+
version: v1
96+
scopes:
97+
- not-my-app-id
98+
`), 0o600))
99+
require.EventuallyWithT(t, func(c *assert.CollectT) {
100+
assert.Empty(c, util.GetMetaComponents(c, ctx, client, s.daprd.HTTPPort()))
101+
}, time.Second*5, time.Millisecond*10)
102+
103+
require.NoError(t, os.WriteFile(filepath.Join(s.resDir, "1.yaml"), []byte(
104+
fmt.Sprintf(`
105+
apiVersion: dapr.io/v1alpha1
106+
kind: Component
107+
metadata:
108+
name: '123'
109+
spec:
110+
type: state.in-memory
111+
version: v1
112+
scopes:
113+
- not-my-app-id
114+
- '%s'
115+
`, s.daprd.AppID())), 0o600))
116+
require.EventuallyWithT(t, func(c *assert.CollectT) {
117+
assert.Len(c, util.GetMetaComponents(c, ctx, client, s.daprd.HTTPPort()), 1)
118+
}, time.Second*5, time.Millisecond*10)
119+
120+
require.NoError(t, os.WriteFile(filepath.Join(s.resDir, "1.yaml"), []byte(`
121+
apiVersion: dapr.io/v1alpha1
122+
kind: Component
123+
metadata:
124+
name: '123'
125+
spec:
126+
type: state.in-memory
127+
version: v1
128+
scopes:
129+
- not-my-app-id
130+
`), 0o600))
131+
require.EventuallyWithT(t, func(c *assert.CollectT) {
132+
assert.Empty(c, util.GetMetaComponents(c, ctx, client, s.daprd.HTTPPort()))
133+
}, time.Second*5, time.Millisecond*10)
134+
135+
require.NoError(t, os.WriteFile(filepath.Join(s.resDir, "1.yaml"), []byte(`
136+
apiVersion: dapr.io/v1alpha1
137+
kind: Component
138+
metadata:
139+
name: '123'
140+
spec:
141+
type: state.in-memory
142+
version: v1
143+
`), 0o600))
144+
require.EventuallyWithT(t, func(c *assert.CollectT) {
145+
assert.Len(c, util.GetMetaComponents(c, ctx, client, s.daprd.HTTPPort()), 1)
146+
}, time.Second*5, time.Millisecond*10)
147+
}

0 commit comments

Comments
 (0)