@@ -14,6 +14,7 @@ import (
14
14
"github.com/rogpeppe/go-internal/testscript"
15
15
"github.com/stretchr/testify/require"
16
16
"go.jetpack.io/devbox/internal/boxcli"
17
+ "go.jetpack.io/devbox/internal/xdg"
17
18
)
18
19
19
20
func TestScripts (t * testing.T ) {
@@ -75,6 +76,34 @@ func getTestscriptParams(dir string) testscript.Params {
75
76
oldPath := env .Getenv ("PATH" )
76
77
newPath := strings .Split (oldPath , ":" )[0 ]
77
78
env .Setenv ("PATH" , newPath )
79
+
80
+ // Both devbox itself and nix occasionally create some files in
81
+ // XDG_CACHE_HOME (which defaults to ~/.cache). For purposes of this
82
+ // test set it to a location within the test's working directory:
83
+ cacheHome := filepath .Join (env .WorkDir , ".cache" )
84
+ env .Setenv ("XDG_CACHE_HOME" , cacheHome )
85
+ err := os .MkdirAll (cacheHome , 0755 ) // Ensure dir exists.
86
+ if err != nil {
87
+ return err
88
+ }
89
+
90
+ // There is one directory we do want to share across tests: nix's cache.
91
+ // Without it tests are very slow, and nix would end up re-downloading
92
+ // nixpkgs every time.
93
+ // Here we create a shared location for nix's cache, and symlink from
94
+ // the test's working directory.
95
+ err = os .MkdirAll (xdg .CacheSubpath ("devbox-tests/nix" ), 0755 ) // Ensure dir exists.
96
+ if err != nil {
97
+ return err
98
+ }
99
+ err = os .Symlink (xdg .CacheSubpath ("devbox-tests/nix" ), filepath .Join (cacheHome , "nix" ))
100
+ if err != nil {
101
+ return err
102
+ }
103
+
104
+ // Enable new `devbox run` so we can use it in tests. This is temporary,
105
+ // and should be removed once we enable this feature flag.
106
+ env .Setenv ("DEVBOX_FEATURE_STRICT_RUN" , "1" )
78
107
return nil
79
108
},
80
109
Cmds : map [string ]func (ts * testscript.TestScript , neg bool , args []string ){
0 commit comments