3838 "values" : Representation {repType : Required , create : []string {`${oci_objectstorage_object.test_object.object}` }},
3939 }
4040
41+ objectSingularDataSourceRepresentation = map [string ]interface {}{
42+ "bucket" : Representation {repType : Required , create : `${oci_objectstorage_bucket.test_bucket.name}` },
43+ "namespace" : Representation {repType : Required , create : `${oci_objectstorage_bucket.test_bucket.namespace}` },
44+ "object" : Representation {repType : Required , create : `my-test-object-3` },
45+ "content_length_limit" : Representation {repType : Optional , create : `17` , update : `15` },
46+ }
47+
4148 objectRepresentation = map [string ]interface {}{
4249 "bucket" : Representation {repType : Required , create : `${oci_objectstorage_bucket.test_bucket.name}` },
4350 "content" : Representation {repType : Optional , create : `content` , update : `<a1>content</a1>` },
@@ -61,6 +68,7 @@ func TestObjectStorageObjectResource_basic(t *testing.T) {
6168
6269 resourceName := "oci_objectstorage_object.test_object"
6370 datasourceName := "data.oci_objectstorage_objects.test_objects"
71+ singularDatasourceName := "data.oci_objectstorage_object.test_object"
6472
6573 var resId , resId2 string
6674 hexSum := md5 .Sum ([]byte ("content" ))
@@ -183,6 +191,47 @@ func TestObjectStorageObjectResource_basic(t *testing.T) {
183191 },
184192 ),
185193 },
194+ // verify singular datasource
195+ {
196+ Config : config + compartmentIdVariableStr + ObjectResourceDependencies +
197+ generateResourceFromRepresentationMap ("oci_objectstorage_object" , "test_object" , Optional , Update ,
198+ getUpdatedRepresentationCopy ("object" , Representation {repType : Required , create : `my-test-object-1` , update : `my-test-object-3` }, objectRepresentation )) +
199+ generateDataSourceFromRepresentationMap ("oci_objectstorage_object" , "test_object" , Required , Create , objectSingularDataSourceRepresentation ),
200+ Check : resource .ComposeAggregateTestCheckFunc (
201+ resource .TestCheckResourceAttr (singularDatasourceName , "content_encoding" , "identity" ),
202+ resource .TestCheckResourceAttr (singularDatasourceName , "content_language" , "en-CA" ),
203+ resource .TestCheckResourceAttr (singularDatasourceName , "content_length" , "16" ),
204+ resource .TestCheckResourceAttrSet (singularDatasourceName , "content_md5" ),
205+ resource .TestCheckResourceAttr (singularDatasourceName , "content_type" , "text/xml" ),
206+ resource .TestCheckResourceAttr (singularDatasourceName , "bucket" , "my-test-1" ),
207+ resource .TestCheckResourceAttrSet (singularDatasourceName , "content" ),
208+ resource .TestCheckResourceAttr (singularDatasourceName , "content" , "<a1>content</a1>" ),
209+ resource .TestCheckResourceAttr (singularDatasourceName , "metadata.%" , "1" ),
210+ resource .TestCheckResourceAttr (singularDatasourceName , "metadata.content-type" , "text/xml" ),
211+ resource .TestCheckResourceAttrSet (singularDatasourceName , "namespace" ),
212+ resource .TestCheckResourceAttr (singularDatasourceName , "object" , "my-test-object-3" ),
213+ ),
214+ },
215+ {
216+ Config : config + compartmentIdVariableStr + ObjectResourceDependencies +
217+ generateResourceFromRepresentationMap ("oci_objectstorage_object" , "test_object" , Optional , Update ,
218+ getUpdatedRepresentationCopy ("object" , Representation {repType : Required , create : `my-test-object-1` , update : `my-test-object-3` }, objectRepresentation )) +
219+ generateDataSourceFromRepresentationMap ("oci_objectstorage_object" , "test_object" , Optional , Create , objectSingularDataSourceRepresentation ),
220+ Check : resource .ComposeAggregateTestCheckFunc (
221+ resource .TestCheckResourceAttr (singularDatasourceName , "content_encoding" , "identity" ),
222+ resource .TestCheckResourceAttr (singularDatasourceName , "content_language" , "en-CA" ),
223+ resource .TestCheckResourceAttr (singularDatasourceName , "content_length" , "16" ),
224+ resource .TestCheckResourceAttrSet (singularDatasourceName , "content_md5" ),
225+ resource .TestCheckResourceAttr (singularDatasourceName , "content_type" , "text/xml" ),
226+ resource .TestCheckResourceAttr (singularDatasourceName , "bucket" , "my-test-1" ),
227+ resource .TestCheckResourceAttrSet (singularDatasourceName , "content" ),
228+ resource .TestCheckResourceAttr (singularDatasourceName , "content" , "<a1>content</a1>" ),
229+ resource .TestCheckResourceAttr (singularDatasourceName , "metadata.%" , "1" ),
230+ resource .TestCheckResourceAttr (singularDatasourceName , "metadata.content-type" , "text/xml" ),
231+ resource .TestCheckResourceAttrSet (singularDatasourceName , "namespace" ),
232+ resource .TestCheckResourceAttr (singularDatasourceName , "object" , "my-test-object-3" ),
233+ ),
234+ },
186235 // verify datasource
187236 {
188237 Config : config +
@@ -233,6 +282,70 @@ func TestObjectStorageObjectResource_basic(t *testing.T) {
233282 })
234283}
235284
285+ func TestObjectStorageObjectResource_failContentLengthLimit (t * testing.T ) {
286+ provider := testAccProvider
287+ config := testProviderConfig ()
288+
289+ compartmentId := getEnvSettingWithBlankDefault ("compartment_ocid" )
290+ compartmentIdVariableStr := fmt .Sprintf ("variable \" compartment_id\" { default = \" %s\" }\n " , compartmentId )
291+
292+ var resourceName = "oci_objectstorage_object.test_object"
293+ var failObjectName , failBucketName , failNamespaceName string
294+
295+ resource .Test (t , resource.TestCase {
296+ PreCheck : func () { testAccPreCheck (t ) },
297+ Providers : map [string ]terraform.ResourceProvider {
298+ "oci" : provider ,
299+ },
300+ Steps : []resource.TestStep {
301+ {
302+ Config : config + compartmentIdVariableStr + ObjectResourceDependencies +
303+ generateResourceFromRepresentationMap ("oci_objectstorage_object" , "test_object" , Optional , Update ,
304+ getUpdatedRepresentationCopy ("object" , Representation {repType : Required , create : `my-test-object-1` , update : `my-test-object-3` }, objectRepresentation )),
305+ Check : resource .ComposeAggregateTestCheckFunc (
306+ func (s * terraform.State ) (err error ) {
307+ failObjectName , err = fromInstanceState (s , resourceName , "object" )
308+ if err != nil {
309+ return err
310+ }
311+ failBucketName , err = fromInstanceState (s , resourceName , "bucket" )
312+ if err != nil {
313+ return err
314+ }
315+ failNamespaceName , err = fromInstanceState (s , resourceName , "namespace" )
316+ return err
317+ }),
318+ },
319+ {
320+ Config : config + compartmentIdVariableStr + ObjectResourceDependencies +
321+ generateResourceFromRepresentationMap ("oci_objectstorage_object" , "test_object" , Optional , Update ,
322+ getUpdatedRepresentationCopy ("object" , Representation {repType : Required , create : `my-test-object-1` , update : `my-test-object-3` }, objectRepresentation )) +
323+ generateDataSourceFromRepresentationMap ("oci_objectstorage_object" , "test_object" , Optional , Update , objectSingularDataSourceRepresentation ),
324+ ExpectError : regexp .MustCompile ("the requested object's content length is" ),
325+ },
326+ },
327+ })
328+
329+ //destroy test will be skipped since there is no state after the error in Get
330+ if failObjectName != "" && failBucketName != "" && failNamespaceName != "" {
331+ client := testAccProvider .Meta ().(* OracleClients ).objectStorageClient
332+ _ , objectErr := client .DeleteObject (context .Background (), oci_object_storage.DeleteObjectRequest {
333+ NamespaceName : & failNamespaceName ,
334+ BucketName : & failBucketName ,
335+ ObjectName : & failObjectName ,
336+ })
337+
338+ _ , bucketErr := client .DeleteBucket (context .Background (), oci_object_storage.DeleteBucketRequest {
339+ NamespaceName : & failNamespaceName ,
340+ BucketName : & failBucketName ,
341+ })
342+
343+ if objectErr != nil || bucketErr != nil {
344+ t .Errorf ("failed to delete resources for the test: %v, %v" , objectErr , bucketErr )
345+ }
346+ }
347+ }
348+
236349// This test is separated from the above test due to weird behavior from Terraform test framework.
237350// An test step that results in an error will result in the state being voided. Isolate such test steps to
238351// avoid interfering with regular tests that Create/Update resources.
0 commit comments