Skip to content

Commit a4c5f81

Browse files
committed
few more refactoring
Signed-off-by: Pravin Pushkar <[email protected]>
1 parent 15a894c commit a4c5f81

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func init() {
377377
RunCmd.Flags().StringVarP(&logLevel, "log-level", "", "info", "The log verbosity. Valid values are: debug, info, warn, error, fatal, or panic")
378378
RunCmd.Flags().IntVarP(&maxConcurrency, "app-max-concurrency", "", -1, "The concurrency level of the application, otherwise is unlimited")
379379
RunCmd.Flags().StringVarP(&protocol, "app-protocol", "P", "http", "The protocol (gRPC or HTTP) Dapr uses to talk to the application")
380-
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "d", standalone.DefaultResourcesDirPrecedence(), "The path for components directory")
380+
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "d", standalone.GetResourcesDir(), "The path for resources directory")
381381
RunCmd.Flags().StringVarP(&resourcesPath, "resources-path", "", "", "The path for resources directory")
382382
// TODO: Remove below line once the flag is removed in the future releases.
383383
// By marking this as deprecated, the flag will be hidden from the help menu, but will continue to work. It will show a warning message when used.

pkg/standalone/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ func DefaultResourcesDirPath() string {
5353
return path_filepath.Join(defaultDaprDirPath(), utils.DefaultResourcesDirName)
5454
}
5555

56-
// DefaultResourcesDirPrecedence returns the path to the resources directory if it exists, or otherwise the components directory.
57-
// TODO: Remove this function and use `DefaultResourcesDirPath` when `--components-path` flag is removed.
58-
func DefaultResourcesDirPrecedence() string {
56+
// GetResourcesDir returns the path to the resources directory if it exists, otherwise it returns the path of components directory.
57+
// TODO: Remove this function and replace all its usage with above defined `DefaultResourcesDirPath` when `--components-path` flag is removed.
58+
func GetResourcesDir() string {
5959
defaultResourcesDirPath := DefaultResourcesDirPath()
6060
if _, err := os.Stat(defaultResourcesDirPath); os.IsNotExist(err) {
6161
return DefaultComponentsDirPath()

pkg/standalone/run_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ func assertArgumentNotEqual(t *testing.T, key string, expectedValue string, args
5656
}
5757

5858
func setupRun(t *testing.T) {
59-
componentsDir := DefaultResourcesDirPath()
59+
resourcesDir := DefaultResourcesDirPath()
6060
configFile := DefaultConfigFilePath()
61-
err := os.MkdirAll(componentsDir, 0o700)
61+
err := os.MkdirAll(resourcesDir, 0o700)
6262
assert.Equal(t, nil, err, "Unable to setup components dir before running test")
6363
file, err := os.Create(configFile)
6464
file.Close()
@@ -87,7 +87,7 @@ func assertCommonArgs(t *testing.T, basicConfig *RunConfig, output *RunOutput) {
8787
assertArgumentEqual(t, "app-max-concurrency", "-1", output.DaprCMD.Args)
8888
assertArgumentEqual(t, "app-protocol", "http", output.DaprCMD.Args)
8989
assertArgumentEqual(t, "app-port", "3000", output.DaprCMD.Args)
90-
assertArgumentEqual(t, "components-path", DefaultResourcesDirPrecedence(), output.DaprCMD.Args)
90+
assertArgumentEqual(t, "components-path", GetResourcesDir(), output.DaprCMD.Args)
9191
assertArgumentEqual(t, "app-ssl", "", output.DaprCMD.Args)
9292
assertArgumentEqual(t, "metrics-port", "9001", output.DaprCMD.Args)
9393
assertArgumentEqual(t, "dapr-http-max-request-size", "-1", output.DaprCMD.Args)
@@ -148,7 +148,7 @@ func TestRun(t *testing.T) {
148148
EnableProfiling: false,
149149
ProfilePort: 9090,
150150
Protocol: "http",
151-
ComponentsPath: DefaultResourcesDirPrecedence(),
151+
ComponentsPath: GetResourcesDir(),
152152
AppSSL: true,
153153
MetricsPort: 9001,
154154
MaxRequestBodySize: -1,

pkg/standalone/standalone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ func createComponentsAndConfiguration(wg *sync.WaitGroup, errorChan chan<- error
664664
}
665665
var err error
666666

667-
// Make default components directory.
667+
// Make default resources directory.
668668
resourcesDir := DefaultResourcesDirPath()
669669

670670
err = createRedisPubSub(redisHost, resourcesDir)

tests/e2e/standalone/upgrade_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ limitations under the License.
1515
*/
1616

1717
// TODO: Remove the test file when `--components-path` flag is removed.
18-
1918
// This file contains tests for the migration of components directory to resources directory.
20-
// It covers the test flow for scenario when user does: (1) dapr uninstall (2) upgrades dapr cli (3) dapr init (4) dapr run.
2119
package standalone_test
2220

2321
import (
@@ -28,6 +26,7 @@ import (
2826

2927
"github.com/dapr/cli/tests/e2e/common"
3028
"github.com/dapr/cli/tests/e2e/spawn"
29+
"github.com/dapr/cli/utils"
3130
"github.com/stretchr/testify/assert"
3231
"github.com/stretchr/testify/require"
3332
)
@@ -38,11 +37,12 @@ var (
3837
defaultResourcesDirPath = ""
3938
)
4039

40+
// It covers the test flow for scenario when user does: (1) dapr uninstall (2) upgrades dapr cli (3) dapr init (4) dapr run.
4141
func TestCompToResrcDirMig(t *testing.T) {
4242
homeDir, err := os.UserHomeDir()
4343
assert.NoError(t, err, "cannot get user home directory")
44-
defaultComponentsDirPath = filepath.Join(homeDir, ".dapr", "components")
45-
defaultResourcesDirPath = filepath.Join(homeDir, ".dapr", "resources")
44+
defaultComponentsDirPath = filepath.Join(homeDir, ".dapr", utils.DefaultComponentsDirName)
45+
defaultResourcesDirPath = filepath.Join(homeDir, ".dapr", utils.DefaultResourcesDirName)
4646
// Ensure a clean environment.
4747
must(t, cmdUninstall, "failed to uninstall Dapr")
4848

0 commit comments

Comments
 (0)