From 9ae95d387ee4c1e59a7ac3cebcd7d2f554fbd8e7 Mon Sep 17 00:00:00 2001 From: nickolasdaniel Date: Mon, 8 Nov 2021 16:59:57 +0200 Subject: [PATCH] Tests for config --- config/erscfg_test.go | 194 +++++++++++++++++++++++++++++++++++ engine/model_helpers_test.go | 4 +- 2 files changed, 196 insertions(+), 2 deletions(-) diff --git a/config/erscfg_test.go b/config/erscfg_test.go index 38a2fa57b..98430044a 100644 --- a/config/erscfg_test.go +++ b/config/erscfg_test.go @@ -2230,3 +2230,197 @@ func TestERsAsMapInterface(t *testing.T) { t.Errorf("Expected %v \n but received \n %v", exp[utils.OptsCfg], rcv[utils.OptsCfg]) } } + +func TestDiffEventReaderOptsJsonCfg(t *testing.T) { + var d *EventReaderOptsJson + + v1 := &EventReaderOpts{ + PartialPath: utils.StringPointer("/tmp/path/diff"), + PartialCacheAction: utils.StringPointer("partial_cache_action_diff"), + PartialOrderField: utils.StringPointer("partial_order_field_diff"), + PartialCSVFieldSeparator: utils.StringPointer(";_diff"), + CSVRowLength: utils.IntPointer(3), + CSVFieldSeparator: utils.StringPointer(",_diff"), + CSVHeaderDefineChar: utils.StringPointer("header_define_char_diff"), + CSVLazyQuotes: utils.BoolPointer(true), + XMLRootPath: utils.StringPointer("xml_root_path_diff"), + AMQPQueueID: utils.StringPointer("queue_id_diff"), + AMQPQueueIDProcessed: utils.StringPointer("queue_id_processed_diff"), + AMQPConsumerTag: utils.StringPointer("consumer_tag_diff"), + AMQPExchange: utils.StringPointer("exchange_diff"), + AMQPExchangeType: utils.StringPointer("exchange_type_diff"), + AMQPRoutingKey: utils.StringPointer("routing_key_diff"), + AMQPExchangeProcessed: utils.StringPointer("exchange_processed_diff"), + AMQPExchangeTypeProcessed: utils.StringPointer("excange_type_processed_diff"), + AMQPRoutingKeyProcessed: utils.StringPointer("routing_key_processed_diff"), + KafkaTopic: utils.StringPointer("topic_diff"), + KafkaGroupID: utils.StringPointer("group_id_diff"), + KafkaMaxWait: utils.DurationPointer(3 * time.Second), + KafkaTopicProcessed: utils.StringPointer("topic_processed_diff"), + SQLDBName: utils.StringPointer("cgrates_diff"), + SQLTableName: utils.StringPointer("cgrates_t1_diff"), + SSLMode: utils.StringPointer("ssl_mode_diff"), + SQLDBNameProcessed: utils.StringPointer("cgrates_processed_diff"), + SQLTableNameProcessed: utils.StringPointer("cgrates_t1_processed_diff"), + SSLModeProcessed: utils.StringPointer("ssl_mode_processed_diff"), + AWSRegion: utils.StringPointer("us-west_diff"), + AWSKey: utils.StringPointer("aws_key_diff"), + AWSSecret: utils.StringPointer("aws_secret_diff"), + AWSToken: utils.StringPointer("aws_token_diff"), + AWSRegionProcessed: utils.StringPointer("region_processed_diff"), + AWSKeyProcessed: utils.StringPointer("aws_key_processed_diff"), + AWSSecretProcessed: utils.StringPointer("aws_secret_processed_diff"), + AWSTokenProcessed: utils.StringPointer("aws_token_processed_diff"), + SQSQueueID: utils.StringPointer("queue_id_diff"), + SQSQueueIDProcessed: utils.StringPointer("queue_id_processed_diff"), + S3BucketID: utils.StringPointer("bucket_id_diff"), + S3FolderPathProcessed: utils.StringPointer("folder_path_processed_diff"), + S3BucketIDProcessed: utils.StringPointer("bucket_id_processed_diff"), + NATSJetStream: utils.BoolPointer(true), + NATSConsumerName: utils.StringPointer("consumer_name_diff"), + NATSSubject: utils.StringPointer("subject_diff"), + NATSQueueID: utils.StringPointer("queue_id_diff"), + NATSJWTFile: utils.StringPointer("jsw_file_diff"), + NATSSeedFile: utils.StringPointer("seed_file_diff"), + NATSCertificateAuthority: utils.StringPointer("ca_diff"), + NATSClientCertificate: utils.StringPointer("cc_diff"), + NATSClientKey: utils.StringPointer("ck_diff"), + NATSJetStreamMaxWait: utils.DurationPointer(5 * time.Second), + NATSJetStreamProcessed: utils.BoolPointer(true), + NATSSubjectProcessed: utils.StringPointer("subject_processed_diff"), + NATSJWTFileProcessed: utils.StringPointer("jwt_file_processed_diff"), + NATSSeedFileProcessed: utils.StringPointer("seed_file_processed_diff"), + NATSCertificateAuthorityProcessed: utils.StringPointer("ca_processed_diff"), + NATSClientCertificateProcessed: utils.StringPointer("cc_processed_diff"), + NATSClientKeyProcessed: utils.StringPointer("ck_processed_diff"), + NATSJetStreamMaxWaitProcessed: utils.DurationPointer(6 * time.Second), + } + + v2 := &EventReaderOpts{ + PartialPath: utils.StringPointer("/tmp/path"), + PartialCacheAction: utils.StringPointer("partial_cache_action"), + PartialOrderField: utils.StringPointer("partial_order_field"), + PartialCSVFieldSeparator: utils.StringPointer(";"), + CSVRowLength: utils.IntPointer(2), + CSVFieldSeparator: utils.StringPointer(","), + CSVHeaderDefineChar: utils.StringPointer("header_define_char"), + CSVLazyQuotes: utils.BoolPointer(false), + XMLRootPath: utils.StringPointer("xml_root_path"), + AMQPQueueID: utils.StringPointer("queue_id"), + AMQPQueueIDProcessed: utils.StringPointer("queue_id_processed"), + AMQPConsumerTag: utils.StringPointer("consumer_tag"), + AMQPExchange: utils.StringPointer("exchange"), + AMQPExchangeType: utils.StringPointer("exchange_type"), + AMQPRoutingKey: utils.StringPointer("routing_key"), + AMQPExchangeProcessed: utils.StringPointer("exchange_processed"), + AMQPExchangeTypeProcessed: utils.StringPointer("excange_type_processed"), + AMQPRoutingKeyProcessed: utils.StringPointer("routing_key_processed"), + KafkaTopic: utils.StringPointer("topic"), + KafkaGroupID: utils.StringPointer("group_id"), + KafkaMaxWait: utils.DurationPointer(2 * time.Second), + KafkaTopicProcessed: utils.StringPointer("topic_processed"), + SQLDBName: utils.StringPointer("cgrates"), + SQLTableName: utils.StringPointer("cgrates_t1"), + SSLMode: utils.StringPointer("ssl_mode"), + SQLDBNameProcessed: utils.StringPointer("cgrates_processed"), + SQLTableNameProcessed: utils.StringPointer("cgrates_t1_processed"), + SSLModeProcessed: utils.StringPointer("ssl_mode_processed"), + AWSRegion: utils.StringPointer("us-west"), + AWSKey: utils.StringPointer("aws_key"), + AWSSecret: utils.StringPointer("aws_secret"), + AWSToken: utils.StringPointer("aws_token"), + AWSRegionProcessed: utils.StringPointer("region_processed"), + AWSKeyProcessed: utils.StringPointer("aws_key_processed"), + AWSSecretProcessed: utils.StringPointer("aws_secret_processed"), + AWSTokenProcessed: utils.StringPointer("aws_token_processed"), + SQSQueueID: utils.StringPointer("queue_id"), + SQSQueueIDProcessed: utils.StringPointer("queue_id_processed"), + S3BucketID: utils.StringPointer("bucket_id"), + S3FolderPathProcessed: utils.StringPointer("folder_path_processed"), + S3BucketIDProcessed: utils.StringPointer("bucket_id_processed"), + NATSJetStream: utils.BoolPointer(false), + NATSConsumerName: utils.StringPointer("consumer_name"), + NATSSubject: utils.StringPointer("subject"), + NATSQueueID: utils.StringPointer("queue_id"), + NATSJWTFile: utils.StringPointer("jsw_file"), + NATSSeedFile: utils.StringPointer("seed_file"), + NATSCertificateAuthority: utils.StringPointer("ca"), + NATSClientCertificate: utils.StringPointer("cc"), + NATSClientKey: utils.StringPointer("ck"), + NATSJetStreamMaxWait: utils.DurationPointer(2 * time.Second), + NATSJetStreamProcessed: utils.BoolPointer(false), + NATSSubjectProcessed: utils.StringPointer("subject_processed"), + NATSJWTFileProcessed: utils.StringPointer("jwt_file_processed"), + NATSSeedFileProcessed: utils.StringPointer("seed_file_processed"), + NATSCertificateAuthorityProcessed: utils.StringPointer("ca_processed"), + NATSClientCertificateProcessed: utils.StringPointer("cc_processed"), + NATSClientKeyProcessed: utils.StringPointer("ck_processed"), + NATSJetStreamMaxWaitProcessed: utils.DurationPointer(2 * time.Second), + } + + exp := &EventReaderOptsJson{ + PartialPath: utils.StringPointer("/tmp/path"), + PartialCacheAction: utils.StringPointer("partial_cache_action"), + PartialOrderField: utils.StringPointer("partial_order_field"), + PartialCSVFieldSeparator: utils.StringPointer(";"), + CSVRowLength: utils.IntPointer(2), + CSVFieldSeparator: utils.StringPointer(","), + CSVHeaderDefineChar: utils.StringPointer("header_define_char"), + CSVLazyQuotes: utils.BoolPointer(false), + XMLRootPath: utils.StringPointer("xml_root_path"), + AMQPQueueID: utils.StringPointer("queue_id"), + AMQPQueueIDProcessed: utils.StringPointer("queue_id_processed"), + AMQPConsumerTag: utils.StringPointer("consumer_tag"), + AMQPExchange: utils.StringPointer("exchange"), + AMQPExchangeType: utils.StringPointer("exchange_type"), + AMQPRoutingKey: utils.StringPointer("routing_key"), + AMQPExchangeProcessed: utils.StringPointer("exchange_processed"), + AMQPExchangeTypeProcessed: utils.StringPointer("excange_type_processed"), + AMQPRoutingKeyProcessed: utils.StringPointer("routing_key_processed"), + KafkaTopic: utils.StringPointer("topic"), + KafkaGroupID: utils.StringPointer("group_id"), + KafkaMaxWait: utils.StringPointer("2s"), + KafkaTopicProcessed: utils.StringPointer("topic_processed"), + SQLDBName: utils.StringPointer("cgrates"), + SQLTableName: utils.StringPointer("cgrates_t1"), + SSLMode: utils.StringPointer("ssl_mode"), + SQLDBNameProcessed: utils.StringPointer("cgrates_processed"), + SQLTableNameProcessed: utils.StringPointer("cgrates_t1_processed"), + SSLModeProcessed: utils.StringPointer("ssl_mode_processed"), + AWSRegion: utils.StringPointer("us-west"), + AWSKey: utils.StringPointer("aws_key"), + AWSSecret: utils.StringPointer("aws_secret"), + AWSToken: utils.StringPointer("aws_token"), + AWSRegionProcessed: utils.StringPointer("region_processed"), + AWSKeyProcessed: utils.StringPointer("aws_key_processed"), + AWSSecretProcessed: utils.StringPointer("aws_secret_processed"), + AWSTokenProcessed: utils.StringPointer("aws_token_processed"), + SQSQueueID: utils.StringPointer("queue_id"), + SQSQueueIDProcessed: utils.StringPointer("queue_id_processed"), + S3BucketID: utils.StringPointer("bucket_id"), + S3FolderPathProcessed: utils.StringPointer("folder_path_processed"), + S3BucketIDProcessed: utils.StringPointer("bucket_id_processed"), + NATSJetStream: utils.BoolPointer(false), + NATSConsumerName: utils.StringPointer("consumer_name"), + NATSSubject: utils.StringPointer("subject"), + NATSQueueID: utils.StringPointer("queue_id"), + NATSJWTFile: utils.StringPointer("jsw_file"), + NATSSeedFile: utils.StringPointer("seed_file"), + NATSCertificateAuthority: utils.StringPointer("ca"), + NATSClientCertificate: utils.StringPointer("cc"), + NATSClientKey: utils.StringPointer("ck"), + NATSJetStreamMaxWait: utils.StringPointer("2s"), + NATSJetStreamProcessed: utils.BoolPointer(false), + NATSSubjectProcessed: utils.StringPointer("subject_processed"), + NATSJWTFileProcessed: utils.StringPointer("jwt_file_processed"), + NATSSeedFileProcessed: utils.StringPointer("seed_file_processed"), + NATSCertificateAuthorityProcessed: utils.StringPointer("ca_processed"), + NATSClientCertificateProcessed: utils.StringPointer("cc_processed"), + NATSClientKeyProcessed: utils.StringPointer("ck_processed"), + NATSJetStreamMaxWaitProcessed: utils.StringPointer("2s"), + } + + if rcv := diffEventReaderOptsJsonCfg(d, v1, v2); !reflect.DeepEqual(rcv, exp) { + t.Errorf("Expected %v \n but received \n %v", exp, rcv) + } +} diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 4879cdcd9..15eaa9e44 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -834,7 +834,7 @@ func TestTPFilterAsTPFilter3(t *testing.T) { { Type: utils.MetaPrefix, Element: "Account", - Values: []string{"1001", "1002"}, + Values: []string{"1001", "1001"}, }, }, }, @@ -854,7 +854,7 @@ func TestTPFilterAsTPFilter3(t *testing.T) { rcvTPs := FilterMdls(tps).AsTPFilter() sort.Strings(rcvTPs[0].Filters[0].Values) - if len(eTPs) != len(rcvTPs) { + if !reflect.DeepEqual(eTPs, rcvTPs) { t.Errorf("Expecting: %+v ,Received: %+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } }