Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

65 lines
1.5 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package output
import (
"bytes"
"testing"
)
func TestModeFromEnv(t *testing.T) {
tests := []struct {
name string
envVal string
want mode
wantWarn bool
}{
{"empty", "", modeOff, false},
{"off", "off", modeOff, false},
{"OFF", "OFF", modeOff, false},
{"warn", "warn", modeWarn, false},
{"WARN", "WARN", modeWarn, false},
{"block", "block", modeBlock, false},
{"unknown", "banana", modeOff, true},
{"whitespace", " warn ", modeWarn, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("LARKSUITE_CLI_CONTENT_SAFETY_MODE", tt.envVal)
var buf bytes.Buffer
got := modeFromEnv(&buf)
if got != tt.want {
t.Errorf("modeFromEnv() = %d, want %d", got, tt.want)
}
if tt.wantWarn && buf.Len() == 0 {
t.Error("expected stderr warning")
}
if !tt.wantWarn && buf.Len() > 0 {
t.Errorf("unexpected stderr: %s", buf.String())
}
})
}
}
func TestNormalizeCommandPath(t *testing.T) {
tests := []struct {
input string
want string
}{
{"lark-cli im +messages-search", "im.messages_search"},
{"lark-cli drive upload +file", "drive.upload.file"},
{"lark-cli api GET /path", "api.GET./path"},
{"lark-cli", ""},
{"", ""},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := normalizeCommandPath(tt.input)
if got != tt.want {
t.Errorf("normalizeCommandPath(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}