eintopf.info@v0.13.16/service/dbmigration/store_test.go (about)

     1  package dbmigration_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"eintopf.info/service/dbmigration"
     8  	"eintopf.info/test"
     9  )
    10  
    11  func TestStore(t *testing.T) {
    12  	testdb, cleanupDB, err := test.CreateSqliteTestDB(t.Name())
    13  	if err != nil {
    14  		t.Fatal(err)
    15  	}
    16  	t.Cleanup(cleanupDB)
    17  
    18  	store, err := dbmigration.NewSqlStore(testdb)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	hasMigration, err := store.HasMigration(context.Background(), "foo")
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  	if hasMigration {
    28  		t.Fatal("should not have migration")
    29  	}
    30  
    31  	err = store.AddMigration(context.Background(), "foo")
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  
    36  	hasMigration, err = store.HasMigration(context.Background(), "foo")
    37  	if err != nil {
    38  		t.Fatal(err)
    39  	}
    40  	if !hasMigration {
    41  		t.Fatal("should have migration")
    42  	}
    43  }