Add more tests for MongoDB state store component (#948)
This commit is contained in:
parent
1580e4ab04
commit
1ac87d93c5
|
@ -338,6 +338,10 @@ func getMongoDBMetaData(metadata state.Metadata) (*mongoDBMetadata, error) {
|
|||
return nil, errors.New("must set 'host' or 'server' fields in metadata")
|
||||
}
|
||||
|
||||
if len(meta.host) != 0 && len(meta.server) != 0 {
|
||||
return nil, errors.New("'host' or 'server' fields are mutually exclusive")
|
||||
}
|
||||
|
||||
if val, ok := metadata.Properties[username]; ok && val != "" {
|
||||
meta.username = val
|
||||
}
|
||||
|
|
|
@ -126,9 +126,9 @@ func TestGetMongoDBMetadata(t *testing.T) {
|
|||
|
||||
t.Run("Valid connectionstring with DNS SRV", func(t *testing.T) {
|
||||
properties := map[string]string{
|
||||
server: "server.example.com",
|
||||
databaseName: "TestDB",
|
||||
collectionName: "TestCollection",
|
||||
server: "server.example.com",
|
||||
params: "?ssl=true",
|
||||
}
|
||||
m := state.Metadata{
|
||||
|
@ -143,4 +143,38 @@ func TestGetMongoDBMetadata(t *testing.T) {
|
|||
|
||||
assert.Equal(t, expected, uri)
|
||||
})
|
||||
|
||||
t.Run("Invalid without host/server", func(t *testing.T) {
|
||||
properties := map[string]string{
|
||||
databaseName: "TestDB",
|
||||
collectionName: "TestCollection",
|
||||
}
|
||||
m := state.Metadata{
|
||||
Properties: properties,
|
||||
}
|
||||
|
||||
_, err := getMongoDBMetaData(m)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
expected := "must set 'host' or 'server' fields in metadata"
|
||||
assert.Equal(t, expected, err.Error())
|
||||
})
|
||||
|
||||
t.Run("Invalid with both host/server", func(t *testing.T) {
|
||||
properties := map[string]string{
|
||||
server: "server.example.com",
|
||||
host: "127.0.0.2",
|
||||
databaseName: "TestDB",
|
||||
collectionName: "TestCollection",
|
||||
}
|
||||
m := state.Metadata{
|
||||
Properties: properties,
|
||||
}
|
||||
|
||||
_, err := getMongoDBMetaData(m)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
expected := "'host' or 'server' fields are mutually exclusive"
|
||||
assert.Equal(t, expected, err.Error())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue