Skip to content
Snippets Groups Projects
log_test.go 1.64 KiB
package logs

import (
	"testing"
	"time"

	"git.perx.ru/perxis/perxis-go/id"
	"github.com/stretchr/testify/assert"
)

func TestEntry_ToMap(t *testing.T) {
	type fields struct {
		ID        string
		Timestamp time.Time
		LogLevel  Level
		Message   string
		Category  string
		Component string
		Event     string
		ObjectId  *id.ObjectId
		CallerId  *id.ObjectId
		Attr      interface{}
		Tags      []string
	}
	tests := []struct {
		name   string
		fields fields
		want   map[string]interface{}
	}{
		{
			"#1",
			fields{
				"1",
				time.Time{},
				0,
				"message",
				"",
				"",
				"",
				id.MustObjectId("/spaces/<space_id>/envs/<env_id>"),
				id.MustObjectId("/users/<user_id>"),
				nil,
				nil,
			},
			map[string]interface{}{"caller": map[string]interface{}{"type": "user", "user_id": "<user_id>"}, "caller_id": "/users/<user_id>", "category": "", "component": "", "event": "", "id": "1", "level": Level(0), "message": "message", "object": map[string]interface{}{"env_id": "<env_id>", "space_id": "<space_id>", "type": "environment"}, "object_id": "/spaces/<space_id>/envs/<env_id>", "timestamp": time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			e := &Entry{
				ID:        tt.fields.ID,
				Timestamp: tt.fields.Timestamp,
				Level:     tt.fields.LogLevel,
				Message:   tt.fields.Message,
				Category:  tt.fields.Category,
				Component: tt.fields.Component,
				Event:     tt.fields.Event,
				ObjectID:  tt.fields.ObjectId,
				CallerID:  tt.fields.CallerId,
				Attr:      tt.fields.Attr,
				Tags:      tt.fields.Tags,
			}
			assert.Equal(t, tt.want, e.ToMap())
		})
	}
}