From 031ee35a00524ff36c47f54e24cfb5e184f25391 Mon Sep 17 00:00:00 2001 From: Cesar Celis Hernandez Date: Wed, 16 Feb 2022 13:23:14 -0500 Subject: [PATCH] Add PostgreSQL Notification Test (#1578) Co-authored-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> --- Makefile | 5 +- integration/buckets_test.go | 94 +++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 03d602066..245ccf3ef 100644 --- a/Makefile +++ b/Makefile @@ -65,9 +65,12 @@ assets: @(cd portal-ui; yarn install; make build-static; yarn prettier --write . --loglevel warn; cd ..) test-integration: + @echo "create docker network to communicate containers MinIO & PostgreSQL" + @(docker network create --subnet=173.18.0.0/29 mynet123) @echo "docker run with MinIO Version below:" @echo $(MINIO_VERSION) - @(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 $(MINIO_VERSION) server /data{1...4} && sleep 5) + @(docker run -v /data1 -v /data2 -v /data3 -v /data4 --net=mynet123 -d --name minio --rm -p 9000:9000 $(MINIO_VERSION) server /data{1...4} && sleep 5) + @(docker run --net=mynet123 --ip=173.18.0.3 --name pgsqlcontainer --rm -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres && sleep 5) @(GO111MODULE=on go test -race -v github.com/minio/console/integration/...) @(docker stop minio) diff --git a/integration/buckets_test.go b/integration/buckets_test.go index 5e6920fa8..5da4866aa 100644 --- a/integration/buckets_test.go +++ b/integration/buckets_test.go @@ -688,6 +688,81 @@ func DeleteObjectsRetentionStatus(bucketName string, prefix string, versionID st return response, err } +func NotifyPostgres() (*http.Response, error) { + /* + Helper function to add Postgres Notification + HTTP Verb: PUT + URL: api/v1/configs/notify_postgres + Body: + { + "key_values":[ + { + "key":"connection_string", + "value":"user=postgres password=password host=localhost dbname=postgres port=5432 sslmode=disable" + }, + { + "key":"table", + "value":"accountsssss" + }, + { + "key":"format", + "value":"namespace" + }, + { + "key":"queue_limit", + "value":"10000" + }, + { + "key":"comment", + "value":"comment" + } + ] + } + */ + Body := models.SetConfigRequest{ + KeyValues: []*models.ConfigurationKV{ + { + Key: "connection_string", + Value: "user=postgres password=password host=173.18.0.3 dbname=postgres port=5432 sslmode=disable", + }, + { + Key: "table", + Value: "accountsssss", + }, + { + Key: "format", + Value: "namespace", + }, + { + Key: "queue_limit", + Value: "10000", + }, + { + Key: "comment", + Value: "comment", + }, + }, + } + + requestDataJSON, _ := json.Marshal(Body) + requestDataBody := bytes.NewReader(requestDataJSON) + request, err := http.NewRequest( + "PUT", + "http://localhost:9090/api/v1/configs/notify_postgres", + requestDataBody, + ) + if err != nil { + log.Println(err) + } + request.Header.Add("Cookie", fmt.Sprintf("token=%s", token)) + request.Header.Add("Content-Type", "application/json") + client := &http.Client{ + Timeout: 2 * time.Second, + } + response, err := client.Do(request) + return response, err +} + func PutBucketQuota(bucketName string, enabled bool, quotaType string, amount int) (*http.Response, error) { /* Helper function to put bucket quota @@ -2357,6 +2432,25 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) { } +func TestNotifyPostgres(t *testing.T) { + + // Variables + assert := assert.New(t) + + // Test + response, err := NotifyPostgres() + finalResponse := inspectHTTPResponse(response) + assert.Nil(err) + if err != nil { + log.Println(err) + assert.Fail(finalResponse) + return + } + if response != nil { + assert.Equal(200, response.StatusCode, finalResponse) + } +} + func TestPutBucketQuota(t *testing.T) { // Variables