INNER CODE UNIT · Go
TestAppNameEmpty
simagix/hatchet · appname_test.go:36
func TestAppNameEmpty(t *testing.T) {
// Test log without 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","command":{"find":"hatchet","filter":{},"$db":"demo"},"planSummary":"COLLSCAN","keysExamined":0,"docsExamined":100,"numYields":1,"nreturned":100,"reslen":5000,"durationMillis":100}}`
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 empty
if doc.Attributes.AppName != "" {
t.Fatalf("expected empty appName, but got '%v'", doc.Attributes.AppName)
}