From 8b4dbc6fafcc688a94bcf089f7272d8943b546f1 Mon Sep 17 00:00:00 2001 From: "eitam.ring@kubemq.io" Date: Wed, 9 Sep 2020 15:20:21 +0300 Subject: [PATCH] Update amazonmq- Update gcp/pubsub --- targets/aws/amazonmq/client_test.go | 16 ++++-- targets/gcp/pubsub/client_test.go | 81 +++++++++++++++++------------ 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/targets/aws/amazonmq/client_test.go b/targets/aws/amazonmq/client_test.go index 82060811..ed247de6 100644 --- a/targets/aws/amazonmq/client_test.go +++ b/targets/aws/amazonmq/client_test.go @@ -11,9 +11,10 @@ import ( ) type testStructure struct { - host string - username string - password string + host string + username string + password string + destination string } func getTestStructure() (*testStructure, error) { @@ -33,6 +34,11 @@ func getTestStructure() (*testStructure, error) { return nil, err } t.password = string(dat) + dat, err = ioutil.ReadFile("./../../../credentials/aws/amazonmq/destination.txt") + if err != nil { + return nil, err + } + t.destination = string(dat) return t, nil } @@ -71,7 +77,7 @@ func TestClient_Init(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() c := New() @@ -106,7 +112,7 @@ func TestClient_Do(t *testing.T) { }, }, request: types.NewRequest(). - SetMetadataKeyValue("destination", "some-destination"). + SetMetadataKeyValue("destination", dat.destination). SetData([]byte("some-data")), wantResponse: types.NewResponse(). SetMetadataKeyValue("result", "ok"), diff --git a/targets/gcp/pubsub/client_test.go b/targets/gcp/pubsub/client_test.go index 25799b80..99e2dec8 100644 --- a/targets/gcp/pubsub/client_test.go +++ b/targets/gcp/pubsub/client_test.go @@ -12,14 +12,36 @@ import ( "time" ) -func TestClient_Init(t *testing.T) { +type testStructure struct { + projectID string + credentials string + topicID string +} + +func getTestStructure() (*testStructure, error) { + t := &testStructure{} dat, err := ioutil.ReadFile("./../../../credentials/projectID.txt") - require.NoError(t, err) - projectID := string(dat) - require.NoError(t, err) + if err != nil { + return nil, err + } + t.projectID = string(dat) dat, err = ioutil.ReadFile("./../../../credentials/google_cred.json") + if err != nil { + return nil, err + } + t.credentials = fmt.Sprintf("%s", dat) + + dat, err = ioutil.ReadFile("./../../../credentials/topicID.txt") + if err != nil { + return nil, err + } + t.topicID = fmt.Sprintf("%s", dat) + return t, nil +} + +func TestClient_Init(t *testing.T) { + dat, err := getTestStructure() require.NoError(t, err) - credentials := fmt.Sprintf("%s", dat) tests := []struct { name string cfg config.Spec @@ -31,19 +53,19 @@ func TestClient_Init(t *testing.T) { Name: "target-gcp-pubsub", Kind: "target.gcp.pubsub", Properties: map[string]string{ - "project_id": projectID, - "retries": "0", - "credentials": credentials, + "project_id": dat.projectID, + "retries": "0", + "credentials": dat.credentials, }, }, wantErr: false, - },{ + }, { name: "init-missing-credentials", cfg: config.Spec{ Name: "target-gcp-pubsub", Kind: "target.gcp.pubsub", Properties: map[string]string{ - "project_id": projectID, + "project_id": dat.projectID, "retries": "0", }, }, @@ -55,8 +77,8 @@ func TestClient_Init(t *testing.T) { Name: "target-gcp-pubsub", Kind: "target.gcp.pubsub", Properties: map[string]string{ - "retries": "0", - "credentials": credentials, + "retries": "0", + "credentials": dat.credentials, }, }, wantErr: true, @@ -81,16 +103,10 @@ func TestClient_Init(t *testing.T) { } func TestClient_Do(t *testing.T) { - dat, err := ioutil.ReadFile("./../../../credentials/projectID.txt") + dat, err := getTestStructure() require.NoError(t, err) - projectID := string(dat) - dat, err = ioutil.ReadFile("./../../../credentials/topicID.txt") - require.NoError(t, err) - topicID := string(dat) + validBody, _ := json.Marshal("valid body") - dat, err = ioutil.ReadFile("./../../../credentials/google_cred.json") - require.NoError(t, err) - credentials := fmt.Sprintf("%s", dat) tests := []struct { name string cfg config.Spec @@ -104,14 +120,15 @@ func TestClient_Do(t *testing.T) { Name: "target-gcp-pubsub", Kind: "target.gcp.pubsub", Properties: map[string]string{ - "project_id": projectID, - "retries": "0", - "credentials": credentials, + "project_id": dat.projectID, + "retries": "0", + "topic_id": dat.topicID, + "credentials": dat.credentials, }, }, request: types.NewRequest(). SetMetadataKeyValue("tags", `{"tag-1":"test","tag-2":"test2"}`). - SetMetadataKeyValue("topic_id", topicID). + SetMetadataKeyValue("topic_id", dat.topicID). SetData(validBody), want: types.NewResponse(). SetData(validBody), @@ -123,9 +140,9 @@ func TestClient_Do(t *testing.T) { Name: "target-gcp-pubsub", Kind: "target.gcp.pubsub", Properties: map[string]string{ - "project_id": projectID, - "retries": "0", - "credentials": credentials, + "project_id": dat.projectID, + "retries": "0", + "credentials": dat.credentials, }, }, request: types.NewRequest(). @@ -157,12 +174,8 @@ func TestClient_Do(t *testing.T) { } func TestClient_list(t *testing.T) { - dat, err := ioutil.ReadFile("./../../../credentials/projectID.txt") - require.NoError(t, err) - projectID := string(dat) - dat, err = ioutil.ReadFile("./../../../credentials/google_cred.json") + dat, err := getTestStructure() require.NoError(t, err) - credentials := fmt.Sprintf("%s", dat) tests := []struct { name string cfg config.Spec @@ -174,8 +187,8 @@ func TestClient_list(t *testing.T) { Name: "target-gcp-pubsub", Kind: "target.gcp.pubsub", Properties: map[string]string{ - "project_id": projectID, - "credentials": credentials, + "project_id": dat.projectID, + "credentials": dat.credentials, }, },