mirror of
https://github.com/larksuite/cli.git
synced 2026-07-13 21:24:31 +08:00
test: add create-svglide dry-run e2e
This commit is contained in:
43
tests/cli_e2e/slides/slides_create_svglide_dryrun_test.go
Normal file
43
tests/cli_e2e/slides/slides_create_svglide_dryrun_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package slides
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
clie2e "github.com/larksuite/cli/tests/cli_e2e"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSlidesCreateSVGlideDryRunE2E(t *testing.T) {
|
||||
setSVGlideDryRunConfigEnv(t)
|
||||
dir := prepareSVGlideImageSmokeBundle(t, "Dry SVGlide")
|
||||
|
||||
result, err := clie2e.RunCmd(context.Background(), clie2e.Request{
|
||||
Args: []string{
|
||||
"slides", "+create-svglide",
|
||||
"--manifest", "manifest.json",
|
||||
"--dry-run",
|
||||
},
|
||||
DefaultAs: "user",
|
||||
WorkDir: dir,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, result.RunErr, "stderr:\n%s", result.Stderr)
|
||||
result.AssertExitCode(t, 0)
|
||||
|
||||
assert.True(t, strings.Contains(result.Stdout, `"api"`), result.Stdout)
|
||||
assert.Contains(t, result.Stdout, "/open-apis/slides_ai/v1/xml_presentations")
|
||||
assert.Contains(t, result.Stdout, "/open-apis/drive/v1/medias/upload_all")
|
||||
assert.Contains(t, result.Stdout, "/slide")
|
||||
assert.Contains(t, result.Stdout, "assets/images/hero.png")
|
||||
assert.Contains(t, result.Stdout, "source_sha256")
|
||||
assert.Contains(t, result.Stdout, "submitted_sha256")
|
||||
assert.Contains(t, result.Stdout, "content_omitted")
|
||||
assert.Contains(t, result.Stdout, "page-001")
|
||||
assert.NotContains(t, result.Stdout, "<svg")
|
||||
}
|
||||
97
tests/cli_e2e/slides/slides_create_svglide_helpers_test.go
Normal file
97
tests/cli_e2e/slides/slides_create_svglide_helpers_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package slides
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func prepareSVGlideImageSmokeBundle(t *testing.T, title string) string {
|
||||
t.Helper()
|
||||
root := svglideProjectRoot(t)
|
||||
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "slides"), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "assets", "images"), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "receipts"), 0o755))
|
||||
|
||||
png, err := base64.StdEncoding.DecodeString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "assets", "images", "hero.png"), png, 0o644))
|
||||
|
||||
page := fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:slide="https://slides.bytedance.com/ns" slide:role="slide" id="page-001" viewBox="0 0 960 540">
|
||||
<defs></defs>
|
||||
<rect slide:role="background" x="0" y="0" width="960" height="540" fill="rgba(250,250,248,1)"/>
|
||||
<image slide:role="image" slide:shape-type="image" href="../assets/images/hero.png" x="72" y="132" width="320" height="240"/>
|
||||
<foreignObject slide:role="shape" slide:shape-type="text" x="430" y="148" width="430" height="150" style="font-size:38px;font-family:Arial,sans-serif;color:rgba(20,28,36,1);font-weight:700;line-height:1.15;letter-spacing:0px;padding:0px">
|
||||
<h1 xmlns="http://www.w3.org/1999/xhtml" style="margin:0px;font-size:38px;line-height:1.15;color:rgba(20,28,36,1);letter-spacing:0px">%s</h1>
|
||||
</foreignObject>
|
||||
</svg>`, title)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "slides", "page-001.svg"), []byte(page), 0o644))
|
||||
|
||||
validateOut := runSVGlideNodeTool(t, root, "skills/lark-slides/scripts/validate_svg_deck.mjs", dir, "--json")
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "receipts", "validate_svg_deck.json"), validateOut, 0o644))
|
||||
|
||||
manifest := map[string]any{
|
||||
"version": "svglide.manifest.v1",
|
||||
"protocol": "svg-slides.v1",
|
||||
"title": title,
|
||||
"size": map[string]any{"width": 960, "height": 540},
|
||||
"publish_ready": true,
|
||||
"published": false,
|
||||
"pages": []map[string]any{{
|
||||
"id": "page-001",
|
||||
"index": 1,
|
||||
"file": "slides/page-001.svg",
|
||||
"sha256": sha256HexForE2E([]byte(page)),
|
||||
}},
|
||||
"receipts": map[string]any{"validate_svg_deck": "receipts/validate_svg_deck.json"},
|
||||
}
|
||||
raw, err := json.MarshalIndent(manifest, "", " ")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "manifest.json"), raw, 0o644))
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
func setSVGlideDryRunConfigEnv(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv("LARKSUITE_CLI_APP_ID", "cli_dryrun_test")
|
||||
t.Setenv("LARKSUITE_CLI_APP_SECRET", "dryrun_secret")
|
||||
t.Setenv("LARKSUITE_CLI_BRAND", "feishu")
|
||||
}
|
||||
|
||||
func svglideProjectRoot(t *testing.T) string {
|
||||
t.Helper()
|
||||
_, file, _, ok := runtime.Caller(0)
|
||||
require.True(t, ok)
|
||||
root := filepath.Clean(filepath.Join(filepath.Dir(file), "..", "..", ".."))
|
||||
require.FileExists(t, filepath.Join(root, "go.mod"))
|
||||
return root
|
||||
}
|
||||
|
||||
func runSVGlideNodeTool(t *testing.T, root string, args ...string) []byte {
|
||||
t.Helper()
|
||||
cmd := exec.Command("node", args...)
|
||||
cmd.Dir = root
|
||||
out, err := cmd.CombinedOutput()
|
||||
require.NoErrorf(t, err, "node %v failed:\n%s", args, string(out))
|
||||
return out
|
||||
}
|
||||
|
||||
func sha256HexForE2E(raw []byte) string {
|
||||
sum := sha256.Sum256(raw)
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
Reference in New Issue
Block a user