Merge branch 'master' into workflow-dev
This commit is contained in:
commit
d8b5d14330
|
@ -52,6 +52,7 @@ jobs:
|
|||
- secretstores.local.file
|
||||
- bindings.rabbitmq
|
||||
- bindings.localstorage
|
||||
- bindings.postgres
|
||||
EOF
|
||||
)
|
||||
echo "::set-output name=pr-components::$PR_COMPONENTS"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# PostgreSQL Output Binding Certification
|
||||
|
||||
The purpose of this module is to provide tests that certify the PostgreSQL Output Binding as a stable component.
|
||||
|
||||
## Test plan
|
||||
|
||||
* Verify the postgres is created/present
|
||||
* Create component spec
|
||||
* Run dapr application with component
|
||||
* Ensure the postgres is present
|
||||
* Verify the connection is established to postgres.
|
||||
* Create component spec.
|
||||
* Run dapr application with component.
|
||||
* Ensure that you have access to postgres and connection to postgres DB is established.
|
||||
* Verify data is getting stored in postgres DB.
|
||||
* Create component spec with the data to be stored.
|
||||
* Run dapr application with component to store data in postgres as output binding.
|
||||
* Read stored data from postgres.
|
||||
* Ensure that read data is same as the data that was stored.
|
||||
* Verify reconnection to postgres for output binding.
|
||||
* Simulate a network error before sending any messages.
|
||||
* Run dapr application with the component.
|
||||
* After the reconnection, send messages to postgres.
|
||||
* Ensure that the messages sent after the reconnection are stored in postgres.
|
|
@ -0,0 +1,10 @@
|
|||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: standard-binding
|
||||
spec:
|
||||
type: bindings.postgres
|
||||
version: v1
|
||||
metadata:
|
||||
- name: url
|
||||
value: "host=localhost user=postgres password=example port=5432 connect_timeout=10 database=dapr_test"
|
|
@ -0,0 +1,6 @@
|
|||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Configuration
|
||||
metadata:
|
||||
name: keyvaultconfig
|
||||
spec:
|
||||
features:
|
|
@ -0,0 +1,11 @@
|
|||
version: '2'
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
restart: always
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: example
|
||||
POSTGRES_DB: dapr_test
|
|
@ -0,0 +1,144 @@
|
|||
module github.com/dapr/components-contrib/tests/certification/state/postgresql
|
||||
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/dapr/components-contrib v1.8.0-rc.6
|
||||
github.com/dapr/components-contrib/tests/certification v0.0.0-20220526162429-d03aeba3e0d6
|
||||
github.com/dapr/dapr v1.8.4-0.20220829184035-996cc622ad0c
|
||||
github.com/dapr/go-sdk v1.4.0
|
||||
github.com/dapr/kit v0.0.2
|
||||
github.com/lib/pq v1.10.2
|
||||
github.com/stretchr/testify v1.8.0
|
||||
)
|
||||
|
||||
require (
|
||||
contrib.go.opencensus.io/exporter/prometheus v0.4.1 // indirect
|
||||
github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect
|
||||
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e // indirect
|
||||
github.com/armon/go-metrics v0.3.10 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
|
||||
github.com/fasthttp/router v1.3.8 // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/go-kit/log v0.2.0 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.1 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/cel-go v0.9.0 // indirect
|
||||
github.com/google/go-cmp v0.5.8 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/googleapis/gnostic v0.5.5 // indirect
|
||||
github.com/grandcat/zeroconf v0.0.0-20190424104450-85eadb44205c // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
|
||||
github.com/hashicorp/consul/api v1.11.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/hashicorp/go-hclog v1.2.1 // indirect
|
||||
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/hashicorp/serf v0.9.6 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.11.0 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
||||
github.com/jackc/pgtype v1.10.0 // indirect
|
||||
github.com/jackc/pgx/v4 v4.15.0 // indirect
|
||||
github.com/jackc/puddle v1.2.1 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.15.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||
github.com/miekg/dns v1.1.50 // indirect
|
||||
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.4.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_golang v1.12.2 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.35.0 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/prometheus/statsd_exporter v0.22.3 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20210217112953-d4a072536008 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/sony/gobreaker v0.4.2-0.20210216022020-dd874f9dd33b // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stoewer/go-strcase v1.2.0 // indirect
|
||||
github.com/stretchr/objx v0.4.0 // indirect
|
||||
github.com/tylertreat/comcast v1.0.1 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.34.0 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
go.opentelemetry.io/otel v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.7.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v0.16.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||
golang.org/x/net v0.0.0-20220630215102-69896b714898 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
|
||||
golang.org/x/tools v0.1.11 // indirect
|
||||
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220622171453-ea41d75dfa0f // indirect
|
||||
google.golang.org/grpc v1.47.0 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/api v0.23.0 // indirect
|
||||
k8s.io/apiextensions-apiserver v0.23.0 // indirect
|
||||
k8s.io/apimachinery v0.23.0 // indirect
|
||||
k8s.io/client-go v0.23.0 // indirect
|
||||
k8s.io/component-base v0.23.0 // indirect
|
||||
k8s.io/klog/v2 v2.30.0 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
|
||||
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
|
||||
sigs.k8s.io/controller-runtime v0.11.0 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/dapr/components-contrib/tests/certification => ../../
|
||||
|
||||
replace github.com/dapr/components-contrib => ../../../../
|
||||
|
||||
replace github.com/dapr/go-sdk => github.com/hunter007/dapr-go-sdk v1.3.1-0.20220709114046-2f2dc4f9a684
|
||||
|
||||
replace github.com/dapr/dapr => github.com/1046102779/dapr v1.5.2-0.20220829014128-56ac94bfadd1
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
Copyright 2022 The Dapr Authors
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package postgres_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dapr/components-contrib/bindings"
|
||||
binding_postgres "github.com/dapr/components-contrib/bindings/postgres"
|
||||
bindings_loader "github.com/dapr/dapr/pkg/components/bindings"
|
||||
"github.com/dapr/dapr/pkg/runtime"
|
||||
dapr_testing "github.com/dapr/dapr/pkg/testing"
|
||||
daprClient "github.com/dapr/go-sdk/client"
|
||||
"github.com/dapr/kit/logger"
|
||||
|
||||
"github.com/dapr/components-contrib/tests/certification/embedded"
|
||||
"github.com/dapr/components-contrib/tests/certification/flow"
|
||||
"github.com/dapr/components-contrib/tests/certification/flow/dockercompose"
|
||||
"github.com/dapr/components-contrib/tests/certification/flow/network"
|
||||
"github.com/dapr/components-contrib/tests/certification/flow/sidecar"
|
||||
)
|
||||
|
||||
const (
|
||||
dockerComposeYAML = "docker-compose.yml"
|
||||
numOfMessages = 10
|
||||
dockerConnectionString = "host=localhost user=postgres password=example port=5432 connect_timeout=10 database=dapr_test sslmode=disable"
|
||||
)
|
||||
|
||||
func TestPostgres(t *testing.T) {
|
||||
|
||||
ports, _ := dapr_testing.GetFreePorts(3)
|
||||
grpcPort := ports[0]
|
||||
httpPort := ports[1]
|
||||
|
||||
testExec := func(ctx flow.Context) error {
|
||||
client, err := daprClient.NewClientWithPort(fmt.Sprintf("%d", grpcPort))
|
||||
require.NoError(t, err, "Could not initialize dapr client.")
|
||||
|
||||
metadata := make(map[string]string)
|
||||
|
||||
ctx.Log("Invoking output binding for exec operation!")
|
||||
req := &daprClient.InvokeBindingRequest{Name: "standard-binding", Operation: "exec", Metadata: metadata}
|
||||
req.Metadata["sql"] = "INSERT INTO dapr_test_table (id, c1, ts) VALUES (1, 'demo', '2020-09-24T11:45:05Z07:00');"
|
||||
errBinding := client.InvokeOutputBinding(ctx, req)
|
||||
require.NoError(ctx, errBinding, "error in output binding - exec")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
testQuery := func(ctx flow.Context) error {
|
||||
client, err := daprClient.NewClientWithPort(fmt.Sprintf("%d", grpcPort))
|
||||
require.NoError(t, err, "Could not initialize dapr client.")
|
||||
|
||||
metadata := make(map[string]string)
|
||||
|
||||
ctx.Log("Invoking output binding for query operation!")
|
||||
req := &daprClient.InvokeBindingRequest{Name: "standard-binding", Operation: "query", Metadata: metadata}
|
||||
req.Metadata["sql"] = "SELECT * FROM dapr_test_table WHERE id = 1;"
|
||||
resp, errBinding := client.InvokeBinding(ctx, req)
|
||||
assert.Contains(t, string(resp.Data), "1,\"demo\",\"2020-09-24T11:45:05Z07:00\"")
|
||||
require.NoError(ctx, errBinding, "error in output binding - query")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
testClose := func(ctx flow.Context) error {
|
||||
client, err := daprClient.NewClientWithPort(fmt.Sprintf("%d", grpcPort))
|
||||
require.NoError(t, err, "Could not initialize dapr client.")
|
||||
|
||||
metadata := make(map[string]string)
|
||||
|
||||
ctx.Log("Invoking output binding for query operation!")
|
||||
req := &daprClient.InvokeBindingRequest{Name: "standard-binding", Operation: "close", Metadata: metadata}
|
||||
errBinding := client.InvokeOutputBinding(ctx, req)
|
||||
require.NoError(ctx, errBinding, "error in output binding - close")
|
||||
|
||||
req = &daprClient.InvokeBindingRequest{Name: "standard-binding", Operation: "query", Metadata: metadata}
|
||||
req.Metadata["sql"] = "SELECT * FROM dapr_test_table WHERE id = 1;"
|
||||
errBinding = client.InvokeOutputBinding(ctx, req)
|
||||
require.Error(ctx, errBinding, "error in output binding - query")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
createTable := func(ctx flow.Context) error {
|
||||
db, err := sql.Open("postgres", dockerConnectionString)
|
||||
assert.NoError(t, err)
|
||||
_, err = db.Exec("CREATE TABLE dapr_test_table(id INT, c1 TEXT, ts TEXT);")
|
||||
assert.NoError(t, err)
|
||||
db.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
flow.New(t, "Run tests").
|
||||
Step(dockercompose.Run("db", dockerComposeYAML)).
|
||||
Step("wait for component to start", flow.Sleep(10*time.Second)).
|
||||
Step("Creating table", createTable).
|
||||
Step("wait for component to start", flow.Sleep(10*time.Second)).
|
||||
Step(sidecar.Run("standardSidecar",
|
||||
embedded.WithoutApp(),
|
||||
embedded.WithDaprGRPCPort(grpcPort),
|
||||
embedded.WithDaprHTTPPort(httpPort),
|
||||
embedded.WithComponentsPath("./components/standard"),
|
||||
componentRuntimeOptions(),
|
||||
)).
|
||||
Step("Run exec test", testExec).
|
||||
Step("Run query test", testQuery).
|
||||
Step("wait for DB operations to complete", flow.Sleep(10*time.Second)).
|
||||
Step("Run close test", testClose).
|
||||
Step("stop postgresql", dockercompose.Stop("db", dockerComposeYAML, "db")).
|
||||
Step("wait for component to start", flow.Sleep(10*time.Second)).
|
||||
Run()
|
||||
}
|
||||
|
||||
func TestPostgresNetworkError(t *testing.T) {
|
||||
|
||||
ports, _ := dapr_testing.GetFreePorts(3)
|
||||
grpcPort := ports[0]
|
||||
httpPort := ports[1]
|
||||
|
||||
testExec := func(ctx flow.Context) error {
|
||||
client, err := daprClient.NewClientWithPort(fmt.Sprintf("%d", grpcPort))
|
||||
require.NoError(t, err, "Could not initialize dapr client.")
|
||||
|
||||
metadata := make(map[string]string)
|
||||
|
||||
ctx.Log("Invoking output binding for exec operation!")
|
||||
req := &daprClient.InvokeBindingRequest{Name: "standard-binding", Operation: "exec", Metadata: metadata}
|
||||
req.Metadata["sql"] = "INSERT INTO dapr_test_table (id, c1, ts) VALUES (1, 'demo', '2020-09-24T11:45:05Z07:00');"
|
||||
errBinding := client.InvokeOutputBinding(ctx, req)
|
||||
require.NoError(ctx, errBinding, "error in output binding - exec")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
testQuery := func(ctx flow.Context) error {
|
||||
client, err := daprClient.NewClientWithPort(fmt.Sprintf("%d", grpcPort))
|
||||
require.NoError(t, err, "Could not initialize dapr client.")
|
||||
|
||||
metadata := make(map[string]string)
|
||||
|
||||
ctx.Log("Invoking output binding for query operation!")
|
||||
req := &daprClient.InvokeBindingRequest{Name: "standard-binding", Operation: "query", Metadata: metadata}
|
||||
req.Metadata["sql"] = "SELECT * FROM dapr_test_table WHERE id = 1;"
|
||||
errBinding := client.InvokeOutputBinding(ctx, req)
|
||||
require.NoError(ctx, errBinding, "error in output binding - query")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
createTable := func(ctx flow.Context) error {
|
||||
db, err := sql.Open("postgres", dockerConnectionString)
|
||||
assert.NoError(t, err)
|
||||
_, err = db.Exec("CREATE TABLE dapr_test_table(id INT, c1 TEXT, ts TEXT);")
|
||||
assert.NoError(t, err)
|
||||
db.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
flow.New(t, "Run tests").
|
||||
Step(dockercompose.Run("db", dockerComposeYAML)).
|
||||
Step("wait for component to start", flow.Sleep(10*time.Second)).
|
||||
Step("Creating table", createTable).
|
||||
Step("wait for component to start", flow.Sleep(10*time.Second)).
|
||||
Step(sidecar.Run("standardSidecar",
|
||||
embedded.WithoutApp(),
|
||||
embedded.WithDaprGRPCPort(grpcPort),
|
||||
embedded.WithDaprHTTPPort(httpPort),
|
||||
embedded.WithComponentsPath("./components/standard"),
|
||||
componentRuntimeOptions(),
|
||||
)).
|
||||
Step("Run exec test", testExec).
|
||||
Step("Run query test", testQuery).
|
||||
Step("wait for DB operations to complete", flow.Sleep(10*time.Second)).
|
||||
Step("interrupt network", network.InterruptNetwork(30*time.Second, nil, nil, "5432")).
|
||||
Step("wait for component to recover", flow.Sleep(10*time.Second)).
|
||||
Step("Run query test", testQuery).
|
||||
Run()
|
||||
}
|
||||
|
||||
func componentRuntimeOptions() []runtime.Option {
|
||||
log := logger.NewLogger("dapr.components")
|
||||
|
||||
bindingsRegistry := bindings_loader.NewRegistry()
|
||||
bindingsRegistry.Logger = log
|
||||
bindingsRegistry.RegisterOutputBinding(func(l logger.Logger) bindings.OutputBinding {
|
||||
return binding_postgres.NewPostgres(l)
|
||||
}, "postgres")
|
||||
|
||||
return []runtime.Option{
|
||||
runtime.WithBindings(bindingsRegistry),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue