Files
larksuite--cli/shortcuts/apps/apps_output_schema_test.go
wehub-resource-sync bf9395e022
CI / results (push) Blocked by required conditions
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / e2e-live (push) Waiting to run
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 / deadcode (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

57 lines
1.7 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package apps
import (
"strings"
"testing"
"time"
)
func TestAppsOutputSchemaProjectsAndFormats(t *testing.T) {
row := map[string]interface{}{
"timestamp_ns": "1782209472123456789",
"level": "ERROR",
"extra": "ignored",
"attributes": map[string]interface{}{
"module": "frontend",
"duration_ms": "1234.5",
},
}
schema := appsOutputSchema{
Columns: []appsOutputColumn{
{Key: "timestamp_ns", Label: "time", Format: appsFormatNS("2006-01-02 15:04:05.000")},
{Key: "module", Value: appsAttrValue("module")},
{Key: "duration_ms", Value: appsAttrValue("duration_ms"), Format: appsFormatDurationMS},
{Key: "level"},
},
Strict: true,
}
projected := appsProjectRow(row, schema)
if len(projected) != 4 {
t.Fatalf("projected field count = %d, want 4: %#v", len(projected), projected)
}
if projected["module"] != "frontend" || projected["duration_ms"] != "1234.5" {
t.Fatalf("projected derived fields = %#v", projected)
}
if _, ok := projected["extra"]; ok {
t.Fatalf("strict projection should drop extra field: %#v", projected)
}
var b strings.Builder
appsPrintSchemaTable(&b, []map[string]interface{}{projected}, schema)
out := b.String()
wantTime := time.Unix(0, 1782209472123456789).Local().Format("2006-01-02 15:04:05.000")
if !strings.HasPrefix(out, "time") {
t.Fatalf("pretty output should start with schema label time, got:\n%s", out)
}
if !strings.Contains(out, wantTime) {
t.Fatalf("pretty output missing formatted time %q:\n%s", wantTime, out)
}
if strings.Contains(out, "1782209472123456789") {
t.Fatalf("pretty output should not contain raw timestamp:\n%s", out)
}
}