mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Add client_error
column to host_disk_encryption_keys
table (#13952)
This commit is contained in:
parent
db8c79aa2a
commit
f0e87737a7
@ -0,0 +1,25 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20230915101341, Down_20230915101341)
|
||||
}
|
||||
|
||||
func Up_20230915101341(tx *sql.Tx) error {
|
||||
stmt := `
|
||||
ALTER TABLE host_disk_encryption_keys
|
||||
ADD COLUMN client_error varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''
|
||||
`
|
||||
if _, err := tx.Exec(stmt); err != nil {
|
||||
return fmt.Errorf("add client_error to host_disk_encryption_keys: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20230915101341(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUp_20230915101341(t *testing.T) {
|
||||
db := applyUpToPrev(t)
|
||||
insertStmt := `
|
||||
INSERT INTO host_disk_encryption_keys
|
||||
(host_id, base64_encrypted)
|
||||
VALUES
|
||||
(?, ?)
|
||||
`
|
||||
execNoErr(t, db, insertStmt, 1, "test-key")
|
||||
|
||||
applyNext(t, db)
|
||||
|
||||
// retrieve the stored value, verify that the new column is present
|
||||
var hdek struct {
|
||||
HostID uint `db:"host_id"`
|
||||
Base64Encrypted string `db:"base64_encrypted"`
|
||||
Decryptable *bool `db:"decryptable"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
ResetRequested bool `db:"reset_requested"`
|
||||
ClientError string `db:"client_error"`
|
||||
}
|
||||
err := db.Get(&hdek, "SELECT * FROM host_disk_encryption_keys WHERE host_id = ?", 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint(1), hdek.HostID)
|
||||
require.Equal(t, "test-key", hdek.Base64Encrypted)
|
||||
require.Nil(t, hdek.Decryptable)
|
||||
require.NotZero(t, hdek.CreatedAt)
|
||||
require.NotZero(t, hdek.UpdatedAt)
|
||||
require.False(t, hdek.ResetRequested)
|
||||
require.Equal(t, "", hdek.ClientError)
|
||||
|
||||
insertStmt = `
|
||||
INSERT INTO host_disk_encryption_keys
|
||||
(host_id, base64_encrypted, client_error)
|
||||
VALUES
|
||||
(?, ?, ?)
|
||||
`
|
||||
execNoErr(t, db, insertStmt, 2, "", "test-error")
|
||||
err = db.Get(&hdek, "SELECT * FROM host_disk_encryption_keys WHERE host_id = ?", 2)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint(2), hdek.HostID)
|
||||
require.Equal(t, "", hdek.Base64Encrypted)
|
||||
require.Nil(t, hdek.Decryptable)
|
||||
require.NotZero(t, hdek.CreatedAt)
|
||||
require.NotZero(t, hdek.UpdatedAt)
|
||||
require.False(t, hdek.ResetRequested)
|
||||
require.Equal(t, "test-error", hdek.ClientError)
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user