X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2c6557f613fcf6cdcebb08c321a5d061aeb780c6..8dedd02357a95a0ae2c7961c8f1d0896b6311b3b:/services/keepstore/azure_blob_volume_test.go diff --git a/services/keepstore/azure_blob_volume_test.go b/services/keepstore/azure_blob_volume_test.go index a543dfc245..b8acd980a1 100644 --- a/services/keepstore/azure_blob_volume_test.go +++ b/services/keepstore/azure_blob_volume_test.go @@ -13,7 +13,6 @@ import ( "encoding/xml" "flag" "fmt" - "io" "io/ioutil" "math/rand" "net" @@ -222,7 +221,7 @@ func (h *azStubHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { rw.WriteHeader(http.StatusCreated) case r.Method == "PUT" && r.Form.Get("comp") == "metadata": // "Set Metadata Headers" API. We don't bother - // stubbing "Get Metadata Headers": AzureBlobVolume + // stubbing "Get Metadata Headers": azureBlobVolume // sets metadata headers only as a way to bump Etag // and Last-Modified. if !blobExists { @@ -367,7 +366,7 @@ func (d *azStubDialer) Dial(network, address string) (net.Conn, error) { } type testableAzureBlobVolume struct { - *AzureBlobVolume + *azureBlobVolume azHandler *azStubHandler azStub *httptest.Server t TB @@ -397,7 +396,7 @@ func (s *stubbedAzureBlobSuite) newTestableAzureBlobVolume(t TB, params newVolum azClient.Sender = &singleSender{} bs := azClient.GetBlobService() - v := &AzureBlobVolume{ + v := &azureBlobVolume{ ContainerName: container, WriteRaceInterval: arvados.Duration(time.Millisecond), WriteRacePollTime: arvados.Duration(time.Nanosecond), @@ -416,7 +415,7 @@ func (s *stubbedAzureBlobSuite) newTestableAzureBlobVolume(t TB, params newVolum } return &testableAzureBlobVolume{ - AzureBlobVolume: v, + azureBlobVolume: v, azHandler: azHandler, azStub: azStub, t: t, @@ -490,15 +489,13 @@ func (s *stubbedAzureBlobSuite) TestAzureBlobVolumeRangeFenceposts(c *check.C) { if err != nil { c.Error(err) } - gotData := bytes.NewBuffer(nil) - gotLen, err := v.BlockRead(context.Background(), hash, gotData) + gotData := &brbuffer{} + err = v.BlockRead(context.Background(), hash, gotData) if err != nil { c.Error(err) } gotHash := fmt.Sprintf("%x", md5.Sum(gotData.Bytes())) - if gotLen != size { - c.Errorf("length mismatch: got %d != %d", gotLen, size) - } + c.Check(gotData.Len(), check.Equals, size) if gotHash != hash { c.Errorf("hash mismatch: got %s != %s", gotHash, hash) } @@ -532,7 +529,7 @@ func (s *stubbedAzureBlobSuite) TestAzureBlobVolumeCreateBlobRace(c *check.C) { wg.Add(1) go func() { defer wg.Done() - _, err := v.BlockRead(context.Background(), TestHash, io.Discard) + err := v.BlockRead(context.Background(), TestHash, brdiscard) if err != nil { c.Error(err) } @@ -553,8 +550,8 @@ func (s *stubbedAzureBlobSuite) TestAzureBlobVolumeCreateBlobRaceDeadline(c *che MetricsVecs: newVolumeMetricsVecs(prometheus.NewRegistry()), BufferPool: newBufferPool(ctxlog.TestLogger(c), 8, prometheus.NewRegistry()), }) - v.AzureBlobVolume.WriteRaceInterval.Set("2s") - v.AzureBlobVolume.WriteRacePollTime.Set("5ms") + v.azureBlobVolume.WriteRaceInterval.Set("2s") + v.azureBlobVolume.WriteRacePollTime.Set("5ms") defer v.Teardown() v.BlockWriteRaw(TestHash, nil) @@ -570,15 +567,13 @@ func (s *stubbedAzureBlobSuite) TestAzureBlobVolumeCreateBlobRaceDeadline(c *che allDone := make(chan struct{}) go func() { defer close(allDone) - buf := bytes.NewBuffer(nil) - n, err := v.BlockRead(context.Background(), TestHash, buf) + buf := &brbuffer{} + err := v.BlockRead(context.Background(), TestHash, buf) if err != nil { c.Error(err) return } - if n != 0 { - c.Errorf("Got %+q (n=%d), expected empty buf", buf.Bytes(), n) - } + c.Check(buf.String(), check.Equals, "") }() select { case <-allDone: @@ -596,8 +591,7 @@ func (s *stubbedAzureBlobSuite) TestAzureBlobVolumeCreateBlobRaceDeadline(c *che func (s *stubbedAzureBlobSuite) TestAzureBlobVolumeContextCancelBlockRead(c *check.C) { s.testAzureBlobVolumeContextCancel(c, func(ctx context.Context, v *testableAzureBlobVolume) error { v.BlockWriteRaw(TestHash, TestBlock) - _, err := v.BlockRead(ctx, TestHash, io.Discard) - return err + return v.BlockRead(ctx, TestHash, brdiscard) }) } @@ -667,7 +661,7 @@ func (s *stubbedAzureBlobSuite) TestStats(c *check.C) { c.Check(stats(), check.Matches, `.*"Errors":0,.*`) loc := "acbd18db4cc2f85cedef654fccc4a4d8" - _, err := volume.BlockRead(context.Background(), loc, io.Discard) + err := volume.BlockRead(context.Background(), loc, brdiscard) c.Check(err, check.NotNil) c.Check(stats(), check.Matches, `.*"Ops":[^0],.*`) c.Check(stats(), check.Matches, `.*"Errors":[^0],.*`) @@ -679,9 +673,9 @@ func (s *stubbedAzureBlobSuite) TestStats(c *check.C) { c.Check(stats(), check.Matches, `.*"OutBytes":3,.*`) c.Check(stats(), check.Matches, `.*"CreateOps":1,.*`) - _, err = volume.BlockRead(context.Background(), loc, io.Discard) + err = volume.BlockRead(context.Background(), loc, brdiscard) c.Check(err, check.IsNil) - _, err = volume.BlockRead(context.Background(), loc, io.Discard) + err = volume.BlockRead(context.Background(), loc, brdiscard) c.Check(err, check.IsNil) c.Check(stats(), check.Matches, `.*"InBytes":6,.*`) }