Skip to content

Commit 1208b3e

Browse files
authored
Conformance test: move loader to each component type's folder (#3162)
Signed-off-by: ItalyPaleAle <[email protected]>
1 parent 5a00d1c commit 1208b3e

File tree

11 files changed

+521
-456
lines changed

11 files changed

+521
-456
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ run:
1515
# list of build tags, all linters use it. Default is empty list.
1616
build-tags:
1717
- certtests
18+
- conftests
1819
- metadata
1920

2021
# which dirs to skip: they won't be analyzed;
@@ -301,3 +302,4 @@ linters:
301302
- deadcode
302303
- nosnakecase
303304
- varcheck
305+
- goconst

tests/conformance/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
1. `tests/` directory contains the configuration and the test definition for conformance tests.
66
2. All the conformance tests are within the `tests/conformance` directory.
7-
3. All the configurations are in the `tests/config` directory.
8-
4. Each of the component specific `component` definition are in their specific `component type` folder in the `tests/config` folder. For example, the `redis` statestore component definition within `state` directory.
9-
- The component types are: `bindings`, `configuration`, `crypto`, `pubsub`, `state`, `secretstores`, `workflows`.
10-
- Cloud specific components will be within their own `cloud` directory within the `component type` folder, e.g. `pubsub/azure/servicebus`.
7+
3. All the components' configurations are in the `tests/config` directory.
8+
4. Each of the component specific component's definition are in their specific `<component type>` folder in the `tests/config` folder. For example, the SQLite state store component definition is in the `tests/config/state/sqlite/` directory.
9+
- The component types are: `bindings`, `configuration`, `crypto`, `lock`, `pubsub`, `state`, `secretstores`, `workflows`.
10+
- Cloud-specific components will be within their own `<cloud>` directory within the `<component type>` folder, e.g. `tests/config/pubsub/azure/servicebus`.
11+
- If a component has multiple variants, they are defined in sub-folders. For example, for the MySQL state store, `tests/config/state/mysql/mysql` contains the configuration for testing against MySQL, while `tests/config/state/mysql/mariadb` uses MariaDB.
1112
5. Similar to the component definitions, each component type has its own set of the conformance tests definitions.
12-
6. Each `component type` contains a `tests.yml` definition that defines the component to be tested along with component specific test configuration. Nested folder names have their `/` in path replaced by `.` in the component name in `tests.yml`, e.g. `azure/servicebus/topics` should be `azure.servicebus.topics`
13-
7. All the tests configurations are defined in `common.go` file.
14-
8. Each `component type` has its own `_test` file to trigger the conformance tests. E.g. `bindings_test.go`.
15-
9. Each test added will also need to be added to the `component type/tests.yml` workflow file.
13+
6. Each component type contains a `tests.yml` definition that defines the component to be tested along with component-specific test configuration. Nested folder names have their `/` in path replaced by `.` in the component name in `tests.yml`, e.g. `azure/servicebus/topics` should be `azure.servicebus.topics`
14+
7. Each component type has its own `_test` file to trigger the conformance tests, e.g. `bindings_test.go`. This file contains also the test configurations.
15+
9. Each test added will also need to be added to the `<component type>/tests.yml` workflow file.
1616

1717
## Conformance test workflow
1818

@@ -24,21 +24,21 @@
2424

2525
1. Add the component specific YAML to `tests/config/<COMPONENT-TYPE>/<COMPONENT>/<FILE>.yaml`.
2626
2. All passwords will be of the form `${{PASSWORD_KEY}}` so that it is injected via environment variables.
27-
3. Register the component `New**` function in `common.go`. For example:
27+
3. Register the component `New**` function in `<COMPONENT-TYPE>_test.go`. For example:
2828

2929
```go
3030
...
31-
switch tc.Component {
31+
switch name {
3232
case "azure.servicebusqueues":
33-
binding = b_azure_servicebusqueues.NewAzureServiceBusQueues(testLogger)
33+
return b_azure_servicebusqueues.NewAzureServiceBusQueues(testLogger)
3434
case "azure.storagequeues":
35-
binding = b_azure_storagequeues.NewAzureStorageQueues(testLogger)
35+
return b_azure_storagequeues.NewAzureStorageQueues(testLogger)
3636
case "azure.eventgrid":
37-
binding = b_azure_eventgrid.NewAzureEventGrid(testLogger)
37+
return b_azure_eventgrid.NewAzureEventGrid(testLogger)
3838
case "kafka":
39-
binding = b_kafka.NewKafka(testLogger)
39+
return b_kafka.NewKafka(testLogger)
4040
case "new-component":
41-
binding = b_new_component.NewComponent(testLogger)
41+
return b_new_component.NewComponent(testLogger)
4242
default:
4343
return nil
4444
}

tests/conformance/bindings_test.go

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,123 @@ limitations under the License.
1717
package conformance
1818

1919
import (
20+
"path/filepath"
2021
"testing"
2122

2223
"github.com/stretchr/testify/require"
24+
25+
"github.com/dapr/components-contrib/bindings"
26+
b_aws_s3 "github.com/dapr/components-contrib/bindings/aws/s3"
27+
b_azure_blobstorage "github.com/dapr/components-contrib/bindings/azure/blobstorage"
28+
b_azure_cosmosdb "github.com/dapr/components-contrib/bindings/azure/cosmosdb"
29+
b_azure_eventgrid "github.com/dapr/components-contrib/bindings/azure/eventgrid"
30+
b_azure_eventhubs "github.com/dapr/components-contrib/bindings/azure/eventhubs"
31+
b_azure_servicebusqueues "github.com/dapr/components-contrib/bindings/azure/servicebusqueues"
32+
b_azure_storagequeues "github.com/dapr/components-contrib/bindings/azure/storagequeues"
33+
b_cron "github.com/dapr/components-contrib/bindings/cron"
34+
b_http "github.com/dapr/components-contrib/bindings/http"
35+
b_influx "github.com/dapr/components-contrib/bindings/influx"
36+
b_kafka "github.com/dapr/components-contrib/bindings/kafka"
37+
b_kubemq "github.com/dapr/components-contrib/bindings/kubemq"
38+
b_mqtt3 "github.com/dapr/components-contrib/bindings/mqtt3"
39+
b_postgres "github.com/dapr/components-contrib/bindings/postgres"
40+
b_rabbitmq "github.com/dapr/components-contrib/bindings/rabbitmq"
41+
b_redis "github.com/dapr/components-contrib/bindings/redis"
42+
conf_bindings "github.com/dapr/components-contrib/tests/conformance/bindings"
2343
)
2444

2545
func TestBindingsConformance(t *testing.T) {
26-
tc, err := NewTestConfiguration("../config/bindings/tests.yml")
46+
const configPath = "../config/bindings/"
47+
tc, err := NewTestConfiguration(filepath.Join(configPath, "tests.yml"))
2748
require.NoError(t, err)
2849
require.NotNil(t, tc)
50+
51+
tc.TestFn = func(comp *TestComponent) func(t *testing.T) {
52+
return func(t *testing.T) {
53+
ParseConfigurationMap(t, comp.Config)
54+
55+
componentConfigPath := convertComponentNameToPath(comp.Component, comp.Profile)
56+
props, err := loadComponentsAndProperties(t, filepath.Join(configPath, componentConfigPath))
57+
require.NoErrorf(t, err, "error running conformance test for component %s", comp.Component)
58+
59+
inputBinding := loadInputBindings(comp.Component)
60+
outputBinding := loadOutputBindings(comp.Component)
61+
require.True(t, inputBinding != nil || outputBinding != nil)
62+
63+
bindingsConfig, err := conf_bindings.NewTestConfig(comp.Component, comp.Operations, comp.Config)
64+
require.NoErrorf(t, err, "error running conformance test for component %s", comp.Component)
65+
66+
conf_bindings.ConformanceTests(t, props, inputBinding, outputBinding, bindingsConfig)
67+
}
68+
}
69+
2970
tc.Run(t)
3071
}
72+
73+
func loadOutputBindings(name string) bindings.OutputBinding {
74+
switch name {
75+
case "redis.v6":
76+
return b_redis.NewRedis(testLogger)
77+
case "redis.v7":
78+
return b_redis.NewRedis(testLogger)
79+
case "azure.blobstorage":
80+
return b_azure_blobstorage.NewAzureBlobStorage(testLogger)
81+
case "azure.storagequeues":
82+
return b_azure_storagequeues.NewAzureStorageQueues(testLogger)
83+
case "azure.servicebusqueues":
84+
return b_azure_servicebusqueues.NewAzureServiceBusQueues(testLogger)
85+
case "azure.eventgrid":
86+
return b_azure_eventgrid.NewAzureEventGrid(testLogger)
87+
case "azure.eventhubs":
88+
return b_azure_eventhubs.NewAzureEventHubs(testLogger)
89+
case "azure.cosmosdb":
90+
return b_azure_cosmosdb.NewCosmosDB(testLogger)
91+
case "kafka":
92+
return b_kafka.NewKafka(testLogger)
93+
case "http":
94+
return b_http.NewHTTP(testLogger)
95+
case "influx":
96+
return b_influx.NewInflux(testLogger)
97+
case "mqtt3":
98+
return b_mqtt3.NewMQTT(testLogger)
99+
case "rabbitmq":
100+
return b_rabbitmq.NewRabbitMQ(testLogger)
101+
case "kubemq":
102+
return b_kubemq.NewKubeMQ(testLogger)
103+
case "postgresql.docker":
104+
return b_postgres.NewPostgres(testLogger)
105+
case "postgresql.azure":
106+
return b_postgres.NewPostgres(testLogger)
107+
case "aws.s3.docker":
108+
return b_aws_s3.NewAWSS3(testLogger)
109+
case "aws.s3.terraform":
110+
return b_aws_s3.NewAWSS3(testLogger)
111+
default:
112+
return nil
113+
}
114+
}
115+
116+
func loadInputBindings(name string) bindings.InputBinding {
117+
switch name {
118+
case "azure.servicebusqueues":
119+
return b_azure_servicebusqueues.NewAzureServiceBusQueues(testLogger)
120+
case "azure.storagequeues":
121+
return b_azure_storagequeues.NewAzureStorageQueues(testLogger)
122+
case "azure.eventgrid":
123+
return b_azure_eventgrid.NewAzureEventGrid(testLogger)
124+
case "cron":
125+
return b_cron.NewCron(testLogger)
126+
case "azure.eventhubs":
127+
return b_azure_eventhubs.NewAzureEventHubs(testLogger)
128+
case "kafka":
129+
return b_kafka.NewKafka(testLogger)
130+
case "mqtt3":
131+
return b_mqtt3.NewMQTT(testLogger)
132+
case "rabbitmq":
133+
return b_rabbitmq.NewRabbitMQ(testLogger)
134+
case "kubemq":
135+
return b_kubemq.NewKubeMQ(testLogger)
136+
default:
137+
return nil
138+
}
139+
}

0 commit comments

Comments
 (0)