2022-11-17 20:25:35 +01:00
|
|
|
package store
|
2022-11-17 20:41:07 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPublicFrontend(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)
|
|
|
|
|
|
|
|
feName := "public"
|
|
|
|
feId, err := str.CreateFrontend(envId, &Frontend{
|
2022-11-30 17:52:48 +01:00
|
|
|
Token: "token",
|
2022-11-28 19:55:53 +01:00
|
|
|
ZId: "zId0",
|
|
|
|
PublicName: &feName,
|
2022-11-17 20:41:07 +01:00
|
|
|
}, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
fe, err := str.GetFrontend(feId, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, fe)
|
2022-12-01 20:56:55 +01:00
|
|
|
assert.Equal(t, envId, *fe.EnvironmentId)
|
2022-11-28 19:55:53 +01:00
|
|
|
assert.Equal(t, feName, *fe.PublicName)
|
2023-03-10 17:07:57 +01:00
|
|
|
assert.False(t, fe.Deleted)
|
2022-11-17 20:41:07 +01:00
|
|
|
|
2022-11-28 19:55:53 +01:00
|
|
|
fe0, err := str.FindFrontendPubliclyNamed(feName, tx)
|
2022-11-17 20:41:07 +01:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, fe0)
|
|
|
|
assert.EqualValues(t, fe, fe0)
|
|
|
|
|
|
|
|
err = str.DeleteFrontend(fe.Id, tx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2022-11-30 20:38:49 +01:00
|
|
|
fe0, err = str.FindFrontendWithToken(feName, tx)
|
2022-11-17 20:41:07 +01:00
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Nil(t, fe0)
|
|
|
|
|
|
|
|
fe0, err = str.GetFrontend(fe.Id, tx)
|
2023-03-10 17:07:57 +01:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, fe0)
|
|
|
|
assert.True(t, fe0.Deleted)
|
2022-11-17 20:41:07 +01:00
|
|
|
}
|