processor/trace_test.go GO 118 lines View on github.com → Search inside
1package processor23import (4	"bytes"5	"strings"6	"testing"7)89func TestTraceLevel(t *testing.T) {10	if levelTrace.String() != "TRACE" {11		t.Errorf("traceLevel format error: got %s, want TRACE", levelTrace.String())12	}13	if levelDebug.String() != "DEBUG" {14		t.Errorf("traceLevel format error: got %s, want DEBUG", levelDebug.String())15	}16	if levelWarn.String() != "WARN" {17		t.Errorf("traceLevel format error: got %s, want WARN", levelWarn.String())18	}19	if levelError.String() != "ERROR" {20		t.Errorf("traceLevel format error: got %s, want ERROR", levelError.String())21	}22	if traceLevel(0).String() != "" {23		t.Error("formated unknown traceLevel is not empty")24	}25}2627func TestDoPrint(t *testing.T) {28	testCases := []struct {29		level          traceLevel30		template       string31		args           []any32		expectedPrefix string33		expectedSuffix string34	}{35		{36			level:          levelTrace,37			template:       "test: %d",38			args:           []any{1},39			expectedPrefix: levelTrace.String(),40			expectedSuffix: ": test: 1\n",41		},42		{43			level:          levelWarn,44			template:       "test: %s",45			args:           []any{"message"},46			expectedPrefix: levelWarn.String(),47			expectedSuffix: ": test: message\n",48		},49		{50			level:          levelDebug,51			template:       "test",52			args:           nil,53			expectedPrefix: levelDebug.String(),54			expectedSuffix: ": test\n",55		},56	}57	buff := &bytes.Buffer{}58	for _, tc := range testCases {59		doPrint(buff, tc.level, tc.template, tc.args)60		if !strings.HasPrefix(buff.String(), tc.expectedPrefix) {61			t.Errorf("doPrint got \"%s\", want prefix \"%s\"", buff.String(), tc.expectedPrefix)62		}63		if !strings.HasSuffix(buff.String(), tc.expectedSuffix) {64			t.Errorf("doPrint got \"%s\", want suffix \"%s\"", buff.String(), tc.expectedSuffix)65		}66		buff.Reset()67	}68}6970func TestPrintTrace(t *testing.T) {71	Trace = true72	printTrace("Testing print trace")73	Trace = false74	printTrace("Testing print trace")75}7677func TestPrintDebug(t *testing.T) {78	Debug = true79	printDebug("Testing print debug")80	Debug = false81	printDebug("Testing print debug")82}8384func TestPrintWarn(t *testing.T) {85	Verbose = true86	printWarn("Testing print warn")87	Verbose = false88	printWarn("Testing print warn")89}9091func TestPrintError(t *testing.T) {92	printError("Testing print error")93}9495func TestPrintWarnF(t *testing.T) {96	printWarnF("Testing print error")97}9899func TestPrintDebugF(t *testing.T) {100	printDebugF("Testing print error")101}102103func TestPrintTraceF(t *testing.T) {104	printTraceF("Testing print error")105}106107func TestGetFormattedTime(t *testing.T) {108	res := getFormattedTime()109110	if !strings.Contains(res, "T") {111		t.Error("String does not contain expected T", res)112	}113114	if !strings.Contains(res, "Z") {115		t.Error("String does not contain expected Z", res)116	}117}

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.