Revise sqs/s3 exporter integration tests

This commit is contained in:
ionutboangiu
2023-01-20 16:16:43 +02:00
committed by Dan Christian Bogos
parent 347da4d066
commit 38b6695d94
4 changed files with 28 additions and 28 deletions

View File

@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package ees
import (
"flag"
"fmt"
"net/rpc"
"path"
@@ -39,6 +40,8 @@ import (
)
var (
runS3Test = flag.Bool("s3_ees", false, "Run the integration test for the S3 exporter")
cgrID string // needed to compute the key when verifying export
s3ConfDir string
s3CfgPath string
s3Cfg *config.CGRConfig
@@ -50,15 +53,14 @@ var (
testS3ResetStorDb,
testS3StartEngine,
testS3RPCConn,
// testS3ExportEvent,
// testS3VerifyExport,
testS3ExportEvent,
testS3VerifyExport,
testStopCgrEngine,
}
)
func TestS3Export(t *testing.T) {
if awsKey == nil || *awsKey == utils.EmptyString ||
awsSecret == nil || *awsSecret == utils.EmptyString {
if !*runS3Test {
t.SkipNow()
}
s3ConfDir = "ees_s3&sqs"
@@ -75,9 +77,8 @@ func testS3LoadConfig(t *testing.T) {
}
for _, value := range s3Cfg.EEsCfg().Exporters {
if value.ID == "sqs_test_file" {
value.ExportPath = fmt.Sprintf("https://s3.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret)
value.Opts.AWSKey = awsKey
value.Opts.AWSSecret = awsSecret
awsKey = *value.Opts.AWSKey
awsSecret = *value.Opts.AWSSecret
}
}
}
@@ -109,6 +110,7 @@ func testS3RPCConn(t *testing.T) {
}
func testS3ExportEvent(t *testing.T) {
cgrID = utils.Sha1("abcdef", time.Unix(1383813745, 0).UTC().String())
ev := &engine.CGREventWithEeIDs{
EeIDs: []string{"s3_test_file"},
CGREvent: &utils.CGREvent{
@@ -116,7 +118,7 @@ func testS3ExportEvent(t *testing.T) {
ID: "dataEvent",
Time: utils.TimePointer(time.Now()),
Event: map[string]interface{}{
utils.CGRID: utils.Sha1("abcdef", time.Unix(1383813745, 0).UTC().String()),
utils.CGRID: cgrID,
utils.ToR: utils.MetaData,
utils.OriginID: "abcdef",
utils.OriginHost: "192.168.1.1",
@@ -139,21 +141,21 @@ func testS3ExportEvent(t *testing.T) {
if err := s3RPC.Call(utils.EeSv1ProcessEvent, ev, &reply); err != nil {
t.Error(err)
}
time.Sleep(time.Second)
time.Sleep(2 * time.Second)
}
func testS3VerifyExport(t *testing.T) {
endpoint := fmt.Sprintf("https://s3.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret)
endpoint := "s3.eu-central-1.amazonaws.com"
region := "eu-central-1"
qname := "cgrates-cdrs"
key := "key"
key += ".json"
key := fmt.Sprintf("%s/%s:%s.json", "", cgrID, utils.MetaDefault)
var sess *session.Session
cfg := aws.Config{Endpoint: aws.String(endpoint)}
cfg.Region = aws.String(region)
cfg.Credentials = credentials.NewStaticCredentials(*awsKey, *awsSecret, "")
cfg.Credentials = credentials.NewStaticCredentials(awsKey, awsSecret, "")
var err error
sess, err = session.NewSessionWithOptions(
session.Options{
@@ -176,7 +178,7 @@ func testS3VerifyExport(t *testing.T) {
t.Fatalf("Unable to download item %v", err)
}
expected := `{"Account":"1001","CGRID":"dbafe9c8614c785a65aabd116dd3959c3c56f7f6","Category":"call","Destination":"1002","OriginID":"dsafdsaf","RequestType":"*rated","RunID":"*default","Subject":"1001","Tenant":"cgrates.org","ToR":"*voice"}`
expected := `{"Account":"1001","CGRID":"ea1f1968cc207859672c332364fc7614c86b04c5","Category":"call","Destination":"1002","OriginID":"abcdef","RequestType":"*rated","RunID":"*default","Subject":"1001","Tenant":"AnotherTenant","ToR":"*data"}`
if rply := string(file.Bytes()); rply != expected {
t.Errorf("Expected: %q, received: %q", expected, rply)
}

View File

@@ -23,7 +23,6 @@ package ees
import (
"flag"
"fmt"
"net/rpc"
"path"
"testing"
@@ -40,8 +39,9 @@ import (
)
var (
awsKey = flag.String("awsKey", utils.EmptyString, "Access key ID for IAM user")
awsSecret = flag.String("awsSecret", utils.EmptyString, "Secret access key")
runSQSTest = flag.Bool("sqs_ees", false, "Run the integration test for the SQS exporter")
awsKey string
awsSecret string
sqsConfDir string
sqsCfgPath string
sqsCfg *config.CGRConfig
@@ -54,14 +54,13 @@ var (
testSQSStartEngine,
testSQSRPCConn,
testSQSExportEvent,
// testSQSVerifyExport,
testSQSVerifyExport,
testStopCgrEngine,
}
)
func TestSQSExport(t *testing.T) {
if awsKey == nil || *awsKey == utils.EmptyString ||
awsSecret == nil || *awsSecret == utils.EmptyString {
if !*runSQSTest {
t.SkipNow()
}
sqsConfDir = "ees_s3&sqs"
@@ -78,9 +77,8 @@ func testSQSLoadConfig(t *testing.T) {
}
for _, value := range sqsCfg.EEsCfg().Exporters {
if value.ID == "sqs_test_file" {
value.ExportPath = fmt.Sprintf("https://sqs.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret)
value.Opts.AWSKey = awsKey
value.Opts.AWSSecret = awsSecret
awsKey = *value.Opts.AWSKey
awsSecret = *value.Opts.AWSSecret
}
}
}
@@ -143,11 +141,11 @@ func testSQSExportEvent(t *testing.T) {
t.Error(err)
}
time.Sleep(time.Second)
time.Sleep(2 * time.Second)
}
func testSQSVerifyExport(t *testing.T) {
endpoint := fmt.Sprintf("https://sqs.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret)
endpoint := "sqs.eu-central-1.amazonaws.com"
region := "eu-central-1"
qname := "testQueue"
@@ -155,7 +153,7 @@ func testSQSVerifyExport(t *testing.T) {
cfg := aws.Config{Endpoint: aws.String(endpoint)}
cfg.Region = aws.String(region)
var err error
cfg.Credentials = credentials.NewStaticCredentials(*awsKey, *awsSecret, "")
cfg.Credentials = credentials.NewStaticCredentials(awsKey, awsSecret, "")
sess, err = session.NewSessionWithOptions(
session.Options{
Config: cfg,

View File

@@ -39,7 +39,7 @@ import (
)
var (
itTestS3 = flag.Bool("s3", false, "Run the test for S3Reader")
itTestS3 = flag.Bool("s3_ers", false, "Run the test for S3Reader")
)
func TestS3ER(t *testing.T) {

View File

@@ -38,7 +38,7 @@ import (
)
var (
itTestSQS = flag.Bool("sqs", false, "Run the test for SQSReader")
itTestSQS = flag.Bool("sqs_ers", false, "Run the test for SQSReader")
)
func TestSQSER(t *testing.T) {