@@ -18,12 +18,16 @@ package standalone_test
18
18
19
19
import (
20
20
"context"
21
+ "net"
21
22
"os"
22
23
"path/filepath"
23
24
"runtime"
25
+ "strconv"
24
26
"strings"
25
27
"testing"
28
+ "time"
26
29
30
+ "github.com/Masterminds/semver"
27
31
"github.com/dapr/cli/tests/e2e/common"
28
32
"github.com/dapr/cli/tests/e2e/spawn"
29
33
"github.com/docker/docker/api/types"
@@ -157,6 +161,48 @@ func TestStandaloneInit(t *testing.T) {
157
161
verifyContainers (t , latestDaprRuntimeVersion )
158
162
verifyBinaries (t , daprPath , latestDaprRuntimeVersion , latestDaprDashboardVersion )
159
163
verifyConfigs (t , daprPath )
164
+
165
+ placementPort := 50005
166
+ if runtime .GOOS == "windows" {
167
+ placementPort = 6050
168
+ }
169
+
170
+ verifyTCPLocalhost (t , placementPort )
171
+ })
172
+
173
+ t .Run ("init version with scheduler" , func (t * testing.T ) {
174
+ // Ensure a clean environment
175
+ must (t , cmdUninstall , "failed to uninstall Dapr" )
176
+
177
+ args := []string {
178
+ "--runtime-version" , "1.14.0-rc.3" ,
179
+ "--dev" ,
180
+ }
181
+ output , err := cmdInit (args ... )
182
+ t .Log (output )
183
+ require .NoError (t , err , "init failed" )
184
+ assert .Contains (t , output , "Success! Dapr is up and running." )
185
+
186
+ homeDir , err := os .UserHomeDir ()
187
+ require .NoError (t , err , "failed to get user home directory" )
188
+
189
+ daprPath := filepath .Join (homeDir , ".dapr" )
190
+ require .DirExists (t , daprPath , "Directory %s does not exist" , daprPath )
191
+
192
+ _ , latestDaprDashboardVersion := common .GetVersionsFromEnv (t , true )
193
+ verifyContainers (t , "1.14.0-rc.3" )
194
+ verifyBinaries (t , daprPath , "1.14.0-rc.3" , latestDaprDashboardVersion )
195
+ verifyConfigs (t , daprPath )
196
+
197
+ placementPort := 50005
198
+ schedulerPort := 50006
199
+ if runtime .GOOS == "windows" {
200
+ placementPort = 6050
201
+ schedulerPort = 6060
202
+ }
203
+
204
+ verifyTCPLocalhost (t , placementPort )
205
+ verifyTCPLocalhost (t , schedulerPort )
160
206
})
161
207
162
208
t .Run ("init without runtime-version flag with mariner images" , func (t * testing.T ) {
@@ -187,10 +233,11 @@ func TestStandaloneInit(t *testing.T) {
187
233
// Note, in case of slim installation, the containers are not installed and
188
234
// this test is automatically skipped.
189
235
func verifyContainers (t * testing.T , daprRuntimeVersion string ) {
236
+ t .Helper ()
237
+
190
238
t .Run ("verifyContainers" , func (t * testing.T ) {
191
239
if isSlimMode () {
192
- t .Log ("Skipping container verification because of slim installation" )
193
- return
240
+ t .Skip ("Skipping container verification because of slim installation" )
194
241
}
195
242
196
243
cli , err := dockerClient .NewClientWithOpts (dockerClient .FromEnv )
@@ -205,6 +252,12 @@ func verifyContainers(t *testing.T, daprRuntimeVersion string) {
205
252
"dapr_redis" : "" ,
206
253
}
207
254
255
+ v , err := semver .NewVersion (daprRuntimeVersion )
256
+ require .NoError (t , err )
257
+ if v .Major () >= 1 && v .Minor () >= 14 {
258
+ daprContainers ["dapr_scheduler" ] = daprRuntimeVersion
259
+ }
260
+
208
261
for _ , container := range containers {
209
262
t .Logf ("Found container: %v %s %s\n " , container .Names , container .Image , container .State )
210
263
if container .State != "running" {
@@ -233,6 +286,8 @@ func verifyContainers(t *testing.T, daprRuntimeVersion string) {
233
286
234
287
// verifyBinaries ensures that the correct binaries are present in the correct path.
235
288
func verifyBinaries (t * testing.T , daprPath , runtimeVersion , dashboardVersion string ) {
289
+ t .Helper ()
290
+
236
291
binPath := filepath .Join (daprPath , "bin" )
237
292
require .DirExists (t , binPath , "Directory %s does not exist" , binPath )
238
293
@@ -247,6 +302,8 @@ func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion str
247
302
248
303
for bin , version := range binaries {
249
304
t .Run ("verifyBinaries/" + bin , func (t * testing.T ) {
305
+ t .Helper ()
306
+
250
307
file := filepath .Join (binPath , bin )
251
308
if runtime .GOOS == "windows" {
252
309
file += ".exe"
@@ -265,6 +322,8 @@ func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion str
265
322
// verifyConfigs ensures that the Dapr configuration and component YAMLs
266
323
// are present in the correct path and have the correct values.
267
324
func verifyConfigs (t * testing.T , daprPath string ) {
325
+ t .Helper ()
326
+
268
327
configSpec := map [interface {}]interface {}{}
269
328
// tracing is not enabled in slim mode by default.
270
329
if ! isSlimMode () {
@@ -353,3 +412,22 @@ func verifyConfigs(t *testing.T, daprPath string) {
353
412
})
354
413
}
355
414
}
415
+
416
+ // verifyTCPLocalhost verifies a given localhost TCP port is being listened to.
417
+ func verifyTCPLocalhost (t * testing.T , port int ) {
418
+ t .Helper ()
419
+
420
+ if isSlimMode () {
421
+ t .Skip ("Skipping container verification because of slim installation" )
422
+ }
423
+
424
+ // Check that the server is up and can accept connections.
425
+ endpoint := "127.0.0.1:" + strconv .Itoa (port )
426
+ assert .EventuallyWithT (t , func (c * assert.CollectT ) {
427
+ conn , err := net .Dial ("tcp" , endpoint )
428
+ //nolint:testifylint
429
+ if assert .NoError (c , err ) {
430
+ conn .Close ()
431
+ }
432
+ }, time .Second * 10 , time .Millisecond * 10 )
433
+ }
0 commit comments