Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ee6b40

Browse files
committed
fix test file name
1 parent7cbbc20 commit2ee6b40

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

‎provisioner/terraform/resources_test.go‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ func ctxAndLogger(t *testing.T) (context.Context, slog.Logger) {
3333
returncontext.Background(),testutil.Logger(t)
3434
}
3535

36-
//TestConvertStateGoldenFiles compares the output of ConvertState to a golden
36+
//TestConvertStateGolden compares the output of ConvertState to a golden
3737
// file to prevent regressions. If the logic changes, update the golden files
3838
// accordingly.
39-
funcTestConvertStateGoldenFiles(t*testing.T) {
39+
//
40+
// This was created to aid in refactoring `ConvertState`.
41+
funcTestConvertStateGolden(t*testing.T) {
4042
t.Parallel()
4143

4244
testResourceDirectories:=filepath.Join("testdata","resources")
@@ -51,22 +53,28 @@ func TestConvertStateGoldenFiles(t *testing.T) {
5153
testFiles,err:=os.ReadDir(filepath.Join(testResourceDirectories,testDirectory.Name()))
5254
require.NoError(t,err)
5355

56+
// ConvertState works on both a plan file and a state file.
57+
// The test should create a golden file for both.
5458
for_,step:=range []string{"plan","state"} {
55-
planIdx:=slices.IndexFunc(testFiles,func(entry os.DirEntry)bool {
59+
srcIdc:=slices.IndexFunc(testFiles,func(entry os.DirEntry)bool {
5660
returnstrings.HasSuffix(entry.Name(),fmt.Sprintf(".tf%s.json",step))
5761
})
5862
dotIdx:=slices.IndexFunc(testFiles,func(entry os.DirEntry)bool {
5963
returnstrings.HasSuffix(entry.Name(),fmt.Sprintf(".tf%s.dot",step))
6064
})
6165

62-
ifplanIdx==-1||dotIdx==-1 {
66+
// If the directory is missing these files, we cannot run ConvertState
67+
// on it. So it's skipped.
68+
ifsrcIdc==-1||dotIdx==-1 {
6369
continue
6470
}
6571

6672
t.Run(step+"_"+testDirectory.Name(),func(t*testing.T) {
73+
// Load the paths before t.Parallel()
6774
testDirectoryPath:=filepath.Join(testResourceDirectories,testDirectory.Name())
68-
planFile:=filepath.Join(testDirectoryPath,testFiles[planIdx].Name())
75+
planFile:=filepath.Join(testDirectoryPath,testFiles[srcIdc].Name())
6976
dotFile:=filepath.Join(testDirectoryPath,testFiles[dotIdx].Name())
77+
7078
t.Parallel()
7179
ctx:=testutil.Context(t,testutil.WaitMedium)
7280
logger:=slogtest.Make(t,nil)
@@ -99,6 +107,8 @@ func TestConvertStateGoldenFiles(t *testing.T) {
99107
dotFileRaw,err:=os.ReadFile(dotFile)
100108
require.NoError(t,err)
101109

110+
// expectedOutput is `any` to support errors too. If `ConvertState` returns an
111+
// error, that error is the golden file output.
102112
varexpectedOutputany
103113
state,err:=terraform.ConvertState(ctx,modules,string(dotFileRaw),logger)
104114
iferr==nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp