github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/database/migration_test.go (about)

     1  // Copyright 2022 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package database
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/database/testing"
    11  )
    12  
    13  type migrationSuite struct {
    14  	testing.DBSuite
    15  }
    16  
    17  var _ = gc.Suite(&migrationSuite{})
    18  
    19  func (s *migrationSuite) TestMigrationSuccess(c *gc.C) {
    20  	delta := []string{
    21  		"CREATE TABLE band(name TEXT PRIMARY KEY);",
    22  		"INSERT INTO band VALUES ('Blood Incantation');",
    23  	}
    24  
    25  	db := s.DB()
    26  	m := NewDBMigration(db, stubLogger{}, delta)
    27  	c.Assert(m.Apply(), jc.ErrorIsNil)
    28  
    29  	rows, err := db.Query("SELECT * from band;")
    30  	c.Assert(err, jc.ErrorIsNil)
    31  	s.AddCleanup(func(*gc.C) { _ = rows.Close() })
    32  
    33  	var band string
    34  	c.Assert(rows.Next(), jc.IsTrue)
    35  	c.Assert(rows.Scan(&band), jc.ErrorIsNil)
    36  	c.Check(band, gc.Equals, "Blood Incantation")
    37  }