diff --git a/router/batchrouter/asyncdestinationmanager/clevertap_segment/manager.go b/router/batchrouter/asyncdestinationmanager/clevertap_segment/manager.go index c63524360d..dd2cf23ab1 100644 --- a/router/batchrouter/asyncdestinationmanager/clevertap_segment/manager.go +++ b/router/batchrouter/asyncdestinationmanager/clevertap_segment/manager.go @@ -42,19 +42,19 @@ func NewClevertapBulkUploader( func NewManager(logger logger.Logger, statsFactory stats.Stats, destination *backendconfig.DestinationT, connection *backendconfig.Connection) (common.AsyncDestinationManager, error) { var destConfig DestinationConfig - destConfig, err := Convert[map[string]interface{}, DestinationConfig](destination.Config) + destConfig, err := convert[map[string]interface{}, DestinationConfig](destination.Config) if err != nil { return nil, fmt.Errorf("error in converting destination config: %v", err) } - clevertapConnectionConfig, err := ConvertToConnectionConfig(connection) + clevertapConnectionConfig, err := convertToConnectionConfig(connection) if err != nil { return nil, fmt.Errorf("error converting to connection config for clevertap segment: %v", err) } destName := destination.DestinationDefinition.Name clevertapService := &ClevertapServiceImpl{} - endpoints, err := GetBulkApi(destConfig) + endpoints, err := getBulkApi(destConfig) if err != nil { return nil, fmt.Errorf("error getting bulk api for clevertap segment: %v", err) } diff --git a/router/batchrouter/asyncdestinationmanager/clevertap_segment/upload.go b/router/batchrouter/asyncdestinationmanager/clevertap_segment/upload.go index 23df1866b5..7c68129673 100644 --- a/router/batchrouter/asyncdestinationmanager/clevertap_segment/upload.go +++ b/router/batchrouter/asyncdestinationmanager/clevertap_segment/upload.go @@ -36,7 +36,7 @@ func (*ClevertapBulkUploader) Transform(job *jobsdb.JobT) (string, error) { return common.GetMarshalledData(string(job.EventPayload), job.JobID) } -func (u *ClevertapBulkUploader) PopulateCsvFile(actionFile *ActionFileInfo, line string, data Data) error { +func (u *ClevertapBulkUploader) populateCsvFile(actionFile *ActionFileInfo, line string, data Data) error { newFileSize := actionFile.FileSize + int64(len(line)) if newFileSize < u.fileSizeLimit { actionFile.FileSize = newFileSize @@ -74,7 +74,6 @@ func (u *ClevertapBulkUploader) PopulateCsvFile(actionFile *ActionFileInfo, line actionFile.CSVWriter.Flush() actionFile.SuccessfulJobIDs = append(actionFile.SuccessfulJobIDs, data.Metadata.JobID) } else { - // fmt.println("size exceeding") actionFile.FailedJobIDs = append(actionFile.FailedJobIDs, data.Metadata.JobID) } return nil @@ -95,7 +94,7 @@ func (u *ClevertapBulkUploader) createCSVFile(existingFilePath string) (*ActionF csvFilePath := fmt.Sprintf("%v.csv", path) // Initialize the CSV writer with the generated file path - actionFile, err := CreateCSVWriter(csvFilePath) + actionFile, err := createCSVWriter(csvFilePath) if err != nil { return nil, err } @@ -134,7 +133,7 @@ func (u *ClevertapBulkUploader) createCSVFile(existingFilePath string) (*ActionF payloadSizeStat.Observe(float64(len(data.Message.Fields))) // Populate the CSV file and collect success/failure job IDs - err := u.PopulateCsvFile(actionFile, line, data) + err := u.populateCsvFile(actionFile, line, data) if err != nil { // Collect the failed job ID only if it's valid if data.Metadata.JobID != 0 { // Check if JobID is not zero diff --git a/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils.go b/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils.go index 4797ecbee3..9a74ec70fe 100644 --- a/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils.go +++ b/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils.go @@ -9,7 +9,7 @@ import ( backendconfig "github.com/rudderlabs/rudder-server/backend-config" ) -func CreateCSVWriter(fileName string) (*ActionFileInfo, error) { +func createCSVWriter(fileName string) (*ActionFileInfo, error) { // Open or create the file where the CSV will be written file, err := os.Create(fileName) if err != nil { @@ -27,8 +27,8 @@ func CreateCSVWriter(fileName string) (*ActionFileInfo, error) { }, nil } -func GetBulkApi(destConfig DestinationConfig) (*Endpoints, error) { - endpoint, err := GetCleverTapEndpoint(destConfig.Region) +func getBulkApi(destConfig DestinationConfig) (*Endpoints, error) { + endpoint, err := getCleverTapEndpoint(destConfig.Region) if err != nil { return nil, err } @@ -38,8 +38,8 @@ func GetBulkApi(destConfig DestinationConfig) (*Endpoints, error) { }, nil } -// GetCleverTapEndpoint returns the API endpoint for the given region -func GetCleverTapEndpoint(region string) (string, error) { +// getCleverTapEndpoint returns the API endpoint for the given region +func getCleverTapEndpoint(region string) (string, error) { // Mapping of regions to endpoints endpoints := map[string]string{ "IN": "in1.api.clevertap.com", @@ -67,7 +67,7 @@ type ConfigOutput interface { } // Generic function to convert input to output using JSON marshal/unmarshal -func Convert[T any, U ConfigOutput](input T) (U, error) { +func convert[T any, U ConfigOutput](input T) (U, error) { var output U // Marshal the input to JSON @@ -85,8 +85,8 @@ func Convert[T any, U ConfigOutput](input T) (U, error) { return output, nil } -func ConvertToConnectionConfig(conn *backendconfig.Connection) (ConnectionConfig, error) { - connConfig, err := Convert[map[string]interface{}, ConnectionConfig](conn.Config) +func convertToConnectionConfig(conn *backendconfig.Connection) (ConnectionConfig, error) { + connConfig, err := convert[map[string]interface{}, ConnectionConfig](conn.Config) if err != nil { return ConnectionConfig{}, fmt.Errorf("failed to convert to connection config: %w", err) } diff --git a/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils_test.go b/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils_test.go index 38cdd473f7..bceea4bd5a 100644 --- a/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils_test.go +++ b/router/batchrouter/asyncdestinationmanager/clevertap_segment/utils_test.go @@ -22,7 +22,7 @@ func TestGetCleverTapEndpoint(t *testing.T) { for _, tc := range tests { t.Run(tc.region, func(t *testing.T) { - endpoint, err := GetCleverTapEndpoint(tc.region) + endpoint, err := getCleverTapEndpoint(tc.region) if tc.expectErr { assert.Error(t, err) @@ -38,7 +38,7 @@ func TestGetBulkApi(t *testing.T) { destConfig := DestinationConfig{Region: "IN"} assert.Equal(t, "IN", destConfig.Region) - endpoints, err := GetBulkApi(destConfig) + endpoints, err := getBulkApi(destConfig) assert.Nil(t, err) assert.NotNil(t, endpoints) assert.NotEmpty(t, endpoints.BulkApi) @@ -60,7 +60,9 @@ func TestConvertToConnectionConfig(t *testing.T) { SourceID: "source123", DestinationID: "destination456", Enabled: true, - Config: nil, + Config: map[string]interface{}{ + "invalidKey": make(chan int), // Channels cannot be marshaled to JSON + }, }, expected: expected{ isErr: true, @@ -82,22 +84,21 @@ func TestConvertToConnectionConfig(t *testing.T) { }, expected: expected{ senderName: "Rudderstack", - isErr: false, }, }, } for _, tc := range tests { t.Run("", func(t *testing.T) { - connConfig, err := ConvertToConnectionConfig(tc.conn) + connConfig, err := convertToConnectionConfig(tc.conn) if tc.expected.isErr { assert.Error(t, err) assert.Equal(t, "", connConfig.Config.Destination.SenderName) return } - assert.NoError(t, err) + assert.NoError(t, err) if connConfig.Config.Destination.SenderName == "" { assert.Equal(t, DEFAULT_SENDER_NAME, connConfig.Config.Destination.SenderName) } else {