mirror of
https://github.com/larksuite/cli.git
synced 2026-08-03 08:32:46 +08:00
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package plugin_e2e
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// TestMain archives HEAD's committed tree once for the whole package before
|
|
// any fork build runs. It lives here (not in harness.go) because `go test`
|
|
// only discovers TestMain in a _test.go file — a TestMain defined in a plain
|
|
// .go file is silently never invoked.
|
|
// NOTE: exactly one TestMain is allowed per package — do not add another in other _test.go files here.
|
|
func TestMain(m *testing.M) {
|
|
root, err := repoRoot()
|
|
if err != nil {
|
|
panic("locate repo root: " + err.Error())
|
|
}
|
|
baseDir, err = os.MkdirTemp("", "plugin-e2e-")
|
|
if err != nil {
|
|
panic("mkdtemp: " + err.Error())
|
|
}
|
|
cleanTree = filepath.Join(baseDir, "larkcli-clean")
|
|
if err := os.MkdirAll(cleanTree, 0o755); err != nil {
|
|
panic("mkdir clean tree: " + err.Error())
|
|
}
|
|
if err := gitArchive(root, cleanTree); err != nil {
|
|
panic("git archive: " + err.Error())
|
|
}
|
|
code := m.Run()
|
|
_ = os.RemoveAll(baseDir)
|
|
os.Exit(code)
|
|
}
|
|
|
|
// noopPlugin registers a plugin that installs nothing observable, proving
|
|
// the blank-import -> init -> Register -> InstallAll assembly chain links
|
|
// and the fork boots.
|
|
const noopPlugin = `// Code generated by plugin_e2e; DO NOT EDIT.
|
|
package plugin
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/larksuite/cli/extension/platform"
|
|
)
|
|
|
|
func init() {
|
|
platform.Register(
|
|
platform.NewPlugin("smoke", "0.0.1").
|
|
Observer(platform.After, "noop", platform.All(),
|
|
func(_ context.Context, _ platform.Invocation) {}).
|
|
FailOpen().
|
|
MustBuild())
|
|
}
|
|
`
|
|
|
|
func TestSmokeForkBoots(t *testing.T) {
|
|
bin := buildFork(t, "smoke", noopPlugin)
|
|
res := run(t, bin, "--help")
|
|
if res.exit != 0 {
|
|
t.Fatalf("--help exit=%d stderr=%s", res.exit, res.stderr)
|
|
}
|
|
if res.stdout == "" {
|
|
t.Fatalf("--help produced empty stdout")
|
|
}
|
|
}
|