MSP-5013 fix get by name
This commit is contained in:
1 parent
efc4a4ee38
commit
7852772e9d
6 files changed
+116
-23
No files matched your search
+41
-22
@@ -23,26 +23,7 @@ import (
|
||||
//nolint:funlen
|
||||
func TestAcceptance(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
t.Setenv("APP_CONFIG_PATH", "../conf/config.yml")
|
||||
t.Setenv("DefaultRemoteConfigPath", "../conf/default_remote_config.json")
|
||||
boot := bootstrap.New("1.0.0", conf.Remote{}, nil)
|
||||
boot.MigrationsDir = "../migrations"
|
||||
dataPath := dataDir(t)
|
||||
boot.App.Config().Set("rqlite.DataPath", dataPath)
|
||||
logger := boot.App.Logger()
|
||||
|
||||
startup, err := startup.New(boot)
|
||||
require.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
for _, closer := range startup.Closers() {
|
||||
err := closer.Close()
|
||||
require.NoError(err)
|
||||
}
|
||||
})
|
||||
err = startup.Run(context.Background())
|
||||
require.NoError(err)
|
||||
time.Sleep(1 * time.Second)
|
||||
logger := setupTest(t)
|
||||
|
||||
clientA1 := newClusterClient("A", "10.2.9.1", logger)
|
||||
go func() {
|
||||
@@ -142,7 +123,17 @@ func newClusterClient(
|
||||
host string,
|
||||
logger log.Logger,
|
||||
) *cluster.Client {
|
||||
schema := schema.NewGenerator().Generate(testModuleRemoteConfig{})
|
||||
return newClusterClientWith(moduleName, host, testModuleRemoteConfig{}, []byte("{}"), logger)
|
||||
}
|
||||
|
||||
func newClusterClientWith(
|
||||
moduleName string,
|
||||
host string,
|
||||
config any,
|
||||
defaultRemoteConfig []byte,
|
||||
logger log.Logger,
|
||||
) *cluster.Client {
|
||||
schema := schema.NewGenerator().Generate(config)
|
||||
schemaData, err := json.Marshal(schema)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -159,6 +150,34 @@ func newClusterClient(
|
||||
}, cluster.ConfigData{
|
||||
Version: "1.0.0",
|
||||
Schema: schemaData,
|
||||
Config: []byte(`{}`),
|
||||
Config: defaultRemoteConfig,
|
||||
}, []string{"127.0.0.1:9001"}, logger)
|
||||
}
|
||||
|
||||
//nolint:ireturn
|
||||
func setupTest(t *testing.T) log.Logger {
|
||||
t.Helper()
|
||||
require := require.New(t)
|
||||
|
||||
t.Setenv("APP_CONFIG_PATH", "../conf/config.yml")
|
||||
t.Setenv("DefaultRemoteConfigPath", "../conf/default_remote_config.json")
|
||||
boot := bootstrap.New("1.0.0", conf.Remote{}, nil)
|
||||
boot.MigrationsDir = "../migrations"
|
||||
dataPath := dataDir(t)
|
||||
boot.App.Config().Set("rqlite.DataPath", dataPath)
|
||||
logger := boot.App.Logger()
|
||||
|
||||
startup, err := startup.New(boot)
|
||||
require.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
for _, closer := range startup.Closers() {
|
||||
err := closer.Close()
|
||||
require.NoError(err)
|
||||
}
|
||||
})
|
||||
err = startup.Run(context.Background())
|
||||
require.NoError(err)
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
return logger
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/txix-open/isp-kit/cluster"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test/fake"
|
||||
"isp-config-service/domain"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const defaultRemoteConfigsWithVariables = `
|
||||
{
|
||||
"varA": "_Var({{ .varA }})",
|
||||
"varB": "_ToInt(_Var({{ .varB }}))"
|
||||
}
|
||||
`
|
||||
|
||||
type configWithVars struct {
|
||||
VarA string
|
||||
VarB int
|
||||
}
|
||||
|
||||
func TestVariableAcceptance(t *testing.T) {
|
||||
require := require.New(t)
|
||||
logger := setupTest(t)
|
||||
|
||||
apiCli, err := client.Default()
|
||||
require.NoError(err)
|
||||
apiCli.Upgrade([]string{"127.0.0.1:9002"})
|
||||
err = apiCli.Invoke("config/variable/create").
|
||||
JsonRequestBody(domain.CreateVariableRequest{
|
||||
Name: "varA",
|
||||
Description: fake.It[string](),
|
||||
Type: "TEXT",
|
||||
Value: fake.It[string](),
|
||||
}).Do(context.Background())
|
||||
require.NoError(err)
|
||||
|
||||
err = apiCli.Invoke("config/variable/upsert").
|
||||
JsonRequestBody([]domain.UpsertVariableRequest{{
|
||||
Name: "varB",
|
||||
Description: "test",
|
||||
Type: "SECRET",
|
||||
Value: strconv.Itoa(fake.It[int]()),
|
||||
}}).
|
||||
Do(context.Background())
|
||||
require.NoError(err)
|
||||
|
||||
clientA1 := newClusterClientWith(
|
||||
"A",
|
||||
"10.2.9.1",
|
||||
configWithVars{},
|
||||
[]byte(defaultRemoteConfigsWithVariables),
|
||||
logger)
|
||||
go func() {
|
||||
handler := cluster.NewEventHandler()
|
||||
err := clientA1.Run(context.Background(), handler)
|
||||
require.NoError(err) //nolint:testifylint
|
||||
}()
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
Reference in new issue
Block a user