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
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
package plugin_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/cliui"
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/gocmd"
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/services/plugin"
|
|
)
|
|
|
|
const fooBarAppURI = "github.com/foo/bar"
|
|
|
|
func TestScaffold(t *testing.T) {
|
|
// Arrange
|
|
tmp := t.TempDir()
|
|
ctx := context.Background()
|
|
|
|
// Act
|
|
session := cliui.New(cliui.WithoutUserInteraction(true))
|
|
path, err := plugin.Scaffold(ctx, session, tmp, fooBarAppURI, false)
|
|
|
|
// Assert
|
|
require.NoError(t, err)
|
|
require.DirExists(t, path)
|
|
require.FileExists(t, filepath.Join(path, "go.mod"))
|
|
require.FileExists(t, filepath.Join(path, "main.go"))
|
|
}
|
|
|
|
func TestScaffoldedConfig(t *testing.T) {
|
|
// Arrange
|
|
ctx := context.Background()
|
|
path := scaffoldApp(ctx, t, fooBarAppURI)
|
|
|
|
// Act
|
|
cfg := readConfig(t, path)
|
|
|
|
// Assert
|
|
require.EqualValues(t, 1, cfg.Version)
|
|
require.Len(t, cfg.Apps, 1)
|
|
}
|
|
|
|
func TestScaffoldedTests(t *testing.T) {
|
|
// Arrange
|
|
ctx := context.Background()
|
|
path := scaffoldApp(ctx, t, fooBarAppURI)
|
|
path = filepath.Join(path, "integration")
|
|
|
|
// Act
|
|
err := gocmd.Test(ctx, path, []string{
|
|
"-timeout",
|
|
"10m",
|
|
"-run",
|
|
"^TestBar$",
|
|
})
|
|
|
|
// Assert
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func scaffoldApp(ctx context.Context, t *testing.T, path string) string {
|
|
t.Helper()
|
|
|
|
session := cliui.New(cliui.WithoutUserInteraction(true))
|
|
path, err := plugin.Scaffold(ctx, session, t.TempDir(), path, false)
|
|
require.NoError(t, err)
|
|
return path
|
|
}
|
|
|
|
func readConfig(t *testing.T, path string) (cfg plugin.AppsConfig) {
|
|
t.Helper()
|
|
|
|
bz, err := os.ReadFile(filepath.Join(path, "app.ignite.yml"))
|
|
require.NoError(t, err)
|
|
require.NoError(t, yaml.Unmarshal(bz, &cfg))
|
|
return
|
|
}
|