2022-01-23 15:01:11 +01:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
func TestMigration_2_8_40_Apply(t *testing.T) {
|
2022-01-23 15:01:11 +01:00
|
|
|
store := CreateTestStore()
|
|
|
|
|
|
|
|
err := store.db.Update(func(tx *bbolt.Tx) error {
|
|
|
|
b, err := tx.CreateBucketIfNotExists([]byte("project"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = b.Put([]byte("0000000001"), []byte("{}"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
r, err := tx.CreateBucketIfNotExists([]byte("project__template_0000000001"))
|
2022-01-23 15:01:11 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = r.Put([]byte("0000000001"),
|
2022-02-03 10:19:35 +01:00
|
|
|
[]byte("{\"id\":\"1\",\"project_id\":\"1\",\"alias\": \"test123\"}"))
|
2022-01-23 15:01:11 +01:00
|
|
|
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
err = migration_2_8_40{migration{store.db}}.Apply()
|
2022-01-23 15:01:11 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var repo map[string]interface{}
|
|
|
|
err = store.db.View(func(tx *bbolt.Tx) error {
|
2022-02-03 08:05:13 +01:00
|
|
|
b := tx.Bucket([]byte("project__template_0000000001"))
|
2022-01-23 15:01:11 +01:00
|
|
|
str := string(b.Get([]byte("0000000001")))
|
|
|
|
return json.Unmarshal([]byte(str), &repo)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
if repo["name"].(string) != "test123" {
|
|
|
|
t.Fatal("invalid name")
|
2022-01-23 15:01:11 +01:00
|
|
|
}
|
|
|
|
|
2022-02-03 10:19:35 +01:00
|
|
|
if repo["alias"] != nil {
|
|
|
|
t.Fatal("alias must be deleted")
|
2022-01-23 15:01:11 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-28 11:45:31 +01:00
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
func TestMigration_2_8_40_Apply2(t *testing.T) {
|
2022-01-28 11:45:31 +01:00
|
|
|
store := CreateTestStore()
|
|
|
|
|
|
|
|
err := store.db.Update(func(tx *bbolt.Tx) error {
|
|
|
|
b, err := tx.CreateBucketIfNotExists([]byte("project"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = b.Put([]byte("0000000001"), []byte("{}"))
|
|
|
|
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
err = migration_2_8_28{migration{store.db}}.Apply()
|
2022-01-28 11:45:31 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|