Skip to content

Commit

Permalink
chore: naming changes - 1
Browse files Browse the repository at this point in the history
- modify error test case while converting connection config
  • Loading branch information
Sai Sankeerth committed Dec 11, 2024
1 parent 5b71fe9 commit c98f393
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit c98f393

Please sign in to comment.