Onboard Argus ACL (#304)

* resource create and schema/model

* consider empty value in resource creation

* Address issue in mapfields that came up in testing

* Unit testing the mapFields func

* extend update

* extend read

* extend datasource.go

* update example

* extended acceptance tests and generated docs

* update description and comments

* improve messages and var names, fix update acceptance test

* extend acceptance tests, improve error messages
This commit is contained in:
Diogo Ferrão 2024-03-22 17:35:10 +00:00 committed by GitHub
parent 8eb14a1136
commit c2389be47b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 379 additions and 22 deletions

View file

@ -14,16 +14,18 @@ import (
func TestMapFields(t *testing.T) {
tests := []struct {
description string
input *argus.GetInstanceResponse
expected Model
isValid bool
description string
instanceResp *argus.GetInstanceResponse
listACLResp *argus.ListACLResponse
expected Model
isValid bool
}{
{
"default_ok",
&argus.GetInstanceResponse{
Id: utils.Ptr("iid"),
},
nil,
Model{
Id: types.StringValue("pid,iid"),
ProjectId: types.StringValue("pid"),
@ -32,6 +34,7 @@ func TestMapFields(t *testing.T) {
PlanName: types.StringNull(),
Name: types.StringNull(),
Parameters: types.MapNull(types.StringType),
ACL: types.SetNull(types.StringType),
},
true,
},
@ -44,6 +47,12 @@ func TestMapFields(t *testing.T) {
PlanId: utils.Ptr("planId"),
Parameters: &map[string]string{"key": "value"},
},
&argus.ListACLResponse{
Acl: &[]string{
"1.1.1.1/32",
},
Message: utils.Ptr("message"),
},
Model{
Id: types.StringValue("pid,iid"),
ProjectId: types.StringValue("pid"),
@ -52,6 +61,40 @@ func TestMapFields(t *testing.T) {
PlanId: types.StringValue("planId"),
PlanName: types.StringValue("plan1"),
Parameters: toTerraformStringMapMust(context.Background(), map[string]string{"key": "value"}),
ACL: types.SetValueMust(types.StringType, []attr.Value{
types.StringValue("1.1.1.1/32"),
}),
},
true,
},
{
"values_ok_multiple_acls",
&argus.GetInstanceResponse{
Id: utils.Ptr("iid"),
Name: utils.Ptr("name"),
PlanName: utils.Ptr("plan1"),
PlanId: utils.Ptr("planId"),
Parameters: &map[string]string{"key": "value"},
},
&argus.ListACLResponse{
Acl: &[]string{
"1.1.1.1/32",
"8.8.8.8/32",
},
Message: utils.Ptr("message"),
},
Model{
Id: types.StringValue("pid,iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringValue("name"),
InstanceId: types.StringValue("iid"),
PlanId: types.StringValue("planId"),
PlanName: types.StringValue("plan1"),
Parameters: toTerraformStringMapMust(context.Background(), map[string]string{"key": "value"}),
ACL: types.SetValueMust(types.StringType, []attr.Value{
types.StringValue("1.1.1.1/32"),
types.StringValue("8.8.8.8/32"),
}),
},
true,
},
@ -61,6 +104,10 @@ func TestMapFields(t *testing.T) {
Id: utils.Ptr("iid"),
Name: nil,
},
&argus.ListACLResponse{
Acl: &[]string{},
Message: nil,
},
Model{
Id: types.StringValue("pid,iid"),
ProjectId: types.StringValue("pid"),
@ -69,18 +116,21 @@ func TestMapFields(t *testing.T) {
PlanName: types.StringNull(),
Name: types.StringNull(),
Parameters: types.MapNull(types.StringType),
ACL: types.SetNull(types.StringType),
},
true,
},
{
"response_nil_fail",
nil,
nil,
Model{},
false,
},
{
"no_resource_id",
&argus.GetInstanceResponse{},
nil,
Model{},
false,
},
@ -90,7 +140,7 @@ func TestMapFields(t *testing.T) {
state := &Model{
ProjectId: tt.expected.ProjectId,
}
err := mapFields(context.Background(), tt.input, state)
err := mapFields(context.Background(), tt.instanceResp, tt.listACLResp, state)
if !tt.isValid && err == nil {
t.Fatalf("Should have failed")
}