github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/tests/client_configuration_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/ravendb/ravendb-go-client"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func clientConfigurationCanHandleNoConfiguration(t *testing.T, driver *RavenTestDriver) {
    11  	store := driver.getDocumentStoreMust(t)
    12  	defer store.Close()
    13  
    14  	operation := ravendb.NewGetClientConfigurationOperation()
    15  	err := store.Maintenance().Send(operation)
    16  	assert.NoError(t, err)
    17  	result := operation.Command.Result
    18  	assert.Nil(t, result.Configuration)
    19  	assert.True(t, result.Etag == -2)
    20  }
    21  
    22  func clientConfigurationCanSaveAndReadClientConfiguration(t *testing.T, driver *RavenTestDriver) {
    23  	store := driver.getDocumentStoreMust(t)
    24  	defer store.Close()
    25  
    26  	configurationToSave := &ravendb.ClientConfiguration{
    27  		Etag:                          123,
    28  		MaxNumberOfRequestsPerSession: 80,
    29  		ReadBalanceBehavior:           ravendb.ReadBalanceBehaviorFastestNode,
    30  		IsDisabled:                    true,
    31  	}
    32  
    33  	saveOperation, err := ravendb.NewPutClientConfigurationOperation(configurationToSave)
    34  	assert.NoError(t, err)
    35  	store.Maintenance().Send(saveOperation)
    36  	operation := ravendb.NewGetClientConfigurationOperation()
    37  	err = store.Maintenance().Send(operation)
    38  	assert.NoError(t, err)
    39  	result := operation.Command.Result
    40  	println(result.Etag)
    41  	assert.True(t, result.Etag != 0)
    42  	newConfiguration := result.Configuration
    43  	assert.NotNil(t, newConfiguration)
    44  	assert.True(t, newConfiguration.Etag != configurationToSave.Etag)
    45  	assert.True(t, newConfiguration.IsDisabled)
    46  	assert.Equal(t, newConfiguration.MaxNumberOfRequestsPerSession, 80)
    47  	assert.Equal(t, newConfiguration.ReadBalanceBehavior, ravendb.ReadBalanceBehaviorFastestNode)
    48  }
    49  
    50  func TestClientConfiguration(t *testing.T) {
    51  	driver := createTestDriver(t)
    52  	destroy := func() { destroyDriver(t, driver) }
    53  	defer recoverTest(t, destroy)
    54  
    55  	// matches order of Java tests
    56  	clientConfigurationCanHandleNoConfiguration(t, driver)
    57  	clientConfigurationCanSaveAndReadClientConfiguration(t, driver)
    58  }