Skip to content

Commit f121693

Browse files
authored
refactor: mv testdata to co-locate in the package of test (#2936)
Move testdata for docker/docker_test.go and librarian/state_test.go into the same package. Removed some unused test data files. For #2842
1 parent 7b71c82 commit f121693

22 files changed

+10
-36
lines changed

internal/docker/docker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ func TestWriteLibraryState(t *testing.T) {
924924
t.Fatalf("Failed to read generated file: %v", err)
925925
}
926926

927-
wantBytes, readErr := os.ReadFile(filepath.Join("../..", "testdata", "test-write-library-state", test.wantFile))
927+
wantBytes, readErr := os.ReadFile(filepath.Join("testdata", "test-write-library-state", test.wantFile))
928928
if readErr != nil {
929929
t.Fatalf("Failed to read expected state for comparison: %v", readErr)
930930
}
@@ -1035,7 +1035,7 @@ func TestWriteLibrarianState(t *testing.T) {
10351035
t.Fatalf("Failed to read generated file: %v", err)
10361036
}
10371037

1038-
wantBytes, readErr := os.ReadFile(filepath.Join("../..", "testdata", "test-write-librarian-state", test.wantFile))
1038+
wantBytes, readErr := os.ReadFile(filepath.Join("testdata", "test-write-librarian-state", test.wantFile))
10391039
if readErr != nil {
10401040
t.Fatalf("Failed to read expected state for comparison: %v", readErr)
10411041
}
@@ -1135,7 +1135,7 @@ func TestReleaseStageRequestContent(t *testing.T) {
11351135
t.Fatalf("ReadFile failed: %v", err)
11361136
}
11371137

1138-
wantFile := filepath.Join("..", "..", "testdata", "docker", "release-stage-request", "release-stage-request.json")
1138+
wantFile := filepath.Join("testdata", "release-stage-request", "release-stage-request.json")
11391139
wantBytes, err := os.ReadFile(wantFile)
11401140
if err != nil {
11411141
t.Fatalf("ReadFile for want file failed: %v", err)

testdata/docker/release-stage-request/release-stage-request.json renamed to internal/docker/testdata/release-stage-request/release-stage-request.json

File renamed without changes.

testdata/test-write-librarian-state/empty-librarian-state.json renamed to internal/docker/testdata/test-write-librarian-state/empty-librarian-state.json

File renamed without changes.

testdata/test-write-librarian-state/write-librarian-state-example.json renamed to internal/docker/testdata/test-write-librarian-state/write-librarian-state-example.json

File renamed without changes.

testdata/test-write-library-state/empty-library-state.json renamed to internal/docker/testdata/test-write-library-state/empty-library-state.json

File renamed without changes.

testdata/test-write-library-state/omit-empty-status.json renamed to internal/docker/testdata/test-write-library-state/omit-empty-status.json

File renamed without changes.

testdata/test-write-library-state/successful-marshaling-and-writing.json renamed to internal/docker/testdata/test-write-library-state/successful-marshaling-and-writing.json

File renamed without changes.

internal/librarian/state_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,24 @@ func TestFindServiceConfigIn(t *testing.T) {
119119
}{
120120
{
121121
name: "find a service config",
122-
path: filepath.Join("..", "..", "testdata", "find_a_service_config"),
122+
path: filepath.Join("testdata", "find_a_service_config"),
123123
want: "service_config.yaml",
124124
},
125125
{
126126
name: "non-existent source path",
127-
path: filepath.Join("..", "..", "testdata", "non-existent-path"),
127+
path: filepath.Join("testdata", "non-existent-path"),
128128
want: "",
129129
wantErr: true,
130130
},
131131
{
132132
name: "no service config in a source path",
133-
path: filepath.Join("..", "..", "testdata", "no_service_config"),
133+
path: filepath.Join("testdata", "no_service_config"),
134134
want: "",
135135
wantErr: false,
136136
},
137137
{
138138
name: "invalid yaml",
139-
path: filepath.Join("..", "..", "testdata", "invalid_yaml"),
139+
path: filepath.Join("testdata", "invalid_yaml"),
140140
want: "",
141141
wantErr: true,
142142
},
@@ -195,7 +195,7 @@ func TestParseGlobalConfig(t *testing.T) {
195195
},
196196
} {
197197
t.Run(test.name, func(t *testing.T) {
198-
path := filepath.Join("../../testdata/test-parse-global-config", test.filename)
198+
path := filepath.Join("testdata", "test-parse-global-config", test.filename)
199199
got, err := parseLibrarianConfig(path)
200200
if test.wantErr {
201201
if err == nil {
@@ -244,7 +244,7 @@ func TestPopulateServiceConfig(t *testing.T) {
244244
},
245245
},
246246
},
247-
path: filepath.Join("..", "..", "testdata", "populate_service_config"),
247+
path: filepath.Join("testdata", "populate_service_config"),
248248
want: &config.LibrarianState{
249249
Libraries: []*config.LibraryState{
250250
{
@@ -388,7 +388,7 @@ func TestReadLibraryState(t *testing.T) {
388388
},
389389
} {
390390
t.Run(test.name, func(t *testing.T) {
391-
path := filepath.Join("../../testdata/test-read-library-state", test.filename)
391+
path := filepath.Join("testdata", "test-read-library-state", test.filename)
392392
// The response file is removed by the readLibraryState() function,
393393
// so we create a copy and read from it.
394394
dstFilePath := filepath.Join(t.TempDir(), "copied-state", test.filename)

testdata/find_a_service_config/another_config.yaml renamed to internal/librarian/testdata/find_a_service_config/another_config.yaml

File renamed without changes.

testdata/find_a_service_config/random_file.txt renamed to internal/librarian/testdata/find_a_service_config/random_file.txt

File renamed without changes.

0 commit comments

Comments
 (0)