mukan-ignite/integration/chain/cache_test.go
Mukan Erkin Törük c32551b6f7
Some checks failed
Docs Deploy / build_and_deploy (push) Has been cancelled
Generate Docs / cli (push) Has been cancelled
Generate Config Doc / cli (push) Has been cancelled
Go formatting / go-formatting (push) Has been cancelled
Check links / markdown-link-check (push) Has been cancelled
Integration / pre-test (push) Has been cancelled
Integration / test on (push) Has been cancelled
Integration / status (push) Has been cancelled
Lint / Lint Go code (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
refactor: replace all github.com upstream refs with git.cw.tr/mukan-network
2026-05-11 03:36:24 +03:00

94 lines
2.1 KiB
Go

//go:build !relayer
package chain_test
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/require"
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/cmdrunner/step"
envtest "git.cw.tr/mukan-network/mukan-ignite/integration"
)
func TestCliWithCaching(t *testing.T) {
var (
env = envtest.New(t)
app = env.ScaffoldApp("github.com/test/cacheblog")
vueGenerated = filepath.Join(app.SourcePath(), "vue/src/store/generated")
openapiGenerated = filepath.Join(app.SourcePath(), "docs/static/openapi.json")
typesDir = filepath.Join(app.SourcePath(), "x/cacheblog/types")
servers = app.RandomizeServerPorts()
ctx, cancel = context.WithTimeout(env.Ctx(), envtest.ServeTimeout)
isBackendAliveErr error
)
app.Scaffold(
"create a message",
false,
"message", "mymessage", "myfield1", "myfield2:bool",
)
app.Scaffold("create a query", false, "query", "myQuery", "mytypefield")
env.Must(env.Exec("build",
step.NewSteps(step.New(
step.Exec(
envtest.IgniteApp,
"c",
"build",
),
step.Workdir(app.SourcePath()),
)),
))
app.EnsureSteady()
deleteCachedFiles(t, vueGenerated, openapiGenerated, typesDir)
env.Must(env.Exec("build",
step.NewSteps(step.New(
step.Exec(
envtest.IgniteApp,
"c",
"build",
),
step.Workdir(app.SourcePath()),
)),
))
app.EnsureSteady()
deleteCachedFiles(t, vueGenerated, openapiGenerated, typesDir)
go func() {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers.API)
}()
app.MustServe(ctx)
require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
func deleteCachedFiles(t *testing.T, vueGenerated, openapiGenerated, typesDir string) {
t.Helper()
require.NoError(t, os.RemoveAll(vueGenerated))
require.NoError(t, os.Remove(openapiGenerated))
typesDirEntries, err := os.ReadDir(typesDir)
require.NoError(t, err)
for _, v := range typesDirEntries {
if v.IsDir() {
continue
}
if strings.Contains(v.Name(), ".pb") {
require.NoError(t, os.Remove(filepath.Join(typesDir, v.Name())))
}
}
}