@@ -5,6 +5,8 @@ package oci
55
66import (
77 "fmt"
8+ "io/ioutil"
9+ "os"
810 "strconv"
911 "testing"
1012
3234 }
3335
3436 ArtifactByPathResourceDependencies = generateResourceFromRepresentationMap ("oci_artifacts_repository" , "test_repository" , Required , Create , repositoryRepresentation )
37+ // the deletion of oci_generic_artifacts_content_artifact_by_path is done by oci_artifacts_generic_artifact
38+ GenericArtifactManager = generateResourceFromRepresentationMap ("oci_artifacts_generic_artifact" , "test_generic_artifact" , Required , Create , genericArtifactRepresentation )
3539)
3640
3741// issue-routing-tag: generic_artifacts_content/default
@@ -57,7 +61,7 @@ func TestGenericArtifactsContentArtifactByPathResource_basic(t *testing.T) {
5761 // verify create
5862 {
5963 Config : config + compartmentIdVariableStr + ArtifactByPathResourceDependencies +
60- generateResourceFromRepresentationMap ("oci_generic_artifacts_content_artifact_by_path" , "test_artifact_by_path" , Required , Create , artifactByPathRepresentation ),
64+ generateResourceFromRepresentationMap ("oci_generic_artifacts_content_artifact_by_path" , "test_artifact_by_path" , Required , Create , artifactByPathRepresentation ) + GenericArtifactManager ,
6165 Check : ComposeAggregateTestCheckFuncWrapper (
6266
6367 func (s * terraform.State ) (err error ) {
@@ -75,7 +79,7 @@ func TestGenericArtifactsContentArtifactByPathResource_basic(t *testing.T) {
7579 // verify updates to updatable parameters
7680 {
7781 Config : config + compartmentIdVariableStr + ArtifactByPathResourceDependencies +
78- generateResourceFromRepresentationMap ("oci_generic_artifacts_content_artifact_by_path" , "test_artifact_by_path" , Optional , Update , artifactByPathRepresentation ),
82+ generateResourceFromRepresentationMap ("oci_generic_artifacts_content_artifact_by_path" , "test_artifact_by_path" , Optional , Update , artifactByPathRepresentation ) + GenericArtifactManager ,
7983 Check : ComposeAggregateTestCheckFuncWrapper (
8084
8185 func (s * terraform.State ) (err error ) {
@@ -87,11 +91,12 @@ func TestGenericArtifactsContentArtifactByPathResource_basic(t *testing.T) {
8791 },
8892 ),
8993 },
94+
9095 // verify singular datasource
9196 {
9297 Config : config +
9398 generateDataSourceFromRepresentationMap ("oci_generic_artifacts_content_artifact_by_path" , "test_artifact_by_path" , Required , Create , artifactByPathSingularDataSourceRepresentation ) +
94- compartmentIdVariableStr + ArtifactByPathResourceConfig ,
99+ compartmentIdVariableStr + ArtifactByPathResourceConfig + GenericArtifactManager ,
95100 Check : ComposeAggregateTestCheckFuncWrapper (
96101 resource .TestCheckResourceAttr (singularDatasourceName , "artifact_path" , "artifactPath" ),
97102 resource .TestCheckResourceAttrSet (singularDatasourceName , "repository_id" ),
@@ -100,3 +105,81 @@ func TestGenericArtifactsContentArtifactByPathResource_basic(t *testing.T) {
100105 },
101106 })
102107}
108+
109+ const (
110+ tempFilePrefix = "small-"
111+ tempFileSize = 2e5
112+ tempFileSha256 = "4cbbd9be0cba685835755f827758705db5a413c5494c34262cd25946a73e7582"
113+ )
114+
115+ func createTmpFile () (string , error ) {
116+ tempFile , err := ioutil .TempFile (os .TempDir (), tempFilePrefix )
117+ if err != nil {
118+ return "" , err
119+ }
120+ if err := tempFile .Truncate (tempFileSize ); err != nil {
121+ return "" , err
122+ }
123+ return tempFile .Name (), nil
124+ }
125+
126+ var (
127+ artifactByPathSourceRepresentation = map [string ]interface {}{
128+ "artifact_path" : Representation {repType : Required , create : `artifactPath` },
129+ "repository_id" : Representation {repType : Required , create : `${oci_artifacts_repository.test_repository.id}` },
130+ "version" : Representation {repType : Required , create : `1.0` },
131+ "source" : Representation {repType : Required , create : `` },
132+ }
133+ )
134+
135+ // issue-routing-tag: generic_artifacts_content/default
136+ func TestGenericArtifactsContentArtifactByPathResource_uploadFile (t * testing.T ) {
137+ httpreplay .SetScenario ("TestGenericArtifactsContentArtifactByPathResource_uploadFile" )
138+ defer httpreplay .SaveScenario ()
139+
140+ provider := testAccProvider
141+ config := testProviderConfig ()
142+
143+ compartmentId := getEnvSettingWithBlankDefault ("compartment_ocid" )
144+ compartmentIdVariableStr := fmt .Sprintf ("variable \" compartment_id\" { default = \" %s\" }\n " , compartmentId )
145+
146+ resourceName := "oci_generic_artifacts_content_artifact_by_path.test_artifact_by_path"
147+
148+ tempFilePath , err := createTmpFile ()
149+ if err != nil {
150+ t .Fatalf ("Unable to create file to upload. Error: %q" , err )
151+ }
152+
153+ var resId , _ string
154+ // Save TF content to create resource with only required properties. This has to be exactly the same as the config part in the create step in the test.
155+ saveConfigContent (config + compartmentIdVariableStr + ArtifactByPathResourceDependencies +
156+ generateResourceFromRepresentationMap ("oci_generic_artifacts_content_artifact_by_path" , "test_artifact_by_path" , Required , Create , artifactByPathRepresentation ), "genericartifactscontent" , "artifactByPath" , t )
157+
158+ resource .Test (t , resource.TestCase {
159+ PreCheck : func () { testAccPreCheck (t ) },
160+ Providers : map [string ]terraform.ResourceProvider {
161+ "oci" : provider ,
162+ },
163+ Steps : []resource.TestStep {
164+ // verify create
165+ {
166+ Config : config + compartmentIdVariableStr + ArtifactByPathResourceDependencies +
167+ generateResourceFromRepresentationMap ("oci_generic_artifacts_content_artifact_by_path" , "test_artifact_by_path" , Required , Create ,
168+ getUpdatedRepresentationCopy ("source" , Representation {repType : Required , create : tempFilePath }, artifactByPathSourceRepresentation )) + GenericArtifactManager ,
169+ Check : ComposeAggregateTestCheckFuncWrapper (
170+ resource .TestCheckResourceAttr (resourceName , "sha256" , tempFileSha256 ),
171+ resource .TestCheckResourceAttr (resourceName , "size_in_bytes" , strconv .Itoa (tempFileSize )),
172+ func (s * terraform.State ) (err error ) {
173+ resId , err = fromInstanceState (s , resourceName , "id" )
174+ if isEnableExportCompartment , _ := strconv .ParseBool (getEnvSettingWithDefault ("enable_export_compartment" , "true" )); isEnableExportCompartment {
175+ if errExport := testExportCompartmentWithResourceName (& resId , & compartmentId , resourceName ); errExport != nil {
176+ return errExport
177+ }
178+ }
179+ return err
180+ },
181+ ),
182+ },
183+ },
184+ })
185+ }
0 commit comments