github.com/uber/kraken@v0.1.4/lib/metainfogen/generator_test.go (about)

     1  // Copyright (c) 2016-2019 Uber Technologies, 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  package metainfogen
    15  
    16  import (
    17  	"bytes"
    18  	"testing"
    19  
    20  	"github.com/uber/kraken/core"
    21  	"github.com/uber/kraken/lib/store"
    22  	"github.com/uber/kraken/lib/store/metadata"
    23  
    24  	"github.com/c2h5oh/datasize"
    25  	"github.com/stretchr/testify/require"
    26  )
    27  
    28  func TestGenerate(t *testing.T) {
    29  	require := require.New(t)
    30  
    31  	cas, cleanup := store.CAStoreFixture()
    32  	defer cleanup()
    33  
    34  	pieceLength := 10
    35  
    36  	generator, err := New(Config{
    37  		PieceLengths: map[datasize.ByteSize]datasize.ByteSize{
    38  			0: datasize.ByteSize(pieceLength),
    39  		},
    40  	}, cas)
    41  	require.NoError(err)
    42  
    43  	blob := core.SizedBlobFixture(100, uint64(pieceLength))
    44  
    45  	require.NoError(cas.CreateCacheFile(blob.Digest.Hex(), bytes.NewReader(blob.Content)))
    46  
    47  	require.NoError(generator.Generate(blob.Digest))
    48  
    49  	var tm metadata.TorrentMeta
    50  	require.NoError(cas.GetCacheFileMetadata(blob.Digest.Hex(), &tm))
    51  	require.Equal(blob.MetaInfo, tm.MetaInfo)
    52  }