mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
parent
1fcb496321
commit
70c99b9791
@ -34,7 +34,7 @@ func (str *Store) GetFrontend(id int, tx *sqlx.Tx) (*Frontend, error) {
|
||||
|
||||
func (str *Store) FindFrontendNamed(name string, tx *sqlx.Tx) (*Frontend, error) {
|
||||
i := &Frontend{}
|
||||
if err := tx.QueryRowx("select frontends.* from frontends where name = $1", name).Scan(i); err != nil {
|
||||
if err := tx.QueryRowx("select frontends.* from frontends where name = $1", name).StructScan(i); err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting frontend by name")
|
||||
}
|
||||
return i, nil
|
||||
|
@ -1 +1,60 @@
|
||||
package store
|
||||
|
||||
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{
|
||||
ZId: "zId0",
|
||||
Name: &feName,
|
||||
}, tx)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fe, err := str.GetFrontend(feId, tx)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, fe)
|
||||
assert.Equal(t, envId, fe.EnvironmentId)
|
||||
assert.Equal(t, feName, *fe.Name)
|
||||
|
||||
fe0, err := str.FindFrontendNamed(feName, tx)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, fe0)
|
||||
assert.EqualValues(t, fe, fe0)
|
||||
|
||||
err = str.DeleteFrontend(fe.Id, tx)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fe0, err = str.FindFrontendNamed(feName, tx)
|
||||
assert.NotNil(t, err)
|
||||
assert.Nil(t, fe0)
|
||||
|
||||
fe0, err = str.GetFrontend(fe.Id, tx)
|
||||
assert.NotNil(t, err)
|
||||
assert.Nil(t, fe0)
|
||||
}
|
||||
|
@ -1,14 +1,5 @@
|
||||
-- +migrate Up
|
||||
|
||||
create table frontends (
|
||||
id serial primary key,
|
||||
environment_id integer not null references environments(id),
|
||||
z_id varchar(32) not null unique,
|
||||
name varchar(64) unique,
|
||||
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
updated_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now'))
|
||||
);
|
||||
|
||||
-- environments.account_id should allow NULL; environments with NULL account_id are "ephemeral"
|
||||
alter table environments rename to environments_old;
|
||||
create table environments (
|
||||
@ -24,4 +15,13 @@ create table environments (
|
||||
constraint chk_z_id check (z_id <> '')
|
||||
);
|
||||
insert into environments select * from environments_old;
|
||||
drop table environments_old;
|
||||
drop table environments_old;
|
||||
|
||||
create table frontends (
|
||||
id integer primary key,
|
||||
environment_id integer not null references environments(id),
|
||||
z_id varchar(32) not null unique,
|
||||
name varchar(64) unique,
|
||||
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
updated_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now'))
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user