mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 14:02:43 +08:00
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package schema
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/core"
|
|
)
|
|
|
|
func TestSchemaCmd_FlagParsing(t *testing.T) {
|
|
f, _, _, _ := cmdutil.TestFactory(t, nil)
|
|
|
|
var gotOpts *SchemaOptions
|
|
cmd := NewCmdSchema(f, func(opts *SchemaOptions) error {
|
|
gotOpts = opts
|
|
return nil
|
|
})
|
|
cmd.SetArgs([]string{"calendar.events.list", "--format", "pretty"})
|
|
err := cmd.Execute()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if gotOpts.Path != "calendar.events.list" {
|
|
t.Errorf("expected path calendar.events.list, got %s", gotOpts.Path)
|
|
}
|
|
if gotOpts.Format != "pretty" {
|
|
t.Errorf("expected Format=pretty, got %s", gotOpts.Format)
|
|
}
|
|
}
|
|
|
|
func TestSchemaCmd_NoArgs(t *testing.T) {
|
|
f, stdout, _, _ := cmdutil.TestFactory(t, nil)
|
|
|
|
cmd := NewCmdSchema(f, nil)
|
|
cmd.SetArgs([]string{})
|
|
err := cmd.Execute()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !strings.Contains(stdout.String(), "Available services") {
|
|
t.Error("expected service list output")
|
|
}
|
|
}
|
|
|
|
func TestSchemaCmd_UnknownService(t *testing.T) {
|
|
f, _, _, _ := cmdutil.TestFactory(t, &core.CliConfig{
|
|
AppID: "test-app", AppSecret: "test-secret", Brand: core.BrandFeishu,
|
|
})
|
|
|
|
cmd := NewCmdSchema(f, nil)
|
|
cmd.SetArgs([]string{"nonexistent_service"})
|
|
err := cmd.Execute()
|
|
if err == nil {
|
|
t.Error("expected error for unknown service")
|
|
}
|
|
if !strings.Contains(err.Error(), "Unknown service") {
|
|
t.Errorf("expected 'Unknown service' error, got: %v", err)
|
|
}
|
|
}
|