github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/segment/structs/segstructs_test.go (about)

     1  package structs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  /*
    10  	The unit tests will cover different scenarios:
    11  		- when the QueryAggregators instance is nil,
    12  		- when it is not nil but the TransactionArguments field is nil,
    13  		- when both the instance and its TransactionArguments field are not nil.
    14  */
    15  
    16  // Test_HasTransactionArguments_NilReceiver tests the case where the QueryAggregators receiver is nil.
    17  func Test_HasTransactionArguments_NilReceiver(t *testing.T) {
    18  	var qa *QueryAggregators
    19  	assert.Equal(t, false, qa.HasTransactionArguments(), "Expected false for nil receiver, got true")
    20  }
    21  
    22  // Test_HasTransactionArguments_NilTransactionArguments tests the case where TransactionArguments is nil.
    23  func Test_HasTransactionArguments_NilTransactionArguments(t *testing.T) {
    24  	qa := &QueryAggregators{}
    25  	assert.Equal(t, false, qa.HasTransactionArguments(), "Expected false when TransactionArguments is nil, got true")
    26  }
    27  
    28  // Test_HasTransactionArguments_NonNilTransactionArguments tests the case where TransactionArguments is not nil.
    29  func Test_HasTransactionArguments_NonNilTransactionArguments(t *testing.T) {
    30  	transactionArgs := TransactionArguments{
    31  		Fields:     []string{"test1", "test2"},
    32  		StartsWith: nil,
    33  		EndsWith:   nil,
    34  	}
    35  	qa := &QueryAggregators{
    36  		TransactionArguments: &transactionArgs,
    37  	}
    38  	assert.Equal(t, true, qa.HasTransactionArguments(), "Expected true when TransactionArguments is not nil, got false")
    39  }