ignore nil repos in list and add better debugging
This commit is contained in:
parent
e3c598109b
commit
80629d12fa
3 changed files with 46 additions and 1 deletions
|
@ -57,7 +57,9 @@ func (s *service) List(ctx context.Context, user *core.User) ([]*core.Repository
|
|||
return nil, err
|
||||
}
|
||||
for _, src := range result {
|
||||
repos = append(repos, convertRepository(src, s.visibility, s.trusted))
|
||||
if src != nil {
|
||||
repos = append(repos, convertRepository(src, s.visibility, s.trusted))
|
||||
}
|
||||
}
|
||||
opts.Page = meta.Page.Next
|
||||
opts.URL = meta.Page.NextURL
|
||||
|
|
|
@ -246,3 +246,44 @@ func TestList_RefreshErr(t *testing.T) {
|
|||
t.Errorf("Expect error refreshing token")
|
||||
}
|
||||
}
|
||||
|
||||
func TestListWithNilRepo(t *testing.T) {
|
||||
controller := gomock.NewController(t)
|
||||
defer controller.Finish()
|
||||
|
||||
mockUser := &core.User{}
|
||||
mockRepos := []*scm.Repository{
|
||||
{
|
||||
Namespace: "octocat",
|
||||
Name: "hello-world",
|
||||
},
|
||||
nil,
|
||||
}
|
||||
|
||||
mockRepoService := mockscm.NewMockRepositoryService(controller)
|
||||
mockRepoService.EXPECT().List(gomock.Any(), gomock.Any()).Return(mockRepos, &scm.Response{}, nil)
|
||||
|
||||
mockRenewer := mock.NewMockRenewer(controller)
|
||||
mockRenewer.EXPECT().Renew(gomock.Any(), mockUser, false)
|
||||
|
||||
client := new(scm.Client)
|
||||
client.Repositories = mockRepoService
|
||||
|
||||
want := []*core.Repository{
|
||||
{
|
||||
Namespace: "octocat",
|
||||
Name: "hello-world",
|
||||
Slug: "octocat/hello-world",
|
||||
Visibility: "public",
|
||||
},
|
||||
}
|
||||
|
||||
service := New(client, mockRenewer, "", false)
|
||||
got, err := service.List(noContext, mockUser)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, want); diff != "" {
|
||||
t.Errorf(diff)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package syncer
|
|||
|
||||
import (
|
||||
"context"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -67,6 +68,7 @@ func (s *Synchronizer) Sync(ctx context.Context, user *core.User) (*core.Batch,
|
|||
if err := recover(); err != nil {
|
||||
logger = logger.WithField("error", err)
|
||||
logger.Errorln("syncer: unexpected panic")
|
||||
debug.PrintStack()
|
||||
}
|
||||
|
||||
// when the synchronization process is complete
|
||||
|
|
Loading…
Reference in a new issue