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":1,"group":"test-group-a"},{"channel_id":27,"group":"test-group-b"}],"private":"secret"},"root_info":{"private":"secret"}}`
|
|
logs := []*Log{
|
|
{Type: LogTypeError, ChannelId: 27, Group: "default", Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 1, Group: "default", Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 0, Group: "default", Other: metadata},
|
|
{Type: LogTypeConsume, ChannelId: 27, Group: "billed-group", Quota: 799463, Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 99, Group: "legacy", Other: metadata},
|
|
{Type: LogTypeError, ChannelId: 27, Group: "legacy", Other: `invalid`},
|
|
}
|
|
format.fn(logs)
|
|
for i, want := range []string{"test-group-b", "test-group-a", "", "billed-group", "legacy", "legacy"} {
|
|
require.Equal(t, want, logs[i].Group)
|
|
}
|
|
require.Equal(t, 799463, 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, "test-group-b", logs[0].Group)
|
|
})
|
|
}
|
|
}
|