fix: Add nacos cert tests (#1723)
* ftr: nacos cert Signed-off-by: LaurenceLiZhixin <382673304@qq.com> * Fix: linter Signed-off-by: LaurenceLiZhixin <382673304@qq.com> * Fix: add readme Signed-off-by: LaurenceLiZhixin <382673304@qq.com> Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
This commit is contained in:
parent
499f6b2d49
commit
07e2657965
|
@ -0,0 +1,18 @@
|
|||
# Alicloud Nacos Binding certification testing
|
||||
|
||||
This project aims to test the Alicloud Nacos binding component under various conditions.
|
||||
|
||||
## Test plan
|
||||
|
||||
### Functional tests
|
||||
|
||||
- Create config:
|
||||
- Successful
|
||||
|
||||
- Get Config:
|
||||
- Successful Get Config
|
||||
- Config does not exist
|
||||
|
||||
### Running the tests
|
||||
|
||||
This must be run in the GitHub Actions Workflow configured for test infrastructure setup.
|
|
@ -0,0 +1,11 @@
|
|||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: alicloud-nacos-binding
|
||||
namespace: default
|
||||
spec:
|
||||
type: bindings.alicloud.nacos
|
||||
version: v1
|
||||
metadata:
|
||||
- name: endpoint
|
||||
value: localhost:8848
|
|
@ -0,0 +1,6 @@
|
|||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Configuration
|
||||
metadata:
|
||||
name: nacosbindingconfig
|
||||
spec:
|
||||
features:
|
|
@ -0,0 +1,9 @@
|
|||
version: "3.7"
|
||||
services:
|
||||
nacos:
|
||||
image: nacos/nacos-server:2.0.3-slim
|
||||
environment:
|
||||
- PREFER_HOST_MODE=hostname
|
||||
- MODE=standalone
|
||||
ports:
|
||||
- "8848:8848"
|
|
@ -0,0 +1,128 @@
|
|||
module servicebusqueue_test
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/dapr/components-contrib v1.7.1-0.20220426033643-068938c67654
|
||||
github.com/dapr/components-contrib/tests/certification v0.0.0-20211026011813-36b75e9ae272
|
||||
github.com/dapr/dapr v1.7.1-0.20220426092903-063b1611d1cb
|
||||
github.com/dapr/go-sdk v1.4.0
|
||||
github.com/dapr/kit v0.0.2-0.20210614175626-b9074b64d233
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.0.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
)
|
||||
|
||||
require (
|
||||
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
|
||||
contrib.go.opencensus.io/exporter/zipkin v0.1.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/aliyun/alibaba-cloud-sdk-go v1.61.18 // indirect
|
||||
github.com/andybalholm/brotli v1.0.2 // indirect
|
||||
github.com/antlr/antlr4 v0.0.0-20200503195918-621b933c7a7f // indirect
|
||||
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.1 // 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.10.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/go-errors/errors v1.4.0 // indirect
|
||||
github.com/go-kit/log v0.1.0 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.1 // indirect
|
||||
github.com/go-logr/logr v1.2.0 // 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.6 // indirect
|
||||
github.com/google/gofuzz v1.1.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/hashicorp/consul/api v1.11.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
|
||||
github.com/hashicorp/go-hclog v0.14.1 // indirect
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0 // 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.5 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.14.4 // indirect
|
||||
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||
github.com/miekg/dns v1.1.35 // 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.4.1 // 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.2.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_golang v1.11.1 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // 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.8.1 // 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.3.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.31.1-0.20211216042702-258a4c17b4f4 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
go.opentelemetry.io/otel v0.20.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.7.0 // indirect
|
||||
go.uber.org/zap v1.19.1 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a // 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
|
||||
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
|
||||
google.golang.org/grpc v1.40.0 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // 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 => ../../../../..
|
||||
|
||||
replace github.com/dapr/components-contrib/tests/certification => ../../..
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
Copyright 2021 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 nacosbinding_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dapr/components-contrib/tests/certification/flow/dockercompose"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/dapr/components-contrib/bindings"
|
||||
nacosbinding "github.com/dapr/components-contrib/bindings/alicloud/nacos"
|
||||
bindings_loader "github.com/dapr/dapr/pkg/components/bindings"
|
||||
"github.com/dapr/dapr/pkg/runtime"
|
||||
daprsdk "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/sidecar"
|
||||
|
||||
nacosclient "github.com/nacos-group/nacos-sdk-go/v2/clients"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/vo"
|
||||
)
|
||||
|
||||
const (
|
||||
sidecarName = "nacos-sidecar"
|
||||
configData = "my config data"
|
||||
bindingName = "alicloud-nacos-binding"
|
||||
nacosClusterName = "nacos"
|
||||
dockerComposeYAML = "docker-compose.yml"
|
||||
)
|
||||
|
||||
func createConfigAndData() (map[string]interface{}, map[string]string) {
|
||||
config := map[string]string{
|
||||
"config-id": "123abc456def",
|
||||
"config-group": "test-group",
|
||||
}
|
||||
//Another way of create serverConfigs
|
||||
serverConfigs := []constant.ServerConfig{
|
||||
*constant.NewServerConfig(
|
||||
"localhost",
|
||||
8848,
|
||||
constant.WithScheme("http"),
|
||||
constant.WithContextPath("/nacos"),
|
||||
),
|
||||
}
|
||||
|
||||
nacosConfig := map[string]interface{}{
|
||||
constant.KEY_SERVER_CONFIGS: serverConfigs,
|
||||
}
|
||||
return nacosConfig, config
|
||||
}
|
||||
|
||||
func TestNacosBinding(t *testing.T) {
|
||||
log := logger.NewLogger("dapr.components")
|
||||
|
||||
invokeCreateWithConfig := func(ctx flow.Context, config map[string]string) error {
|
||||
client, clientErr := daprsdk.NewClientWithPort(fmt.Sprint(runtime.DefaultDaprAPIGRPCPort))
|
||||
if clientErr != nil {
|
||||
panic(clientErr)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
invokeRequest := &daprsdk.InvokeBindingRequest{
|
||||
Name: bindingName,
|
||||
Operation: string(bindings.CreateOperation),
|
||||
Data: []byte(configData),
|
||||
Metadata: config,
|
||||
}
|
||||
|
||||
err := client.InvokeOutputBinding(ctx, invokeRequest)
|
||||
return err
|
||||
}
|
||||
|
||||
invokeGetWithConfig := func(ctx flow.Context, config map[string]string) ([]byte, error) {
|
||||
client, clientErr := daprsdk.NewClientWithPort(fmt.Sprint(runtime.DefaultDaprAPIGRPCPort))
|
||||
if clientErr != nil {
|
||||
panic(clientErr)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
invokeRequest := &daprsdk.InvokeBindingRequest{
|
||||
Name: bindingName,
|
||||
Operation: string(bindings.GetOperation),
|
||||
Metadata: config,
|
||||
}
|
||||
|
||||
rsp, err := client.InvokeBinding(ctx, invokeRequest)
|
||||
return rsp.Data, err
|
||||
}
|
||||
|
||||
testInvokeCreateAndVerify := func(ctx flow.Context) error {
|
||||
nacosConfig, config := createConfigAndData()
|
||||
invokeErr := invokeCreateWithConfig(ctx, config)
|
||||
assert.NoError(t, invokeErr)
|
||||
|
||||
// sleep to avoid metadata request rate limit before initializing new client
|
||||
flow.Sleep(3 * time.Second)
|
||||
|
||||
client, creatConfigErr := nacosclient.CreateConfigClient(nacosConfig)
|
||||
assert.NoError(t, creatConfigErr)
|
||||
content, getConfigError := client.GetConfig(vo.ConfigParam{
|
||||
DataId: config["config-id"],
|
||||
Group: config["config-group"],
|
||||
Content: "",
|
||||
OnChange: nil,
|
||||
})
|
||||
assert.NoError(t, getConfigError)
|
||||
assert.Equal(t, configData, content)
|
||||
|
||||
// cleanup
|
||||
_, err := client.DeleteConfig(vo.ConfigParam{
|
||||
DataId: config["config-id"],
|
||||
Group: config["config-group"],
|
||||
Content: "",
|
||||
OnChange: nil,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
testInvokeGetAndVerify := func(ctx flow.Context) error {
|
||||
nacosConfig, config := createConfigAndData()
|
||||
|
||||
// sleep to avoid metadata request rate limit before initializing new client
|
||||
flow.Sleep(3 * time.Second)
|
||||
|
||||
client, creatConfigErr := nacosclient.CreateConfigClient(nacosConfig)
|
||||
assert.NoError(t, creatConfigErr)
|
||||
ok, getConfigError := client.PublishConfig(vo.ConfigParam{
|
||||
DataId: config["config-id"],
|
||||
Group: config["config-group"],
|
||||
Content: configData,
|
||||
OnChange: nil,
|
||||
})
|
||||
assert.NoError(t, getConfigError)
|
||||
assert.True(t, ok)
|
||||
|
||||
data, invokeErr := invokeGetWithConfig(ctx, config)
|
||||
assert.Equal(t, configData, string(data))
|
||||
assert.NoError(t, invokeErr)
|
||||
|
||||
// cleanup
|
||||
_, err := client.DeleteConfig(vo.ConfigParam{
|
||||
DataId: config["config-id"],
|
||||
Group: config["config-group"],
|
||||
Content: "",
|
||||
OnChange: nil,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
testInvokeGetWithErrorAndVerify := func(ctx flow.Context) error {
|
||||
_, config := createConfigAndData()
|
||||
|
||||
// sleep to avoid metadata request rate limit before initializing new client
|
||||
flow.Sleep(3 * time.Second)
|
||||
|
||||
_, invokeErr := invokeGetWithConfig(ctx, config)
|
||||
assert.NotNil(t, invokeErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
flow.New(t, "test nacos binding config").
|
||||
Step(dockercompose.Run(nacosClusterName, dockerComposeYAML)).
|
||||
Step(sidecar.Run(sidecarName,
|
||||
embedded.WithoutApp(),
|
||||
embedded.WithComponentsPath("./components"),
|
||||
embedded.WithDaprGRPCPort(runtime.DefaultDaprAPIGRPCPort),
|
||||
embedded.WithDaprHTTPPort(runtime.DefaultDaprHTTPPort),
|
||||
runtime.WithOutputBindings(
|
||||
bindings_loader.NewOutput("alicloud.nacos", func() bindings.OutputBinding {
|
||||
return nacosbinding.NewNacos(log)
|
||||
}),
|
||||
))).
|
||||
Step("verify data sent to output binding is written to nacos", testInvokeCreateAndVerify).
|
||||
Step("verify data sent in nacos can be got correctly", testInvokeGetAndVerify).
|
||||
Step("verify get config with error", testInvokeGetWithErrorAndVerify).
|
||||
Run()
|
||||
}
|
Loading…
Reference in New Issue