github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/store/nbs/aws_chunk_source_test.go (about)

     1  // Copyright 2019 Dolthub, Inc.
     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  // This file incorporates work covered by the following copyright and
    16  // permission notice:
    17  //
    18  // Copyright 2017 Attic Labs, Inc. All rights reserved.
    19  // Licensed under the Apache License, version 2.0:
    20  // http://www.apache.org/licenses/LICENSE-2.0
    21  
    22  package nbs
    23  
    24  import (
    25  	"context"
    26  	"testing"
    27  
    28  	"github.com/stretchr/testify/assert"
    29  	"github.com/stretchr/testify/require"
    30  )
    31  
    32  func TestAWSChunkSource(t *testing.T) {
    33  	chunks := [][]byte{
    34  		[]byte("hello2"),
    35  		[]byte("goodbye2"),
    36  		[]byte("badbye2"),
    37  	}
    38  	tableData, h, err := buildTable(chunks)
    39  	require.NoError(t, err)
    40  
    41  	s3 := makeFakeS3(t)
    42  
    43  	s3or := &s3ObjectReader{s3, "bucket", nil, ""}
    44  
    45  	makeSrc := func(chunkMax int) chunkSource {
    46  		cs, err := newAWSChunkSource(
    47  			context.Background(),
    48  			s3or,
    49  			awsLimits{},
    50  			h,
    51  			uint32(len(chunks)),
    52  			NewUnlimitedMemQuotaProvider(),
    53  			&Stats{},
    54  		)
    55  
    56  		require.NoError(t, err)
    57  
    58  		return cs
    59  	}
    60  
    61  	t.Run("S3", func(t *testing.T) {
    62  		s3.data[h.String()] = tableData
    63  
    64  		t.Run("Has Chunks", func(t *testing.T) {
    65  			src := makeSrc(len(chunks) - 1)
    66  			assertChunksInReader(chunks, src, assert.New(t))
    67  			src.close()
    68  		})
    69  	})
    70  }