github.com/ethersphere/bee/v2@v2.2.0/pkg/storer/migration/all_steps_test.go (about)

     1  // Copyright 2023 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package migration_test
     6  
     7  import (
     8  	"context"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  
    13  	"github.com/ethersphere/bee/v2/pkg/log"
    14  	"github.com/ethersphere/bee/v2/pkg/storage/inmemstore"
    15  	"github.com/ethersphere/bee/v2/pkg/storer/internal"
    16  	"github.com/ethersphere/bee/v2/pkg/storer/internal/transaction"
    17  
    18  	"github.com/ethersphere/bee/v2/pkg/storage/migration"
    19  	localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration"
    20  )
    21  
    22  func TestPreSteps(t *testing.T) {
    23  	t.Parallel()
    24  
    25  	store := internal.NewInmemStorage()
    26  
    27  	assert.NotEmpty(t, localmigration.AfterInitSteps("", 0, store, log.Noop))
    28  
    29  	t.Run("version numbers", func(t *testing.T) {
    30  		t.Parallel()
    31  
    32  		err := migration.ValidateVersions(localmigration.AfterInitSteps("", 0, store, log.Noop))
    33  		assert.NoError(t, err)
    34  	})
    35  
    36  	t.Run("zero store migration", func(t *testing.T) {
    37  		t.Parallel()
    38  
    39  		store := internal.NewInmemStorage()
    40  		err := store.Run(context.Background(), func(s transaction.Store) error {
    41  			return migration.Migrate(s.IndexStore(), "migration", localmigration.AfterInitSteps("", 4, store, log.Noop))
    42  		})
    43  		assert.NoError(t, err)
    44  	})
    45  }
    46  
    47  func TestPostSteps(t *testing.T) {
    48  	t.Parallel()
    49  
    50  	st := inmemstore.New()
    51  
    52  	assert.NotEmpty(t, localmigration.BeforeInitSteps(st))
    53  
    54  	t.Run("version numbers", func(t *testing.T) {
    55  		t.Parallel()
    56  
    57  		err := migration.ValidateVersions(localmigration.BeforeInitSteps(st))
    58  		assert.NoError(t, err)
    59  	})
    60  
    61  	t.Run("zero store migration", func(t *testing.T) {
    62  		t.Parallel()
    63  
    64  		store := inmemstore.New()
    65  
    66  		err := migration.Migrate(store, "migration", localmigration.BeforeInitSteps(store))
    67  		assert.NoError(t, err)
    68  	})
    69  }