INNER CODE UNIT · Go

TestAppNameParsing

simagix/hatchet · appname_test.go:15

func TestAppNameParsing(t *testing.T) {
	// Test log with appName
	str := `{"t":{"$date":"2021-07-25T09:38:57.078+00:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"conn541","msg":"Slow query","attr":{"type":"command","ns":"demo.hatchet","appName":"Keyhole Lib","command":{"aggregate":"hatchet","allowDiskUse":true,"pipeline":[{"$match":{"status":{"$in":["completed","split","splitting"]}}}],"cursor":{},"$db":"demo"},"planSummary":"IXSCAN { status: 1 }","keysExamined":218,"docsExamined":217,"numYields":6,"nreturned":53,"reslen":6117,"durationMillis":530}}`

	doc := Logv2Info{}
	err := bson.UnmarshalExtJSON([]byte(str), false, &doc)
	if err != nil {
		t.Fatalf("bson unmarshal error %v", err)
	}

	// Parse attributes
	b, _ := bson.Marshal(doc.Attr)
	bson.Unmarshal(b, &doc.Attributes)

	// Verify appName is parsed correctly
	if doc.Attributes.AppName != "Keyhole Lib" {
		t.Fatalf("expected appName 'Keyhole Lib', but got '%v'", doc.Attributes.AppName)
	}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…