Skip to content

Commit ca32437

Browse files
authored
fix: read api dir from temp folder (#2239)
fixes: #2238
1 parent 70f603f commit ca32437

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

internal/librarian/generate.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const (
3333

3434
type generateRunner struct {
3535
api string
36-
apiSource string
3736
branch string
3837
build bool
3938
commit bool
@@ -57,7 +56,6 @@ func newGenerateRunner(cfg *config.Config) (*generateRunner, error) {
5756
}
5857
return &generateRunner{
5958
api: cfg.API,
60-
apiSource: cfg.APISource,
6159
branch: cfg.Branch,
6260
build: cfg.Build,
6361
commit: cfg.Commit,
@@ -333,7 +331,7 @@ func (r *generateRunner) runBuildCommand(ctx context.Context, libraryID string)
333331
// it returns an empty string and an error.
334332
func (r *generateRunner) runConfigureCommand(ctx context.Context) (string, error) {
335333

336-
apiRoot, err := filepath.Abs(r.apiSource)
334+
apiRoot, err := filepath.Abs(r.sourceRepo.GetDir())
337335
if err != nil {
338336
return "", err
339337
}
@@ -347,7 +345,7 @@ func (r *generateRunner) runConfigureCommand(ctx context.Context) (string, error
347345

348346
if err := populateServiceConfigIfEmpty(
349347
r.state,
350-
r.apiSource); err != nil {
348+
apiRoot); err != nil {
351349
return "", err
352350
}
353351

internal/librarian/generate_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func TestRunGenerateCommand(t *testing.T) {
8181
t.Parallel()
8282
r := &generateRunner{
8383
api: test.api,
84-
apiSource: t.TempDir(),
8584
repo: test.repo,
8685
sourceRepo: newTestGitRepo(t),
8786
ghClient: test.ghClient,
@@ -326,29 +325,28 @@ func TestRunConfigureCommand(t *testing.T) {
326325
} {
327326
t.Run(test.name, func(t *testing.T) {
328327
t.Parallel()
329-
sourcePath := t.TempDir()
330328
r := &generateRunner{
331329
api: test.api,
332-
apiSource: sourcePath,
333330
repo: test.repo,
331+
sourceRepo: newTestGitRepo(t),
334332
state: test.state,
335333
containerClient: test.container,
336334
}
337335

338336
// Create a service config
339-
if err := os.MkdirAll(filepath.Join(r.apiSource, test.api), 0755); err != nil {
337+
if err := os.MkdirAll(filepath.Join(r.sourceRepo.GetDir(), test.api), 0755); err != nil {
340338
t.Fatal(err)
341339
}
342340

343341
data := []byte("type: google.api.Service")
344-
if err := os.WriteFile(filepath.Join(r.apiSource, test.api, "example_service_v2.yaml"), data, 0755); err != nil {
342+
if err := os.WriteFile(filepath.Join(r.sourceRepo.GetDir(), test.api, "example_service_v2.yaml"), data, 0755); err != nil {
345343
t.Fatal(err)
346344
}
347345

348346
if test.name == "configures library with non-existent api source" {
349347
// This test verifies the scenario of no service config is found
350348
// in api path.
351-
if err := os.RemoveAll(filepath.Join(r.apiSource)); err != nil {
349+
if err := os.RemoveAll(filepath.Join(r.sourceRepo.GetDir())); err != nil {
352350
t.Fatal(err)
353351
}
354352
}
@@ -961,13 +959,11 @@ func TestGenerateScenarios(t *testing.T) {
961959
},
962960
} {
963961
t.Run(test.name, func(t *testing.T) {
964-
apiSource := t.TempDir()
965962
repo := newTestGitRepoWithState(t, test.state, true)
966963

967964
r := &generateRunner{
968965
api: test.api,
969966
library: test.library,
970-
apiSource: apiSource,
971967
build: test.build,
972968
repo: repo,
973969
sourceRepo: newTestGitRepo(t),
@@ -979,11 +975,11 @@ func TestGenerateScenarios(t *testing.T) {
979975
}
980976

981977
// Create a service config in api path.
982-
if err := os.MkdirAll(filepath.Join(r.apiSource, test.api), 0755); err != nil {
978+
if err := os.MkdirAll(filepath.Join(r.sourceRepo.GetDir(), test.api), 0755); err != nil {
983979
t.Fatal(err)
984980
}
985981
data := []byte("type: google.api.Service")
986-
if err := os.WriteFile(filepath.Join(r.apiSource, test.api, "example_service_v2.yaml"), data, 0755); err != nil {
982+
if err := os.WriteFile(filepath.Join(r.sourceRepo.GetDir(), test.api, "example_service_v2.yaml"), data, 0755); err != nil {
987983
t.Fatal(err)
988984
}
989985

0 commit comments

Comments
 (0)