github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/debug/log/memory/memory_test.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); 2 // you may not use this file except in compliance with the License. 3 // You may obtain a copy of the License at 4 // 5 // https://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, 9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 // 13 // Original source: github.com/micro/go-micro/v3/debug/log/memory/memory_test.go 14 15 package memory 16 17 import ( 18 "reflect" 19 "testing" 20 21 "github.com/tickoalcantara12/micro/v3/service/debug/log" 22 ) 23 24 func TestLogger(t *testing.T) { 25 // set size to some value 26 size := 100 27 // override the global logger 28 lg := NewLog(log.Size(size)) 29 // make sure we have the right size of the logger ring buffer 30 if lg.(*memoryLog).Size() != size { 31 t.Errorf("expected buffer size: %d, got: %d", size, lg.(*memoryLog).Size()) 32 } 33 34 // Log some cruft 35 lg.Write(log.Record{Message: "foobar"}) 36 lg.Write(log.Record{Message: "foo bar"}) 37 38 // Check if the logs are stored in the logger ring buffer 39 expected := []string{"foobar", "foo bar"} 40 entries, _ := lg.Read(log.Count(len(expected))) 41 for i, entry := range entries { 42 if !reflect.DeepEqual(entry.Message, expected[i]) { 43 t.Errorf("expected %s, got %s", expected[i], entry.Message) 44 } 45 } 46 }