@@ -19,13 +19,10 @@ limitations under the License.
1919package standalone_test
2020
2121import (
22- "fmt"
2322 "os"
2423 "path/filepath"
2524 "testing"
2625
27- "github.com/dapr/cli/tests/e2e/common"
28- "github.com/dapr/cli/tests/e2e/spawn"
2926 "github.com/dapr/cli/utils"
3027 "github.com/stretchr/testify/assert"
3128 "github.com/stretchr/testify/require"
@@ -46,28 +43,23 @@ func TestCompToResrcDirMig(t *testing.T) {
4643 // Ensure a clean environment.
4744 must (t , cmdUninstall , "failed to uninstall Dapr" )
4845
49- // install dapr.
46+ // install dapr -> installs dapr, creates resources dir and symlink components dir .
5047 ensureDaprInstallation (t )
5148
52- // rename resources to components dir.
53- renameResourcesDir (t )
54-
55- // dapr run should work with only components dir.
56- // 2nd parameter is true to indicate that only components dir is present.
57- checkDaprRunPrecedenceTest (t , true )
58-
59- // dapr uninstall without --all flag should work.
60- uninstallWithoutAllFlag (t )
61-
62- // dapr init should duplicate files from components dir to resources dir.
63- initTest (t )
49+ // check dapr run -> should not load in-memory component.
50+ checkDaprRunPrecedenceTest (t , false )
6451
6552 // copy a in memomy state store component to resources dir.
6653 copyInMemStateStore (t )
6754
68- // check dapr run precedence order, resources dir 1st then components dir.
69- // 2nd parameter is false to indicate that both components and resources dir are present.
70- checkDaprRunPrecedenceTest (t , false )
55+ // check dapr run -> should load in-memory component.
56+ checkDaprRunPrecedenceTest (t , true )
57+
58+ // dapr run with --components-path flag -> should load in-memory component.
59+ checkDaprRunPrecedenceTest (t , true , "--components-path" , defaultComponentsDirPath )
60+
61+ // dapr run with --resources-path flag -> should load in-memory component.
62+ checkDaprRunPrecedenceTest (t , true , "--resources-path" , defaultResourcesDirPath )
7163}
7264
7365func copyInMemStateStore (t * testing.T ) {
@@ -78,59 +70,20 @@ func copyInMemStateStore(t *testing.T) {
7870 assert .NoError (t , err , "cannot write testdata/resources/test-statestore.yaml file to resources directory" )
7971}
8072
81- func initTest (t * testing.T ) {
82- daprRuntimeVersion , _ := common .GetVersionsFromEnv (t , false )
83-
84- output , err := cmdInit (daprRuntimeVersion )
85- t .Log (output )
86- require .NoError (t , err , "init failed" )
87- assert .Contains (t , output , "Success! Dapr is up and running." )
88-
89- homeDir , err := os .UserHomeDir ()
90- require .NoError (t , err , "failed to get user home directory" )
91-
92- daprPath := filepath .Join (homeDir , ".dapr" )
93- require .DirExists (t , daprPath , "Directory %s does not exist" , daprPath )
94- require .DirExists (t , defaultComponentsDirPath , "Components dir does not exist" )
95- require .DirExists (t , defaultResourcesDirPath , "Resources dir does not exist" )
96- }
97-
98- func checkDaprRunPrecedenceTest (t * testing.T , onlyCompDirPresent bool ) {
73+ func checkDaprRunPrecedenceTest (t * testing.T , inMemoryCompPresent bool , flags ... string ) {
9974 args := []string {
10075 "--app-id" , "testapp" ,
10176 "--" , "bash" , "-c" , "echo 'test'" ,
10277 }
78+ args = append (args , flags ... )
10379 output , err := cmdRun ("" , args ... )
10480 t .Log (output )
10581 require .NoError (t , err , "run failed" )
106- if onlyCompDirPresent {
107- assert .NotContains (t , output , "component loaded. name: test-statestore, type: state.in-memory/v1" )
108- } else {
82+ if inMemoryCompPresent {
10983 assert .Contains (t , output , "component loaded. name: test-statestore, type: state.in-memory/v1" )
84+ } else {
85+ assert .NotContains (t , output , "component loaded. name: test-statestore, type: state.in-memory/v1" )
11086 }
11187 assert .Contains (t , output , "Exited App successfully" )
11288 assert .Contains (t , output , "Exited Dapr successfully" )
11389}
114-
115- func uninstallWithoutAllFlag (t * testing.T ) {
116- uninstallArgs := []string {"uninstall" }
117- daprContainerRuntime := containerRuntime ()
118-
119- // Add --container-runtime flag only if daprContainerRuntime is not empty, or overridden via args.
120- // This is only valid for non-slim mode.
121- if ! isSlimMode () && daprContainerRuntime != "" {
122- uninstallArgs = append (uninstallArgs , "--container-runtime" , daprContainerRuntime )
123- }
124- _ , error := spawn .Command (common .GetDaprPath (), uninstallArgs ... )
125- if error != nil {
126- assert .NoError (t , error , "failed to uninstall Dapr" )
127- }
128- }
129-
130- func renameResourcesDir (t * testing.T ) {
131- err := os .Rename (defaultResourcesDirPath , defaultComponentsDirPath )
132- if err != nil {
133- mesg := fmt .Sprintf ("pre-req to TestCompToResrcDirMig failed. error renaming components dir to resources dir: %s" , err )
134- assert .NoError (t , err , mesg )
135- }
136- }
0 commit comments