@@ -956,35 +956,62 @@ func TestOpenWriterEmulated(t *testing.T) {
956956 })
957957}
958958
959- func TestWriterOneshotNoProgressReportEmulated (t * testing.T ) {
959+ // Test that Writer.ProgressFunc is called at the expected intervals, showing
960+ // consistency across HTTP and gRPC.
961+ func TestWriterProgressFuncEmulated (t * testing.T ) {
960962 transportClientTest (context .Background (), t , func (t * testing.T , ctx context.Context , project , bucket string , client storageClient ) {
961963 _ , err := client .CreateBucket (ctx , project , bucket , & BucketAttrs {
962964 Name : bucket ,
963965 }, nil )
964966 if err != nil {
965967 t .Fatalf ("client.CreateBucket: %v" , err )
966968 }
967- // Oneshot uploads can be forced with either a chunksize of 0, or a
968- // chunksize larger than the data size.
969- for _ , chunksize := range []int {0 , 16 * MiB } {
970- t .Run (fmt .Sprintf ("data size %d chunksize %d" , 3 * MiB , chunksize ), func (t * testing.T ) {
971- prefix := time .Now ().Nanosecond ()
972- objName := fmt .Sprintf ("%d-object-%d" , prefix , time .Now ().Nanosecond ())
973-
969+ cases := []struct {
970+ name string
971+ chunkSize int
972+ expectedCalls []int64
973+ }{
974+ {
975+ name : "one shot, zero chunkSize" ,
976+ chunkSize : 0 ,
977+ expectedCalls : []int64 {},
978+ },
979+ {
980+ name : "one shot, chunk larger than data" ,
981+ chunkSize : 16 * MiB ,
982+ expectedCalls : []int64 {},
983+ },
984+ {
985+ name : "resumable, obj size evenly divisible by chunkSize" ,
986+ chunkSize : 1 * MiB ,
987+ expectedCalls : []int64 {MiB , 2 * MiB , 3 * MiB },
988+ },
989+ {
990+ name : "resumable, obj size not divisible by chunkSize" ,
991+ chunkSize : 2 * MiB ,
992+ expectedCalls : []int64 {2 * MiB , 3 * MiB },
993+ },
994+ }
995+ for _ , c := range cases {
996+ t .Run (c .name , func (t * testing.T ) {
974997 vc := & Client {tc : client }
975- obj := vc .Bucket (bucket ).Object (objName )
998+ obj := vc .Bucket (bucket ).Object (c .name )
999+
9761000 w := obj .NewWriter (ctx )
977- w .ChunkSize = chunksize
978- progressCalls := 0
979- w .ProgressFunc = func (int64 ) { progressCalls ++ }
1001+ w .ChunkSize = c .chunkSize
1002+ var gotCalls []int64
1003+ w .ProgressFunc = func (off int64 ) {
1004+ gotCalls = append (gotCalls , off )
1005+ }
1006+
9801007 if _ , err := w .Write (randomBytes3MiB ); err != nil {
981- t .Fatalf ("writer.Write : %v" , err )
1008+ t .Fatalf ("writing data : %v" , err )
9821009 }
9831010 if err := w .Close (); err != nil {
984- t .Fatalf ("writer.Close : %v" , err )
1011+ t .Fatalf ("closing writer: %v" , err )
9851012 }
986- if progressCalls != 0 {
987- t .Errorf ("ProgressFunc was called %d times, expected 0 " , progressCalls )
1013+ if slices . Compare ( gotCalls , c . expectedCalls ) != 0 {
1014+ t .Errorf ("progressFunc: got calls at %v, want %v " , gotCalls , c . expectedCalls )
9881015 }
9891016 attrs , err := obj .Attrs (ctx )
9901017 if err != nil {
@@ -996,6 +1023,7 @@ func TestWriterOneshotNoProgressReportEmulated(t *testing.T) {
9961023 })
9971024 }
9981025 })
1026+
9991027}
10001028
10011029func TestOpenAppendableWriterEmulated (t * testing.T ) {
0 commit comments