Skip to content

Commit

Permalink
test for options
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Aug 11, 2024
1 parent 98c64ad commit 5d510ec
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
package backup

import (
"log/slog"
"strings"
"testing"

"github.com/aerospike/backup-go/mocks"
"github.com/stretchr/testify/assert"
"golang.org/x/sync/semaphore"
)

func TestPartitionRange_validate(t *testing.T) {
Expand Down Expand Up @@ -81,3 +87,28 @@ func TestPartitionRange_validate(t *testing.T) {
})
}
}

func TestNilClient(t *testing.T) {
_, err := NewClient(nil)
assert.Error(t, err, "aerospike client is required")
}

func TestClientOptions(t *testing.T) {
var logBuffer strings.Builder
logger := slog.New(slog.NewTextHandler(&logBuffer, nil))
sem := semaphore.NewWeighted(10)
id := "ID"

client, err := NewClient(&mocks.MockAerospikeClient{},
WithID(id),
WithLogger(logger),
WithScanLimiter(sem),
)

assert.NoError(t, err)
assert.Equal(t, id, client.id)
assert.Equal(t, sem, client.scanLimiter)

client.logger.Info("test")
assert.Contains(t, logBuffer.String(), "level=INFO msg=test backup.client.id=ID")
}

0 comments on commit 5d510ec

Please sign in to comment.