Skip to content

Commit

Permalink
Merge pull request #37 from eitam-ring/master
Browse files Browse the repository at this point in the history
Update aws/amazonmq-Update gcp/pubsub
  • Loading branch information
kubemq authored Sep 10, 2020
2 parents afbcd51 + 8b4dbc6 commit 7ccf245
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 39 deletions.
16 changes: 11 additions & 5 deletions targets/aws/amazonmq/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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"),
Expand Down
81 changes: 47 additions & 34 deletions targets/gcp/pubsub/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
},
},
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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),
Expand All @@ -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().
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
},

Expand Down

0 comments on commit 7ccf245

Please sign in to comment.