github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/autoprofile/internal/recorder_test.go (about) 1 // (c) Copyright IBM Corp. 2021 2 // (c) Copyright Instana Inc. 2020 3 4 package internal_test 5 6 import ( 7 "errors" 8 "testing" 9 10 "github.com/instana/go-sensor/autoprofile/internal" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestRecorder_Flush(t *testing.T) { 15 var profiles []internal.AgentProfile 16 17 rec := internal.NewRecorder() 18 rec.SendProfiles = func(p []internal.AgentProfile) error { 19 profiles = p 20 return nil 21 } 22 23 rec.Record(internal.AgentProfile{ID: "1"}) 24 rec.Record(internal.AgentProfile{ID: "2"}) 25 26 rec.Flush() 27 28 assert.Len(t, profiles, 2) 29 30 assert.Equal(t, 0, rec.Size()) 31 } 32 33 func TestRecorder_Flush_Fail(t *testing.T) { 34 rec := internal.NewRecorder() 35 rec.SendProfiles = func(profiles []internal.AgentProfile) error { 36 return errors.New("some error") 37 } 38 39 rec.Record(internal.AgentProfile{ID: "1"}) 40 rec.Record(internal.AgentProfile{ID: "2"}) 41 42 rec.Flush() 43 44 assert.Equal(t, 2, rec.Size()) 45 }