diff --git a/src/jobservice/logger/getter/db_getter.go b/src/jobservice/logger/getter/db_getter.go index 1d98170abc3..ba96b9905b4 100644 --- a/src/jobservice/logger/getter/db_getter.go +++ b/src/jobservice/logger/getter/db_getter.go @@ -47,7 +47,7 @@ func (dbg *DBGetter) Retrieve(logID string) ([]byte, error) { sz := int64(len(jobLog.Content)) var buf []byte sizeLimit := logSizeLimit() - if sizeLimit <= 0 { + if sizeLimit <= 0 || sz <= sizeLimit { buf = []byte(jobLog.Content) return buf, nil } diff --git a/src/jobservice/logger/getter/db_getter_test.go b/src/jobservice/logger/getter/db_getter_test.go index ef696303172..0faccca8de5 100644 --- a/src/jobservice/logger/getter/db_getter_test.go +++ b/src/jobservice/logger/getter/db_getter_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" + "github.com/goharbor/harbor/src/jobservice/config" "github.com/goharbor/harbor/src/jobservice/logger/backend" "github.com/goharbor/harbor/src/jobservice/logger/sweeper" "github.com/goharbor/harbor/src/lib/log" @@ -44,9 +45,11 @@ func TestDBGetter(t *testing.T) { err = l.Close() require.NoError(t, err) + _ = config.DefaultConfig.Load("../../config_test.yml", true) dbGetter := NewDBGetter() ll, err := dbGetter.Retrieve(uuid) require.Nil(t, err) + require.NotEqual(t, 0, len(ll)) log.Infof("get logger %s", ll) err = sweeper.PrepareDBSweep()