Bugfix inconsistent applies of ListAttributes (#328)
* sort the list of ACLs for MongoDBFlex * Fix and test other cases of ListAttribute ordering * fix linting * revert sorting changes, introduce new reconcilestrlist function * merge main * Fix rabbitmq * fix segmentation fault * Improve testing * pass context to mapfields, minor name fixes
This commit is contained in:
parent
18d3f4d1fb
commit
9bd1da7cee
26 changed files with 1011 additions and 146 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package rabbitmq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
|
@ -13,12 +14,17 @@ import (
|
|||
func TestMapFields(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
state Model
|
||||
input *rabbitmq.CredentialsResponse
|
||||
expected Model
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
&rabbitmq.CredentialsResponse{
|
||||
Id: utils.Ptr("cid"),
|
||||
Raw: &rabbitmq.RawCredentials{},
|
||||
|
|
@ -43,6 +49,10 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"simple_values",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
&rabbitmq.CredentialsResponse{
|
||||
Id: utils.Ptr("cid"),
|
||||
Raw: &rabbitmq.RawCredentials{
|
||||
|
|
@ -96,8 +106,92 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"hosts_uris_unordered",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Hosts: types.ListValueMust(types.StringType, []attr.Value{
|
||||
types.StringValue("host_2"),
|
||||
types.StringValue(""),
|
||||
types.StringValue("host_1"),
|
||||
}),
|
||||
Uris: types.ListValueMust(types.StringType, []attr.Value{
|
||||
types.StringValue("uri_2"),
|
||||
types.StringValue(""),
|
||||
types.StringValue("uri_1"),
|
||||
}),
|
||||
HttpAPIURIs: types.ListValueMust(types.StringType, []attr.Value{
|
||||
types.StringValue("http_api_uri_2"),
|
||||
types.StringValue(""),
|
||||
types.StringValue("http_api_uri_1"),
|
||||
}),
|
||||
},
|
||||
&rabbitmq.CredentialsResponse{
|
||||
Id: utils.Ptr("cid"),
|
||||
Raw: &rabbitmq.RawCredentials{
|
||||
Credentials: &rabbitmq.Credentials{
|
||||
Host: utils.Ptr("host"),
|
||||
Hosts: &[]string{
|
||||
"",
|
||||
"host_1",
|
||||
"host_2",
|
||||
},
|
||||
HttpApiUri: utils.Ptr("http"),
|
||||
HttpApiUris: &[]string{
|
||||
"",
|
||||
"http_api_uri_1",
|
||||
"http_api_uri_2",
|
||||
},
|
||||
Management: utils.Ptr("management"),
|
||||
Password: utils.Ptr("password"),
|
||||
Port: utils.Ptr(int64(1234)),
|
||||
Uri: utils.Ptr("uri"),
|
||||
Uris: &[]string{
|
||||
"",
|
||||
"uri_1",
|
||||
"uri_2",
|
||||
},
|
||||
Username: utils.Ptr("username"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,iid,cid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Host: types.StringValue("host"),
|
||||
Hosts: types.ListValueMust(types.StringType, []attr.Value{
|
||||
types.StringValue("host_2"),
|
||||
types.StringValue(""),
|
||||
types.StringValue("host_1"),
|
||||
}),
|
||||
HttpAPIURI: types.StringValue("http"),
|
||||
HttpAPIURIs: types.ListValueMust(types.StringType, []attr.Value{
|
||||
types.StringValue("http_api_uri_2"),
|
||||
types.StringValue(""),
|
||||
types.StringValue("http_api_uri_1"),
|
||||
}),
|
||||
Management: types.StringValue("management"),
|
||||
Password: types.StringValue("password"),
|
||||
Port: types.Int64Value(1234),
|
||||
Uri: types.StringValue("uri"),
|
||||
Uris: types.ListValueMust(types.StringType, []attr.Value{
|
||||
types.StringValue("uri_2"),
|
||||
types.StringValue(""),
|
||||
types.StringValue("uri_1"),
|
||||
}),
|
||||
Username: types.StringValue("username"),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"null_fields_and_int_conversions",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
&rabbitmq.CredentialsResponse{
|
||||
Id: utils.Ptr("cid"),
|
||||
Raw: &rabbitmq.RawCredentials{
|
||||
|
|
@ -135,18 +229,30 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"nil_response",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
nil,
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
&rabbitmq.CredentialsResponse{},
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"nil_raw_credential",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
&rabbitmq.CredentialsResponse{
|
||||
Id: utils.Ptr("cid"),
|
||||
},
|
||||
|
|
@ -156,11 +262,7 @@ func TestMapFields(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
model := &Model{
|
||||
ProjectId: tt.expected.ProjectId,
|
||||
InstanceId: tt.expected.InstanceId,
|
||||
}
|
||||
err := mapFields(tt.input, model)
|
||||
err := mapFields(context.Background(), tt.input, &tt.state)
|
||||
if !tt.isValid && err == nil {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
|
|
@ -168,7 +270,7 @@ func TestMapFields(t *testing.T) {
|
|||
t.Fatalf("Should not have failed: %v", err)
|
||||
}
|
||||
if tt.isValid {
|
||||
diff := cmp.Diff(model, &tt.expected)
|
||||
diff := cmp.Diff(tt.state, tt.expected)
|
||||
if diff != "" {
|
||||
t.Fatalf("Data does not match: %s", diff)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue