go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/artifactcontent/rbecas_test.go (about)

     1  // Copyright 2021 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package artifactcontent
    16  
    17  import (
    18  	"bufio"
    19  	"context"
    20  	"io"
    21  	"strings"
    22  	"testing"
    23  
    24  	artifactcontenttest "go.chromium.org/luci/resultdb/internal/artifactcontent/testutil"
    25  	"go.chromium.org/luci/resultdb/internal/testutil"
    26  
    27  	. "github.com/smartystreets/goconvey/convey"
    28  )
    29  
    30  func TestDownloadRBECASContent(t *testing.T) {
    31  	Convey(`TestDownloadRBECASContent`, t, func() {
    32  		ctx := testutil.TestingContext()
    33  
    34  		ac := &Reader{
    35  			RBEInstance: "projects/p/instances/a",
    36  			Hash:        "deadbeef",
    37  			Size:        int64(10),
    38  		}
    39  
    40  		var str strings.Builder
    41  		err := ac.DownloadRBECASContent(ctx, &artifactcontenttest.FakeByteStreamClient{[]byte("contentspart2\n")}, func(_ context.Context, pr io.Reader) error {
    42  			sc := bufio.NewScanner(pr)
    43  			for sc.Scan() {
    44  				str.Write(sc.Bytes())
    45  				str.Write([]byte("\n"))
    46  			}
    47  			return nil
    48  		})
    49  		So(err, ShouldBeNil)
    50  		So(str.String(), ShouldEqual, "contentspart1\ncontentspart2\n")
    51  	})
    52  }