-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathbase_path_resolution_test.go
More file actions
570 lines (469 loc) · 19.8 KB
/
base_path_resolution_test.go
File metadata and controls
570 lines (469 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
package config
import (
"errors"
"os"
"path/filepath"
"testing"
errUtils "github.com/cloudposse/atmos/errors"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestInitCliConfig_ExplicitBasePath_DotSlash_ResolvesRelativeToCWD verifies that when
// AtmosBasePath uses a dot-slash prefix (e.g., "./.terraform/modules/monorepo"), it resolves
// relative to CWD. This is Tyler's scenario: the dot-slash explicitly anchors to CWD.
func TestInitCliConfig_ExplicitBasePath_DotSlash_ResolvesRelativeToCWD(t *testing.T) {
// Create a temp directory to simulate a project layout.
tmpDir := t.TempDir()
// Resolve symlinks (macOS /var -> /private/var).
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
// Create a subdirectory to simulate CWD being different from project root.
subDir := filepath.Join(tmpDir, "components", "terraform", "vpc")
require.NoError(t, os.MkdirAll(subDir, 0o755))
// Create a relative base path target with dot-slash prefix.
relBasePath := filepath.Join(".", ".terraform", "modules", "monorepo")
absTarget := filepath.Join(subDir, ".terraform", "modules", "monorepo")
require.NoError(t, os.MkdirAll(absTarget, 0o755))
// Create minimal atmos.yaml in the target.
atmosYaml := filepath.Join(absTarget, "atmos.yaml")
require.NoError(t, os.WriteFile(atmosYaml, []byte("base_path: ./\nstacks:\n base_path: stacks\n"), 0o644))
// Create stacks directory so config loading doesn't fail.
require.NoError(t, os.MkdirAll(filepath.Join(absTarget, "stacks"), 0o755))
// Change to the subdirectory (simulating terraform-provider-utils context).
t.Chdir(subDir)
// Provide AtmosBasePath with dot-slash prefix — this is a runtime source.
configAndStacksInfo := schema.ConfigAndStacksInfo{
AtmosBasePath: relBasePath,
}
atmosConfig, err := InitCliConfig(configAndStacksInfo, false)
require.NoError(t, err)
// The base path should resolve to CWD + relative path (dot-slash = CWD anchor).
assert.True(t, filepath.IsAbs(atmosConfig.BasePathAbsolute),
"BasePathAbsolute should be absolute, got: %s", atmosConfig.BasePathAbsolute)
assert.Equal(t, absTarget, atmosConfig.BasePathAbsolute,
"Dot-slash AtmosBasePath should resolve relative to CWD, not config dir")
}
// TestInitCliConfig_ExplicitBasePath_AbsolutePassedThrough verifies that an absolute
// AtmosBasePath is passed through without modification.
func TestInitCliConfig_ExplicitBasePath_AbsolutePassedThrough(t *testing.T) {
tmpDir := t.TempDir()
// Resolve symlinks (macOS /var -> /private/var).
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
// Create minimal atmos.yaml.
require.NoError(t, os.WriteFile(
filepath.Join(tmpDir, "atmos.yaml"),
[]byte("base_path: ./\nstacks:\n base_path: stacks\n"),
0o644,
))
require.NoError(t, os.MkdirAll(filepath.Join(tmpDir, "stacks"), 0o755))
configAndStacksInfo := schema.ConfigAndStacksInfo{
AtmosBasePath: tmpDir,
}
atmosConfig, err := InitCliConfig(configAndStacksInfo, false)
require.NoError(t, err)
assert.Equal(t, tmpDir, atmosConfig.BasePath,
"Absolute AtmosBasePath should be used as-is")
}
// TestInitCliConfig_EmptyBasePath_DefaultsToAbsolute verifies that when AtmosBasePath is empty,
// the default resolution produces an absolute path.
func TestInitCliConfig_EmptyBasePath_DefaultsToAbsolute(t *testing.T) {
configAndStacksInfo := schema.ConfigAndStacksInfo{
AtmosBasePath: "",
}
// InitCliConfig with processStacks=false — BasePath gets populated by AtmosConfigAbsolutePaths.
atmosConfig, err := InitCliConfig(configAndStacksInfo, false)
require.NoError(t, err)
// After AtmosConfigAbsolutePaths, BasePath should be absolute (from git root, config dir, or CWD).
if atmosConfig.BasePath != "" {
assert.True(t, filepath.IsAbs(atmosConfig.BasePath),
"Default BasePath should be absolute, got: %s", atmosConfig.BasePath)
}
}
// TestInitCliConfig_EnvVarBasePath_DotSlash_ResolvesRelativeToCWD verifies that when
// ATMOS_BASE_PATH is set with a dot-slash prefix, it resolves relative to CWD.
// This is Tyler's scenario: ATMOS_BASE_PATH=./.terraform/modules/monorepo on Spacelift.
func TestInitCliConfig_EnvVarBasePath_DotSlash_ResolvesRelativeToCWD(t *testing.T) {
tmpDir := t.TempDir()
// Resolve symlinks (macOS /var -> /private/var).
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
// Create a subdirectory to simulate CWD being a component directory.
subDir := filepath.Join(tmpDir, "components", "terraform", "iam-delegated-roles")
require.NoError(t, os.MkdirAll(subDir, 0o755))
// Create the relative base path target with dot-slash prefix.
relBasePath := filepath.Join(".", ".terraform", "modules", "monorepo")
absTarget := filepath.Join(subDir, ".terraform", "modules", "monorepo")
require.NoError(t, os.MkdirAll(absTarget, 0o755))
// Create minimal atmos.yaml in the target.
require.NoError(t, os.WriteFile(
filepath.Join(absTarget, "atmos.yaml"),
[]byte("base_path: ./\nstacks:\n base_path: stacks\n"),
0o644,
))
require.NoError(t, os.MkdirAll(filepath.Join(absTarget, "stacks"), 0o755))
// Change to the component directory.
t.Chdir(subDir)
// Set ATMOS_BASE_PATH with dot-slash prefix (Tyler's fix).
// Resolves to CWD (not config dir). In shell context, "." means "here" is CWD.
t.Setenv("ATMOS_BASE_PATH", relBasePath)
// No AtmosBasePath in struct — the env var is the source.
configAndStacksInfo := schema.ConfigAndStacksInfo{}
atmosConfig, err := InitCliConfig(configAndStacksInfo, false)
require.NoError(t, err)
// After AtmosConfigAbsolutePaths, BasePathAbsolute should resolve to CWD + relBasePath.
assert.True(t, filepath.IsAbs(atmosConfig.BasePathAbsolute),
"BasePathAbsolute should be absolute, got: %s", atmosConfig.BasePathAbsolute)
assert.Equal(t, absTarget, atmosConfig.BasePathAbsolute,
"ATMOS_BASE_PATH env var with dot-slash should resolve relative to CWD")
}
// TestInitCliConfig_EnvVarBasePath_Dot_ResolvesToCWD verifies that ATMOS_BASE_PATH=.
// Resolves to CWD (not config dir). In shell context, "." means "here" is CWD.
func TestInitCliConfig_EnvVarBasePath_Dot_ResolvesToCWD(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
// Create project layout: config in one dir, CWD in another.
configDir := filepath.Join(tmpDir, "config")
cwdDir := filepath.Join(tmpDir, "workdir")
require.NoError(t, os.MkdirAll(configDir, 0o755))
require.NoError(t, os.MkdirAll(cwdDir, 0o755))
// Create atmos.yaml in configDir.
require.NoError(t, os.WriteFile(
filepath.Join(configDir, "atmos.yaml"),
[]byte("base_path: ./\nstacks:\n base_path: stacks\n"),
0o644,
))
require.NoError(t, os.MkdirAll(filepath.Join(cwdDir, "stacks"), 0o755))
t.Chdir(cwdDir)
t.Setenv("ATMOS_CLI_CONFIG_PATH", configDir)
t.Setenv("ATMOS_BASE_PATH", ".")
t.Setenv("ATMOS_GIT_ROOT_BASEPATH", "false")
atmosConfig, err := InitCliConfig(schema.ConfigAndStacksInfo{}, false)
require.NoError(t, err)
// ATMOS_BASE_PATH=. in shell context should resolve to CWD, not config dir.
assert.Equal(t, cwdDir, atmosConfig.BasePathAbsolute,
"ATMOS_BASE_PATH=. should resolve to CWD (shell convention), not config dir")
}
// TestResolveAbsolutePath_DotPrefix_SourceAware verifies that dot-prefixed paths
// resolve differently based on source: config → config dir, runtime → CWD.
func TestResolveAbsolutePath_DotPrefix_SourceAware(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
configDir := filepath.Join(tmpDir, "config")
cwdDir := filepath.Join(tmpDir, "workdir")
require.NoError(t, os.MkdirAll(configDir, 0o755))
require.NoError(t, os.MkdirAll(cwdDir, 0o755))
t.Chdir(cwdDir)
tests := []struct {
name string
path string
source string
expected string
}{
{
name: "dot from config resolves to config dir",
path: ".",
source: "",
expected: configDir,
},
{
name: "dot from runtime resolves to CWD",
path: ".",
source: "runtime",
expected: cwdDir,
},
{
name: "dot-slash-foo from config resolves to config dir",
path: "./foo",
source: "",
expected: filepath.Join(configDir, "foo"),
},
{
name: "dot-slash-foo from runtime resolves to CWD",
path: "./foo",
source: "runtime",
expected: filepath.Join(cwdDir, "foo"),
},
{
name: "dot-dot from config resolves relative to config dir",
path: "..",
source: "",
expected: tmpDir,
},
{
name: "dot-dot from runtime resolves relative to CWD",
path: "..",
source: "runtime",
expected: tmpDir,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := resolveAbsolutePath(tt.path, configDir, tt.source)
require.NoError(t, err)
assert.Equal(t, tt.expected, result)
})
}
}
// TestResolveAbsolutePath_BarePath_SourceIndependent verifies that bare paths
// (no dot prefix) go through the same git root search regardless of source.
func TestResolveAbsolutePath_BarePath_SourceIndependent(t *testing.T) {
gitRoot := getGitRootOrEmpty()
require.NotEmpty(t, gitRoot, "test requires git root discovery")
// "go.mod" exists at git root — bare path should find it regardless of source.
_, err := os.Stat(filepath.Join(gitRoot, "go.mod"))
require.NoError(t, err)
t.Chdir(filepath.Join(gitRoot, "pkg", "config"))
configResult, err := resolveAbsolutePath("go.mod", "", "")
require.NoError(t, err)
runtimeResult, err := resolveAbsolutePath("go.mod", "", "runtime")
require.NoError(t, err)
// Both should resolve to git root — bare paths are source-independent.
assert.Equal(t, filepath.Join(gitRoot, "go.mod"), configResult,
"bare path from config should resolve via git root")
assert.Equal(t, filepath.Join(gitRoot, "go.mod"), runtimeResult,
"bare path from runtime should resolve via git root (same as config)")
assert.Equal(t, configResult, runtimeResult,
"bare paths must resolve identically regardless of source")
}
// TestTryResolveWithGitRoot_ExistingPathAtGitRoot verifies that when a simple relative path
// exists at the git root, resolveAbsolutePath returns the git-root-joined path.
func TestTryResolveWithGitRoot_ExistingPathAtGitRoot(t *testing.T) {
gitRoot := getGitRootOrEmpty()
require.NotEmpty(t, gitRoot, "test requires git root discovery")
pathAtGitRoot := "go.mod"
_, err := os.Stat(filepath.Join(gitRoot, pathAtGitRoot))
require.NoError(t, err)
t.Chdir(filepath.Join(gitRoot, "pkg", "config"))
resolved, err := resolveAbsolutePath(pathAtGitRoot, "", "")
require.NoError(t, err)
assert.Equal(t, filepath.Join(gitRoot, pathAtGitRoot), resolved)
}
// TestTryResolveWithGitRoot_CWDFallback verifies that when a simple relative path does NOT
// exist at the git root but DOES exist relative to CWD, the resolver falls back to the
// CWD-relative path.
func TestTryResolveWithGitRoot_CWDFallback(t *testing.T) {
gitRoot := getGitRootOrEmpty()
require.NotEmpty(t, gitRoot, "test requires git root discovery")
cwdDir := filepath.Join(gitRoot, "pkg", "config", "testdata-cwd-fallback")
require.NoError(t, os.MkdirAll(cwdDir, 0o755))
t.Cleanup(func() { os.RemoveAll(cwdDir) })
cwdOnlyPath := "test-cwd-fallback-unique-dir-12345"
absExpected := filepath.Join(cwdDir, cwdOnlyPath)
require.NoError(t, os.MkdirAll(absExpected, 0o755))
t.Cleanup(func() { os.RemoveAll(absExpected) })
_, statErr := os.Stat(filepath.Join(gitRoot, cwdOnlyPath))
require.True(t, os.IsNotExist(statErr), "path should not exist at git root")
t.Chdir(cwdDir)
resolved, err := resolveAbsolutePath(cwdOnlyPath, "", "")
require.NoError(t, err)
assert.Equal(t, absExpected, resolved,
"should fall back to CWD-relative path when git root path doesn't exist")
}
// TestTryResolveWithGitRoot_NeitherExists verifies that when a simple relative path exists
// at neither git root nor CWD, the resolver returns the git-root-joined path.
func TestTryResolveWithGitRoot_NeitherExists(t *testing.T) {
gitRoot := getGitRootOrEmpty()
require.NotEmpty(t, gitRoot, "test requires git root discovery")
nonexistentPath := "nonexistent-path-that-should-not-exist-anywhere-12345"
resolved, err := resolveAbsolutePath(nonexistentPath, "", "")
require.NoError(t, err)
assert.Equal(t, filepath.Join(gitRoot, nonexistentPath), resolved,
"should return git-root-joined path when neither location exists")
}
// TestResolveDotPrefixPath_NoConfigPath_FallsToCWD verifies that when source is config
// but no cliConfigPath is provided, dot-prefixed paths fall back to CWD.
func TestResolveDotPrefixPath_NoConfigPath_FallsToCWD(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
cwdDir := filepath.Join(tmpDir, "workdir")
require.NoError(t, os.MkdirAll(cwdDir, 0o755))
t.Chdir(cwdDir)
// Config source with empty cliConfigPath — should fall back to CWD.
result, err := resolveAbsolutePath(".", "", "")
require.NoError(t, err)
assert.Equal(t, cwdDir, result,
"dot from config with no cliConfigPath should fall back to CWD")
// Same for dot-slash-foo.
result, err = resolveAbsolutePath("./sub", "", "")
require.NoError(t, err)
assert.Equal(t, filepath.Join(cwdDir, "sub"), result,
"dot-slash from config with no cliConfigPath should fall back to CWD")
}
// TestResolveDotPrefixPath_DotDotSlash_Runtime verifies "../foo" from runtime resolves to CWD.
func TestResolveDotPrefixPath_DotDotSlash_Runtime(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
cwdDir := filepath.Join(tmpDir, "a", "b")
require.NoError(t, os.MkdirAll(cwdDir, 0o755))
t.Chdir(cwdDir)
result, err := resolveAbsolutePath("../c", filepath.Join(tmpDir, "config"), "runtime")
require.NoError(t, err)
assert.Equal(t, filepath.Join(tmpDir, "a", "c"), result,
"../c from runtime should resolve relative to CWD")
}
// TestResolveAbsolutePath_AbsolutePassThrough verifies absolute paths pass through unchanged.
func TestResolveAbsolutePath_AbsolutePassThrough(t *testing.T) {
// Use a real absolute path from the OS to avoid Windows drive-letter issues.
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
absPath := filepath.Join(tmpDir, "some", "absolute", "path")
configPath := filepath.Join(tmpDir, "config")
result, err := resolveAbsolutePath(absPath, configPath, "")
require.NoError(t, err)
assert.Equal(t, absPath, result, "absolute path should pass through unchanged")
result, err = resolveAbsolutePath(absPath, "", "runtime")
require.NoError(t, err)
assert.Equal(t, absPath, result, "absolute path should pass through regardless of source")
}
// TestTryResolveWithConfigPath_AllBranches covers tryResolveWithConfigPath branches.
func TestTryResolveWithConfigPath_AllBranches(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
configDir := filepath.Join(tmpDir, "config")
require.NoError(t, os.MkdirAll(configDir, 0o755))
cwdDir := filepath.Join(tmpDir, "cwd")
require.NoError(t, os.MkdirAll(cwdDir, 0o755))
t.Chdir(cwdDir)
tests := []struct {
name string
path string
configPath string
expected string
}{
{
name: "empty path with config path returns config path",
path: "",
configPath: configDir,
expected: configDir,
},
{
name: "relative path with config path joins them",
path: "stacks",
configPath: configDir,
expected: filepath.Join(configDir, "stacks"),
},
{
name: "empty path and empty config path returns CWD",
path: "",
configPath: "",
expected: cwdDir,
},
{
name: "relative path with empty config path resolves to CWD",
path: "stacks",
configPath: "",
expected: filepath.Join(cwdDir, "stacks"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := tryResolveWithConfigPath(tt.path, tt.configPath)
require.NoError(t, err)
assert.Equal(t, tt.expected, result)
})
}
}
// TestResolveAbsolutePath_BarePathNoGitRoot verifies that bare paths without git root
// fall back to config dir, then CWD.
func TestResolveAbsolutePath_BarePathNoGitRoot(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
configDir := filepath.Join(tmpDir, "config")
require.NoError(t, os.MkdirAll(configDir, 0o755))
t.Chdir(tmpDir)
t.Setenv("ATMOS_GIT_ROOT_BASEPATH", "false")
// Bare path with config dir and no git root → config dir join.
result, err := resolveAbsolutePath("stacks", configDir, "")
require.NoError(t, err)
assert.Equal(t, filepath.Join(configDir, "stacks"), result,
"bare path without git root should resolve via config dir")
// Bare path with no config dir and no git root → CWD join.
result, err = resolveAbsolutePath("stacks", "", "")
require.NoError(t, err)
assert.Equal(t, filepath.Join(tmpDir, "stacks"), result,
"bare path without git root and config dir should resolve via CWD")
}
// TestInitCliConfig_BasePathSource_SetForStructField verifies that BasePathSource
// is set to "runtime" when AtmosBasePath is provided via struct field.
func TestInitCliConfig_BasePathSource_SetForStructField(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
require.NoError(t, os.WriteFile(
filepath.Join(tmpDir, "atmos.yaml"),
[]byte("base_path: ./\nstacks:\n base_path: stacks\n"),
0o644,
))
require.NoError(t, os.MkdirAll(filepath.Join(tmpDir, "stacks"), 0o755))
configAndStacksInfo := schema.ConfigAndStacksInfo{
AtmosBasePath: tmpDir,
}
atmosConfig, err := InitCliConfig(configAndStacksInfo, false)
require.NoError(t, err)
assert.Equal(t, "runtime", atmosConfig.BasePathSource,
"BasePathSource should be 'runtime' when AtmosBasePath is set via struct field")
}
// TestInitCliConfig_BasePathSource_SetForEnvVar verifies that BasePathSource
// is set to "runtime" when ATMOS_BASE_PATH env var is provided.
func TestInitCliConfig_BasePathSource_SetForEnvVar(t *testing.T) {
tmpDir := t.TempDir()
tmpDir, err := filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
require.NoError(t, os.WriteFile(
filepath.Join(tmpDir, "atmos.yaml"),
[]byte("base_path: ./\nstacks:\n base_path: stacks\n"),
0o644,
))
require.NoError(t, os.MkdirAll(filepath.Join(tmpDir, "stacks"), 0o755))
t.Chdir(tmpDir)
t.Setenv("ATMOS_BASE_PATH", tmpDir)
atmosConfig, err := InitCliConfig(schema.ConfigAndStacksInfo{}, false)
require.NoError(t, err)
assert.Equal(t, "runtime", atmosConfig.BasePathSource,
"BasePathSource should be 'runtime' when ATMOS_BASE_PATH env var is set")
}
// TestFindAllStackConfigsInPathsForStack_ErrorWrapping verifies that when GetGlobMatches
// fails, the error is wrapped with the ErrFailedToFindImport sentinel.
func TestFindAllStackConfigsInPathsForStack_ErrorWrapping(t *testing.T) {
atmosConfig := schema.AtmosConfiguration{
StacksBaseAbsolutePath: filepath.Join(os.TempDir(), "nonexistent-stacks-dir-test"),
}
includeStackPaths := []string{
filepath.Join(os.TempDir(), "nonexistent-stacks-dir-test", "**", "*.yaml"),
}
_, _, _, err := FindAllStackConfigsInPathsForStack(
atmosConfig,
"test-stack",
includeStackPaths,
nil,
)
require.Error(t, err)
assert.True(t, errors.Is(err, errUtils.ErrFailedToFindImport),
"Error should wrap ErrFailedToFindImport, got: %v", err)
}
// TestFindAllStackConfigsInPaths_ErrorWrapping verifies error wrapping in the non-stack variant.
func TestFindAllStackConfigsInPaths_ErrorWrapping(t *testing.T) {
atmosConfig := schema.AtmosConfiguration{
StacksBaseAbsolutePath: filepath.Join(os.TempDir(), "nonexistent-stacks-dir-test2"),
}
includeStackPaths := []string{
filepath.Join(os.TempDir(), "nonexistent-stacks-dir-test2", "**", "*.yaml"),
}
_, _, err := FindAllStackConfigsInPaths(
&atmosConfig,
includeStackPaths,
nil,
)
require.Error(t, err)
assert.True(t, errors.Is(err, errUtils.ErrFailedToFindImport),
"Error should wrap ErrFailedToFindImport, got: %v", err)
}