Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package model
|
|
|
|
import (
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func TestErrorLogGroupProjection(t *testing.T) {
|
|
for _, format := range []struct {
|
|
name string
|
|
fn func([]*Log)
|
|
}{
|
|
{"root", FormatRootLogs}, {"admin", FormatAdminLogs}, {"user", func(logs []*Log) { formatUserLogs(logs, 0) }},
|
|
} {
|
|
t.Run(format.name, func(t *testing.T) {
|
|
metadata := `{"admin_info":{"request_policy":[{"channel_id":101,"group":"example-primary"},{"channel_id":102,"group":"example-preferred"}],"private":"secret"},"root_info":{"private":"secret"}}`
|
|
logs := []*Log{
|
|
{Type: LogTypeError, ChannelId: 102, Group: "default", Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 101, Group: "default", Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 0, Group: "default", Other: metadata},
|
|
{Type: LogTypeConsume, ChannelId: 102, Group: "billed-group", Quota: 12345, Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 99, Group: "legacy", Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 102, Group: "legacy", Other: `invalid`},
|
|
}
|
|
format.fn(logs)
|
|
for i, want := range []string{"example-preferred", "example-primary", "", "billed-group", "legacy", "legacy"} {
|
|
require.Equal(t, want, logs[i].Group)
|
|
}
|
|
require.Equal(t, 12345, logs[3].Quota)
|
|
if format.name == "user" {
|
|
require.NotContains(t, logs[0].Other, "secret")
|
|
require.NotContains(t, logs[0].Other, "request_policy")
|
|
}
|
|
format.fn(logs)
|
|
require.Equal(t, "example-preferred", logs[0].Group)
|
|
})
|
|
}
|
|
}
|