@@ -3,9 +3,13 @@ package acctest
33import (
44 "encoding/base64"
55 "encoding/json"
6+ "os"
7+ "path"
68 "reflect"
79 "testing"
810
11+ "github.com/oracle/terraform-provider-oci/httpreplay"
12+
913 tf_client "github.com/oracle/terraform-provider-oci/internal/client"
1014
1115 "github.com/stretchr/testify/assert"
@@ -927,6 +931,16 @@ func TestUnitProviderTestCopy(t *testing.T) {
927931}
928932
929933func TestUnitRepresentationCopyWithNewProperties (t * testing.T ) {
934+ auditEventResourceRepresentation := map [string ]interface {}{
935+ "compartment_id" : Representation {RepType : Required , Create : `${var.compartment_id}` },
936+ "end_time" : Representation {RepType : Required , Create : `${timestamp()}` },
937+ }
938+ updatedAuditEventResourceRepresentation := map [string ]interface {}{
939+ "compartment_id" : Representation {RepType : Required , Create : `${var.compartment_id}` },
940+ "end_time" : Representation {RepType : Required , Create : `${timestamp()}` },
941+ "dns_label" : Representation {RepType : Required , Create : `dnslabel` },
942+ }
943+ newProperties := map [string ]interface {}{"dns_label" : Representation {RepType : Required , Create : `dnslabel` }}
930944 type args struct {
931945 representations map [string ]interface {}
932946 newProperties map [string ]interface {}
@@ -936,7 +950,14 @@ func TestUnitRepresentationCopyWithNewProperties(t *testing.T) {
936950 args args
937951 want map [string ]interface {}
938952 }{
939- // TODO: Add test cases.
953+ {
954+ name : "Positive test" ,
955+ args : args {
956+ representations : auditEventResourceRepresentation ,
957+ newProperties : newProperties ,
958+ },
959+ want : updatedAuditEventResourceRepresentation ,
960+ },
940961 }
941962 for _ , tt := range tests {
942963 t .Run (tt .name , func (t * testing.T ) {
@@ -969,6 +990,16 @@ func TestUnitRepresentationCopyWithRemovedNestedProperties(t *testing.T) {
969990}
970991
971992func TestUnitRepresentationCopyWithRemovedProperties (t * testing.T ) {
993+ auditEventResourceRepresentation := map [string ]interface {}{
994+ "compartment_id" : Representation {RepType : Required , Create : `${var.compartment_id}` },
995+ "end_time" : Representation {RepType : Required , Create : `${timestamp()}` },
996+ "start_time" : Representation {RepType : Required , Create : `${timeadd(timestamp(), "-1m")}` },
997+ }
998+ updatedAuditEventResourceRepresentation := map [string ]interface {}{
999+ "compartment_id" : Representation {RepType : Required , Create : `${var.compartment_id}` },
1000+ "end_time" : Representation {RepType : Required , Create : `${timestamp()}` },
1001+ }
1002+ removedProperties := []string {"start_time" }
9721003 type args struct {
9731004 representations map [string ]interface {}
9741005 removedProperties []string
@@ -978,7 +1009,14 @@ func TestUnitRepresentationCopyWithRemovedProperties(t *testing.T) {
9781009 args args
9791010 want map [string ]interface {}
9801011 }{
981- // TODO: Add test cases.
1012+ {
1013+ name : "Positive test" ,
1014+ args : args {
1015+ representations : auditEventResourceRepresentation ,
1016+ removedProperties : removedProperties ,
1017+ },
1018+ want : updatedAuditEventResourceRepresentation ,
1019+ },
9821020 }
9831021 for _ , tt := range tests {
9841022 t .Run (tt .name , func (t * testing.T ) {
@@ -1205,3 +1243,36 @@ func TestUnit_updateNestedRepresentationRemoveProperty(t *testing.T) {
12051243 })
12061244 }
12071245}
1246+
1247+ // issue-routing-tag: terraform/default
1248+ func TestUnitProviderConfig (t * testing.T ) {
1249+ if httpreplay .ModeRecordReplay () {
1250+ t .Skip ("Skip ProviderConfigTest in HttpReplay mode." )
1251+ }
1252+ if os .Getenv ("TF_HOME_OVERRIDE" ) == "" {
1253+ t .Skip ("This run requires you to set TF_HOME_OVERRIDE" )
1254+ }
1255+ ProviderConfigTest (t , true , true , globalvar .AuthAPIKeySetting , "" , nil ) // ApiKey with required fields + disable auto-retries
1256+ ProviderConfigTest (t , false , true , globalvar .AuthAPIKeySetting , "" , nil ) // ApiKey without required fields
1257+ ProviderConfigTest (t , false , false , globalvar .AuthInstancePrincipalSetting , "" , nil ) // InstancePrincipal
1258+ ProviderConfigTest (t , true , false , "invalid-auth-setting" , "" , nil ) // Invalid auth + disable auto-retries
1259+ configFile , keyFile , err := WriteConfigFile ()
1260+ assert .Nil (t , err )
1261+ ProviderConfigTest (t , true , true , globalvar .AuthAPIKeySetting , "DEFAULT" , nil ) // ApiKey with required fields + disable auto-retries
1262+ ProviderConfigTest (t , false , true , globalvar .AuthAPIKeySetting , "DEFAULT" , nil ) // ApiKey without required fields
1263+ ProviderConfigTest (t , false , false , globalvar .AuthInstancePrincipalSetting , "DEFAULT" , nil ) // InstancePrincipal
1264+ ProviderConfigTest (t , true , false , "invalid-auth-setting" , "DEFAULT" , nil ) // Invalid auth + disable auto-retries
1265+ ProviderConfigTest (t , false , false , globalvar .AuthAPIKeySetting , "PROFILE1" , nil ) // correct profileName
1266+ ProviderConfigTest (t , false , false , globalvar .AuthAPIKeySetting , "wrongProfile" , nil ) // Invalid profileName
1267+ //acctest.ProviderConfigTest(t, false, false, globalvar.AuthAPIKeySetting, "PROFILE2", nil) // correct profileName with mix and match
1268+ ProviderConfigTest (t , false , false , globalvar .AuthAPIKeySetting , "PROFILE3" , nil ) // correct profileName with mix and match & env
1269+ defer func () {
1270+ _ = utils .RemoveFile (configFile )
1271+ }()
1272+ defer func () {
1273+ _ = utils .RemoveFile (keyFile )
1274+ }()
1275+ defer func () {
1276+ _ = os .RemoveAll (path .Join (utils .GetHomeFolder (), globalvar .DefaultConfigDirName ))
1277+ }()
1278+ }
0 commit comments