Skip to content

Commit e7ccf04

Browse files
committed
fix tests
Signed-off-by: Pravin Pushkar <[email protected]>
1 parent f73af11 commit e7ccf04

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

tests/e2e/standalone/commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ func cmdStop(appId string, args ...string) (string, error) {
122122
func cmdUninstallAll(args ...string) (string, error) {
123123
uninstallArgs := []string{"uninstall", "--all"}
124124
uninstallArgs = append(uninstallArgs, args...)
125-
return uninstallDapr(uninstallArgs)
125+
return uninstallDapr(uninstallArgs...)
126126
}
127127

128128
// cmdUninstall uninstalls Dapr without --all flag and returns the command output and error.
129129
func cmdUninstall(args ...string) (string, error) {
130130
uninstallArgs := []string{"uninstall"}
131131
uninstallArgs = append(uninstallArgs, args...)
132-
return uninstallDapr(uninstallArgs)
132+
return uninstallDapr(uninstallArgs...)
133133
}
134134

135135
// cmdVersion checks the version of Dapr and returns the command output and error.

tests/e2e/standalone/upgrade_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919
package standalone_test
2020

2121
import (
22+
"fmt"
2223
"os"
2324
"path/filepath"
2425
"testing"
@@ -65,11 +66,11 @@ func TestResourcesLoadPrecedence(t *testing.T) {
6566

6667
// dapr run with both flags --resources-path and --components-path.
6768
args := []string{
68-
"--components-path", defaultComponentsDirPath,
69-
"--resources-path", defaultResourcesDirPath
69+
"--components-path", defaultComponentsDirPath,
70+
"--resources-path", defaultResourcesDirPath,
7071
}
7172
testDaprRunOutput(t, true, args...)
72-
}
73+
})
7374

7475
t.Run("with pre-existing components directory", func(t *testing.T) {
7576
// Ensure a clean environment.
@@ -87,7 +88,7 @@ func TestResourcesLoadPrecedence(t *testing.T) {
8788
// uninstall without removing the components directory.
8889
must(t, cmdUninstall, "failed to uninstall Dapr")
8990

90-
// install dapr -> installs dapr. It does following -
91+
// install dapr -> installs dapr. It does following -
9192
// 1) creates resources directory. 2)copy resources from components to resources directory.
9293
// 3) delete components directory. 4) creates symlink components for resources directory.
9394
ensureDaprInstallation(t)
@@ -100,7 +101,7 @@ func TestResourcesLoadPrecedence(t *testing.T) {
100101

101102
// dapr run with --resources-path flag -> should also load the in-memory component.
102103
testDaprRunOutput(t, true, "--resources-path", defaultResourcesDirPath)
103-
}
104+
})
104105

105106
t.Run("add resources to components directory post dapr install", func(t *testing.T) {
106107
// Ensure a clean environment.
@@ -123,7 +124,7 @@ func TestResourcesLoadPrecedence(t *testing.T) {
123124

124125
// dapr run with --resources-path flag -> should also load the in-memory component.
125126
testDaprRunOutput(t, true, "--resources-path", defaultResourcesDirPath)
126-
}
127+
})
127128
}
128129

129130
func prepareComponentsDir(t *testing.T) {

tests/e2e/standalone/utils.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,27 @@ func executeAgainstRunningDapr(t *testing.T, f func(), daprArgs ...string) {
127127
// ensureDaprInstallation ensures that Dapr is installed.
128128
// If Dapr is not installed, a new installation is attempted.
129129
func ensureDaprInstallation(t *testing.T) {
130-
daprRuntimeVersion, _ := common.GetVersionsFromEnv(t, false)
131130
homeDir, err := os.UserHomeDir()
132131
require.NoError(t, err, "failed to get user home directory")
133132

134133
daprPath := filepath.Join(homeDir, ".dapr")
135-
_, err = os.Stat(daprPath)
136-
if os.IsNotExist(err) {
137-
args := []string{
138-
"--runtime-version", daprRuntimeVersion,
134+
if _, err = os.Stat(daprPath); err != nil {
135+
if os.IsNotExist(err) {
136+
installDapr(t)
137+
} else {
138+
// Some other error occurred.
139+
require.NoError(t, err, "failed to stat dapr installation")
140+
}
141+
}
142+
daprBinPath := filepath.Join(daprPath, "bin")
143+
if _, err = os.Stat(daprBinPath); err != nil {
144+
if os.IsNotExist(err) {
145+
installDapr(t)
146+
} else {
147+
// Some other error occurred.
148+
require.NoError(t, err, "failed to stat dapr installation")
139149
}
140-
_, err = cmdInit(args...)
141-
require.NoError(t, err, "failed to install dapr")
142-
} else if err != nil {
143-
// Some other error occurred.
144-
require.NoError(t, err, "failed to stat dapr installation")
145150
}
146-
147151
// Slim mode does not have any resources by default.
148152
// Install the resources required by the tests.
149153
if isSlimMode() {
@@ -159,6 +163,15 @@ func containerRuntime() string {
159163
return ""
160164
}
161165

166+
func installDapr(t *testing.T) {
167+
daprRuntimeVersion, _ := common.GetVersionsFromEnv(t, false)
168+
args := []string{
169+
"--runtime-version", daprRuntimeVersion,
170+
}
171+
_, err := cmdInit(args...)
172+
require.NoError(t, err, "failed to install dapr")
173+
}
174+
162175
func uninstallDapr(uninstallArgs ...string) (string, error) {
163176
daprContainerRuntime := containerRuntime()
164177

0 commit comments

Comments
 (0)