2022-11-17 18:44:53 +01:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEphemeralEnvironment(t *testing.T) {
|
|
|
|
str, err := Open(&Config{Path: ":memory:", Type: "sqlite3"})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, str)
|
|
|
|
|
|
|
|
tx, err := str.Begin()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, tx)
|
|
|
|
|
|
|
|
envId, err := str.CreateEphemeralEnvironment(&Environment{
|
|
|
|
Description: "description",
|
|
|
|
Host: "host",
|
|
|
|
Address: "address",
|
|
|
|
ZId: "zId0",
|
|
|
|
}, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
env, err := str.GetEnvironment(envId, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, env)
|
|
|
|
assert.Nil(t, env.AccountId)
|
2023-03-10 16:57:59 +01:00
|
|
|
assert.False(t, env.Deleted)
|
2022-11-17 18:44:53 +01:00
|
|
|
}
|
2022-11-17 19:27:57 +01:00
|
|
|
|
|
|
|
func TestEnvironment(t *testing.T) {
|
|
|
|
str, err := Open(&Config{Path: ":memory:", Type: "sqlite3"})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, str)
|
|
|
|
|
|
|
|
tx, err := str.Begin()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, tx)
|
|
|
|
|
|
|
|
acctId, err := str.CreateAccount(&Account{
|
|
|
|
Email: "test@test.com",
|
|
|
|
Password: "password",
|
|
|
|
Token: "token",
|
|
|
|
}, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
envId, err := str.CreateEnvironment(acctId, &Environment{
|
|
|
|
Description: "description",
|
|
|
|
Host: "host",
|
|
|
|
Address: "address",
|
|
|
|
ZId: "zId0",
|
|
|
|
}, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
env, err := str.GetEnvironment(envId, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, env)
|
|
|
|
assert.NotNil(t, env.AccountId)
|
|
|
|
assert.Equal(t, acctId, *env.AccountId)
|
2023-03-10 16:57:59 +01:00
|
|
|
assert.False(t, env.Deleted)
|
2022-11-17 19:27:57 +01:00
|
|
|
}
|