package observability import ( "os" "testing" "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { os.Exit(m.Run()) } func TestLogIfStateChanged(t *testing.T) { tests := map[string]struct { initialState bool newState bool expectLog bool }{ "Changed": { initialState: true, newState: false, expectLog: true, }, "NotChanged": { initialState: true, newState: true, expectLog: false, }, } for name, tc := range tests { t.Run(name, func(t *testing.T) { stateLogger := StateLogger{ lastState: tc.initialState, log: &spyLogger{}, } stateLogger.LogIfStateChanged(tc.newState) assert.Equal(t, tc.newState, stateLogger.lastState) logger := stateLogger.log.(*spyLogger) assert.Equal(t, tc.expectLog, logger.hasLogged) }) } } type spyLogger struct { hasLogged bool } func (s *spyLogger) Info(_ string, _ ...interface{}) { s.hasLogged = true }