Skip to content

Commit

Permalink
Fill in the Size field in OCI downloaderResponse
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey-Kizimov <[email protected]>
  • Loading branch information
Sergey-Kizimov authored and ashutosh-narkar committed Aug 21, 2024
1 parent 7a29bb5 commit b36a332
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 6 additions & 2 deletions download/oci_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (d *OCIDownloader) oneShot(ctx context.Context) error {
d.SetCache(resp.etag) // set the current etag sha to the cache

if d.f != nil {
d.f(ctx, Update{ETag: resp.etag, Bundle: resp.b, Error: nil, Metrics: m, Raw: resp.raw})
d.f(ctx, Update{ETag: resp.etag, Bundle: resp.b, Error: nil, Metrics: m, Raw: resp.raw, Size: resp.size})
}
return nil
}
Expand Down Expand Up @@ -258,7 +258,10 @@ func (d *OCIDownloader) download(ctx context.Context, m metrics.Metrics) (*downl
}, nil
}
fileReader, err := os.Open(bundleFilePath)
tee := io.TeeReader(fileReader, &buf)

cnt := &count{}
r := io.TeeReader(fileReader, cnt)
tee := io.TeeReader(r, &buf)

if err != nil {
return nil, err
Expand All @@ -281,6 +284,7 @@ func (d *OCIDownloader) download(ctx context.Context, m metrics.Metrics) (*downl
raw: &buf,
etag: etag,
longPoll: false,
size: cnt.Bytes(),
}, nil
}

Expand Down
24 changes: 18 additions & 6 deletions download/oci_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package download

import (
"bytes"
"context"
"encoding/base64"
"fmt"
"net/http"
"reflect"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -383,8 +383,7 @@ func TestOCICustomAuthPlugin(t *testing.T) {
}
}

func TestOCIRawDataHasNonZeroSize(t *testing.T) {
var buf bytes.Buffer
func TestOCIValidateAndInjectDefaults(t *testing.T) {
ctx := context.Background()
fixture := newTestFixture(t)
fixture.server.expEtag = "sha256:c5834dbce332cabe6ae68a364de171a50bf5b08024c27d7c08cc72878b4df7ff"
Expand All @@ -407,14 +406,27 @@ func TestOCIRawDataHasNonZeroSize(t *testing.T) {

u1 := <-updates

buf.ReadFrom(u1.Raw)
if u1.Size == 0 {
t.Fatal("expected non-0 size")
}

if u1.Raw == nil {
t.Fatal("expected bundle reader to be non-nil")
}

if buf.Len() == 0 {
t.Fatal("expected non-0 size")
r := bundle.NewReader(u1.Raw)

b, err := r.Read()
if err != nil {
t.Fatal(err)
}

if !reflect.DeepEqual(b.Data, u1.Bundle.Data) {
t.Fatal("expected the bundle object and reader to have the same data")
}

if len(b.Modules) != len(u1.Bundle.Modules) {
t.Fatal("expected the bundle object and reader to have the same number of bundle modules")
}

d.Stop(ctx)
Expand Down

0 comments on commit b36a332

Please sign in to comment.