-
Notifications
You must be signed in to change notification settings - Fork 886
Expand file tree
/
Copy pathdocs_create_dryrun_test.go
More file actions
112 lines (103 loc) · 2.66 KB
/
docs_create_dryrun_test.go
File metadata and controls
112 lines (103 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package docs
import (
"context"
"testing"
"time"
clie2e "github.com/larksuite/cli/tests/cli_e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
)
func TestDocs_CreateV2RejectsLegacyFlagsDryRun(t *testing.T) {
setDocsDryRunEnv(t)
tests := []struct {
name string
args []string
wantErr string
}{
{
name: "markdown",
args: []string{
"docs", "+create",
"--api-version", "v2",
"--markdown", "## legacy",
"--dry-run",
},
wantErr: "use --content with --doc-format markdown",
},
{
name: "wiki node",
args: []string{
"docs", "+create",
"--api-version", "v2",
"--content", "<title>内容</title><p>正文</p>",
"--wiki-node", "wikcn_legacy_node",
"--dry-run",
},
wantErr: "use --parent-token",
},
{
name: "title",
args: []string{
"docs", "+create",
"--api-version", "v2",
"--content", "<p>正文</p>",
"--title", "Legacy title",
"--dry-run",
},
wantErr: "include the document title in --content",
},
{
name: "folder token",
args: []string{
"docs", "+create",
"--api-version", "v2",
"--content", "<title>内容</title><p>正文</p>",
"--folder-token", "fldcn_legacy_folder",
"--dry-run",
},
wantErr: "use --parent-token",
},
{
name: "wiki space",
args: []string{
"docs", "+create",
"--api-version", "v2",
"--content", "<title>内容</title><p>正文</p>",
"--wiki-space", "my_library",
"--dry-run",
},
wantErr: "use --parent-position or --parent-token",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Cleanup(cancel)
result, err := clie2e.RunCmd(ctx, clie2e.Request{
Args: tt.args,
DefaultAs: "bot",
})
require.NoError(t, err)
result.AssertExitCode(t, 2)
assert.Contains(t, docsValidationErrorMessage(result), tt.wantErr)
assert.Equal(t, int64(0), gjson.Get(result.Stdout, "api.#").Int(),
"validation failure must not produce dry-run API calls, stdout:\n%s", result.Stdout)
})
}
}
func setDocsDryRunEnv(t *testing.T) {
t.Helper()
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
t.Setenv("LARKSUITE_CLI_APP_ID", "docs_dryrun_e2e_app")
t.Setenv("LARKSUITE_CLI_APP_SECRET", "docs_dryrun_e2e_secret")
t.Setenv("LARKSUITE_CLI_BRAND", "feishu")
}
func docsValidationErrorMessage(r *clie2e.Result) string {
if msg := gjson.Get(r.Stdout, "error.message").String(); msg != "" {
return msg
}
return gjson.Get(r.Stderr, "error.message").String()
}