...

Source file src/github.com/cybertec-postgresql/pgwatch/v3/internal/log/log_broker_hook_test.go

Documentation: github.com/cybertec-postgresql/pgwatch/v3/internal/log

     1  package log
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestRemoveSubscriber(t *testing.T) {
    11  	hook := NewBrokerHook(context.Background(), "info")
    12  	msgChan1 := make(MessageChanType)
    13  	msgChan2 := make(MessageChanType)
    14  	hook.AddSubscriber(msgChan1)
    15  	hook.AddSubscriber(msgChan2)
    16  	assert.Equal(t, 2, len(hook.subscribers))
    17  
    18  	// Remove the first subscriber
    19  	hook.RemoveSubscriber(msgChan1)
    20  	assert.Equal(t, 1, len(hook.subscribers))
    21  
    22  	// Remove the last subscriber, this is where the "index out of range" error occurs
    23  	hook.RemoveSubscriber(msgChan2)
    24  	assert.Equal(t, 0, len(hook.subscribers))
    25  }
    26