Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type Config struct {
APISource string

// APISourceDepth controls the depth of the repository closing **IF**
// APISource is a github repository and it is cloned.
// APISource is a GitHub repository, and it is cloned.
APISourceDepth int

// Branch is the remote branch of the language repository to use.
Expand Down
2 changes: 1 addition & 1 deletion internal/librarian/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ type commandRunner struct {
librarianConfig *config.LibrarianConfig
ghClient GitHubClient
containerClient ContainerClient
workRoot string
image string
workRoot string
}

const defaultAPISourceBranch = "master"
Expand Down
1 change: 1 addition & 0 deletions internal/librarian/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func newGenerateRunner(cfg *config.Config) (*generateRunner, error) {
return &generateRunner{
api: cfg.API,
apiSource: cfg.APISource,
branch: cfg.Branch,
build: cfg.Build,
commit: cfg.Commit,
containerClient: runner.containerClient,
Expand Down
38 changes: 30 additions & 8 deletions internal/librarian/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,17 @@ func TestRunConfigureCommand(t *testing.T) {
func TestNewGenerateRunner(t *testing.T) {
t.Parallel()
for _, test := range []struct {
name string
cfg *config.Config
wantErr bool
name string
cfg *config.Config
wantErr bool
wantErrMsg string
}{
{
name: "valid config",
cfg: &config.Config{
API: "some/api",
APISource: newTestGitRepo(t).GetDir(),
Branch: "test-branch",
Repo: newTestGitRepo(t).GetDir(),
WorkRoot: t.TempDir(),
Image: "gcr.io/test/test-image",
Expand All @@ -406,13 +408,15 @@ func TestNewGenerateRunner(t *testing.T) {
Image: "gcr.io/test/test-image",
CommandName: generateCmdName,
},
wantErr: true,
wantErr: true,
wantErrMsg: "repository does not exist",
},
{
name: "missing image",
Comment thread
JoeWang1127 marked this conversation as resolved.
cfg: &config.Config{
API: "some/api",
APISource: t.TempDir(),
Branch: "test-branch",
Repo: "https://github.com/googleapis/librarian.git",
WorkRoot: t.TempDir(),
CommandName: generateCmdName,
Expand All @@ -424,6 +428,7 @@ func TestNewGenerateRunner(t *testing.T) {
cfg: &config.Config{
API: "some/api",
APISource: newTestGitRepo(t).GetDir(),
Branch: "test-branch",
Repo: newTestGitRepo(t).GetDir(),
WorkRoot: t.TempDir(),
Image: "gcr.io/test/test-image",
Expand All @@ -437,6 +442,7 @@ func TestNewGenerateRunner(t *testing.T) {
API: "some/api",
APISource: "https://github.com/googleapis/googleapis", // This will trigger the clone of googleapis
APISourceDepth: 1,
Branch: "test-branch",
Repo: newTestGitRepo(t).GetDir(),
WorkRoot: t.TempDir(),
Image: "gcr.io/test/test-image",
Expand All @@ -454,13 +460,15 @@ func TestNewGenerateRunner(t *testing.T) {
Image: "gcr.io/test/test-image",
CommandName: generateCmdName,
},
wantErr: true,
wantErr: true,
wantErrMsg: "repo must be specified",
},
{
name: "valid config with local repo",
cfg: &config.Config{
API: "some/api",
APISource: newTestGitRepo(t).GetDir(),
Branch: "test-branch",
Repo: newTestGitRepo(t).GetDir(),
WorkRoot: t.TempDir(),
Image: "gcr.io/test/test-image",
Expand Down Expand Up @@ -500,12 +508,26 @@ func TestNewGenerateRunner(t *testing.T) {
}

r, err := newGenerateRunner(test.cfg)
if (err != nil) != test.wantErr {
t.Errorf("newGenerateRunner() error = %v, wantErr %v", err, test.wantErr)
}
if test.wantErr {
if err == nil {
t.Fatalf("newGenerateRunner() error = %v, wantErr %v", err, test.wantErr)
}

if !strings.Contains(err.Error(), test.wantErrMsg) {
t.Fatalf("want error message: %s, got: %s", test.wantErrMsg, err.Error())
}

return
}

if err != nil {
t.Fatalf("newGenerateRunner() got error: %v", err)
}

if r.branch == "" {
t.Errorf("newGenerateRunner() branch is not set")
}

if r.ghClient == nil {
t.Errorf("newGenerateRunner() ghClient is nil")
}
Expand Down
Loading