github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/core/ledger/kvledger/upgrade_dbs_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package kvledger
     8  
     9  import (
    10  	"fmt"
    11  	"testing"
    12  
    13  	"github.com/osdi23p228/fabric/common/ledger/dataformat"
    14  	"github.com/osdi23p228/fabric/core/ledger/mock"
    15  	"github.com/stretchr/testify/require"
    16  )
    17  
    18  func TestUpgradeWrongFormat(t *testing.T) {
    19  	conf, cleanup := testConfig(t)
    20  	conf.HistoryDBConfig.Enabled = false
    21  	defer cleanup()
    22  	provider := testutilNewProvider(conf, t, &mock.DeployedChaincodeInfoProvider{})
    23  
    24  	// change format to a wrong value to test upgradeFormat error path
    25  	err := provider.idStore.db.Put(formatKey, []byte("x.0"), true)
    26  	provider.Close()
    27  	require.NoError(t, err)
    28  
    29  	err = UpgradeDBs(conf)
    30  	expectedErr := &dataformat.ErrFormatMismatch{
    31  		ExpectedFormat: dataformat.PreviousFormat,
    32  		Format:         "x.0",
    33  		DBInfo:         fmt.Sprintf("leveldb for channel-IDs at [%s]", LedgerProviderPath(conf.RootFSPath)),
    34  	}
    35  	require.EqualError(t, err, expectedErr.Error())
    36  }