Skip to content

Commit

Permalink
Revert "remove deprecated methods and use alternative methods"
Browse files Browse the repository at this point in the history
This reverts commit 4d2f0a6.
  • Loading branch information
yharish991 committed Aug 5, 2024
1 parent 4d2f0a6 commit dd0bf20
Show file tree
Hide file tree
Showing 105 changed files with 623 additions and 643 deletions.
21 changes: 11 additions & 10 deletions acceptance/config_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package acceptance
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand All @@ -28,7 +29,7 @@ var _ = Describe("config-template command", func() {
When("there is only one .pivotal file for the product version", func() {
BeforeEach(func() {
pivotalFile := createPivotalFile("[example-product,1.10.1]example*pivotal", "./fixtures/example-product.yml")
contents, err := os.ReadFile(pivotalFile)
contents, err := ioutil.ReadFile(pivotalFile)
Expect(err).ToNot(HaveOccurred())
modTime := time.Now()

Expand Down Expand Up @@ -85,7 +86,7 @@ var _ = Describe("config-template command", func() {
})

It("writes a config template subdir for the product in the output directory", func() {
outputDir, err := os.MkdirTemp("", "")
outputDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())

productSlug, productVersion := "example-product", "1.0-build.0"
Expand All @@ -111,7 +112,7 @@ var _ = Describe("config-template command", func() {

When("the metadata contains a required collection that contains a cert", func() {
It("renders the cert fields appropriately in the product.yml", func() {
outputDir, err := os.MkdirTemp("", "")
outputDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())

productSlug, metadataName, productVersion := "example-product", "example-product", "1.0-build.0"
Expand All @@ -134,7 +135,7 @@ var _ = Describe("config-template command", func() {
productYMLFile := filepath.Join(outputDir, metadataName, productVersion, "product.yml")
Expect(productYMLFile).To(BeAnExistingFile())

productYMLBytes, err := os.ReadFile(productYMLFile)
productYMLBytes, err := ioutil.ReadFile(productYMLFile)
Expect(err).ToNot(HaveOccurred())

expectedYAML := `.properties.example_required_cert_collection:
Expand All @@ -149,7 +150,7 @@ var _ = Describe("config-template command", func() {

When("the metadata contains a required collection that contains a cert", func() {
It("renders the cert fields appropriately in the product.yml", func() {
outputDir, err := os.MkdirTemp("", "")
outputDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())

productSlug, metadataName, productVersion := "example-product", "example-product", "1.0-build.0"
Expand All @@ -172,7 +173,7 @@ var _ = Describe("config-template command", func() {
productYMLFile := filepath.Join(outputDir, metadataName, productVersion, "product.yml")
Expect(productYMLFile).To(BeAnExistingFile())

productYMLBytes, err := os.ReadFile(productYMLFile)
productYMLBytes, err := ioutil.ReadFile(productYMLFile)
Expect(err).ToNot(HaveOccurred())

expectedYAML := `.properties.required_secret_collection:
Expand All @@ -188,7 +189,7 @@ var _ = Describe("config-template command", func() {
When("there is more than one .pivotal file for a product version", func() {
BeforeEach(func() {
pivotalFile := createPivotalFile("[example-product,1.10.1]example*pivotal", "./fixtures/example-product.yml")
contents, err := os.ReadFile(pivotalFile)
contents, err := ioutil.ReadFile(pivotalFile)
Expect(err).ToNot(HaveOccurred())
modTime := time.Now()

Expand Down Expand Up @@ -263,7 +264,7 @@ var _ = Describe("config-template command", func() {
})
Context("and the user has not provided a product file glob", func() {
It("errors because the default glob did not match", func() {
outputDir, err := os.MkdirTemp("", "")
outputDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())

productSlug, productVersion := "another-example-product", "1.0-build.0"
Expand All @@ -286,7 +287,7 @@ var _ = Describe("config-template command", func() {
})
Context("and the user has provided a glob with a unique match", func() {
It("writes a config template subdir for the product in the output directory", func() {
outputDir, err := os.MkdirTemp("", "")
outputDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())

productSlug, productVersion := "another-example-product", "1.0-build.0"
Expand Down Expand Up @@ -320,7 +321,7 @@ var _ = Describe("config-template output", func() {
Skip("TEST_PIVNET_TOKEN not specified")
}

outputDir, err := os.MkdirTemp("", "")
outputDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())

command := exec.Command(pathToMain,
Expand Down
13 changes: 6 additions & 7 deletions acceptance/configure_director_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package acceptance

import (
"github.com/onsi/gomega/ghttp"
"io/ioutil"
"net/http"
"os"
"os/exec"

"github.com/onsi/gomega/ghttp"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
Expand Down Expand Up @@ -36,7 +35,7 @@ var _ = Describe("configure-director command", func() {
})

It("displays a helpful error message when using moved director properties", func() {
configFile, err := os.CreateTemp("", "config.yml")
configFile, err := ioutil.TempFile("", "config.yml")
Expect(err).ToNot(HaveOccurred())
_, err = configFile.WriteString(`{
"iaas-configuration": {
Expand Down Expand Up @@ -93,7 +92,7 @@ var _ = Describe("configure-director command", func() {
Expect(session.Err).To(gbytes.Say("The following keys have recently been removed from the top level configuration: director-configuration, iaas-configuration, security-configuration, syslog-configuration"))
Expect(session.Err).To(gbytes.Say("To fix this error, move the above keys under 'properties-configuration' and change their dashes to underscores."))

configFile, err = os.CreateTemp("", "config.yml")
configFile, err = ioutil.TempFile("", "config.yml")
Expect(err).ToNot(HaveOccurred())
_, err = configFile.WriteString(`{
"what is this": "key?"
Expand Down Expand Up @@ -282,7 +281,7 @@ iaas-configurations:
}
`)

tempfile, err := os.CreateTemp("", "config.yaml")
tempfile, err := ioutil.TempFile("", "config.yaml")
Expect(err).ToNot(HaveOccurred())

_, err = tempfile.Write(configYAML)
Expand Down Expand Up @@ -375,7 +374,7 @@ iaas-configurations:
}
`)

tempfile, err := os.CreateTemp("", "config.yaml")
tempfile, err := ioutil.TempFile("", "config.yaml")
Expect(err).ToNot(HaveOccurred())

_, err = tempfile.Write(configYAML)
Expand Down
8 changes: 4 additions & 4 deletions acceptance/configure_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package acceptance

import (
"fmt"
"github.com/onsi/gomega/ghttp"
"io/ioutil"
"net/http"
"os"
"os/exec"

"github.com/onsi/gomega/ghttp"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
Expand Down Expand Up @@ -170,7 +170,7 @@ var _ = Describe("configure-product command", func() {
),
)

configFile, err = os.CreateTemp("", "")
configFile, err = ioutil.TempFile("", "")
Expect(err).ToNot(HaveOccurred())

_, err = configFile.WriteString(configFileContents)
Expand Down Expand Up @@ -256,7 +256,7 @@ var _ = Describe("configure-product command", func() {
"resource-config": %s
}`, propertiesJSON, productNetworkJSON, nsxResourceConfigJSON)

configFile, err = os.CreateTemp("", "")
configFile, err = ioutil.TempFile("", "")
Expect(err).ToNot(HaveOccurred())

_, err = configFile.WriteString(nsxConfigFileContents)
Expand Down
10 changes: 5 additions & 5 deletions acceptance/download_product_azure_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package acceptance

import (
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
"io/ioutil"
"os"
"os/exec"
"path/filepath"

"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -61,7 +61,7 @@ var _ = Describe("download-product command", func() {
az("storage", "blob", "upload", "--overwrite", "-f", pivotalFile, "-n", "/some/product/[pivnet-example-slug,1.10.1]example-product.pivotal")
az("storage", "blob", "upload", "--overwrite", "-f", pivotalFile, "-n", "/another/stemcell/[stemcells-ubuntu-xenial,97.57]light-bosh-stemcell-97.57-google-kvm-ubuntu-xenial-go_agent.tgz")

tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "example-product.pivotal",
Expand Down Expand Up @@ -90,7 +90,7 @@ var _ = Describe("download-product command", func() {
Expect(filepath.Join(tmpDir, "[stemcells-ubuntu-xenial,97.57]light-bosh-stemcell-97.57-google-kvm-ubuntu-xenial-go_agent.tgz.partial")).ToNot(BeAnExistingFile())

By("ensuring an assign stemcell artifact is created")
contents, err := os.ReadFile(filepath.Join(tmpDir, "assign-stemcell.yml"))
contents, err := ioutil.ReadFile(filepath.Join(tmpDir, "assign-stemcell.yml"))
Expect(err).ToNot(HaveOccurred())
Expect(string(contents)).To(MatchYAML(`{product: example-product, stemcell: "97.57"}`))

Expand Down
26 changes: 13 additions & 13 deletions acceptance/download_product_gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package acceptance
import (
"encoding/json"
"fmt"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"time"

"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -48,9 +48,9 @@ var _ = Describe("download-product command", func() {
}{}
err = json.Unmarshal([]byte(serviceAccountKey), &clientEmail)
Expect(err).ToNot(HaveOccurred())
authFile, err := os.CreateTemp("", "")
authFile, err := ioutil.TempFile("", "")
Expect(err).ToNot(HaveOccurred())
err = os.WriteFile(authFile.Name(), []byte(serviceAccountKey), 0600)
err = ioutil.WriteFile(authFile.Name(), []byte(serviceAccountKey), 0600)
Expect(err).ToNot(HaveOccurred())
Expect(authFile.Close()).ToNot(HaveOccurred())
runCommand("gcloud", "auth", "activate-service-account", clientEmail.Email, "--key-file", authFile.Name())
Expand All @@ -68,7 +68,7 @@ var _ = Describe("download-product command", func() {
uploadGCSFile(pivotalFile, serviceAccountKey, bucketName, "some/product/[pivnet-example-slug,1.10.1]example-product.pivotal")
uploadGCSFile(pivotalFile, serviceAccountKey, bucketName, "another/stemcell/[stemcells-ubuntu-xenial,97.57]light-bosh-stemcell-97.57-google-kvm-ubuntu-xenial-go_agent.tgz")

tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "example-product.pivotal",
Expand All @@ -95,7 +95,7 @@ var _ = Describe("download-product command", func() {
Expect(err).ToNot(HaveOccurred())

By("ensuring an assign stemcell artifact is created")
contents, err := os.ReadFile(filepath.Join(tmpDir, "assign-stemcell.yml"))
contents, err := ioutil.ReadFile(filepath.Join(tmpDir, "assign-stemcell.yml"))
Expect(err).ToNot(HaveOccurred())
Expect(string(contents)).To(MatchYAML(`{product: example-product, stemcell: "97.57"}`))

Expand Down Expand Up @@ -128,7 +128,7 @@ var _ = Describe("download-product command", func() {

When("the bucket does not exist", func() {
It("gives a helpful error message", func() {
tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand All @@ -154,7 +154,7 @@ var _ = Describe("download-product command", func() {
When("no files exist in the bucket", func() {
// The bucket we get from the before each is already empty, so, no setup
It("raises an error saying that no automation-downloaded files were found", func() {
tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand Down Expand Up @@ -186,7 +186,7 @@ var _ = Describe("download-product command", func() {
})

It("raises an error that no files with a prefixed name matching the slug and version are available", func() {
tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand Down Expand Up @@ -215,7 +215,7 @@ var _ = Describe("download-product command", func() {
})

It("outputs the file and downloaded file metadata", func() {
tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand Down Expand Up @@ -251,7 +251,7 @@ var _ = Describe("download-product command", func() {
})

It("raises an error that too many files match the glob", func() {
tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand All @@ -278,7 +278,7 @@ var _ = Describe("download-product command", func() {
})

It("raises an error that too many files match the glob", func() {
tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand Down
13 changes: 7 additions & 6 deletions acceptance/download_product_pivnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand All @@ -29,7 +30,7 @@ var _ = Describe("download-product command", func() {

BeforeEach(func() {
pivotalFile := createPivotalFile("[pivnet-product,1.10.1]example*pivotal", "./fixtures/example-product.yml")
pivotalContents, err := os.ReadFile(pivotalFile)
pivotalContents, err := ioutil.ReadFile(pivotalFile)
Expect(err).ToNot(HaveOccurred())
modTime := time.Now()

Expand Down Expand Up @@ -194,7 +195,7 @@ var _ = Describe("download-product command", func() {
})

It("downloads the product", func() {
tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--pivnet-api-token", "token",
Expand Down Expand Up @@ -235,7 +236,7 @@ var _ = Describe("download-product command", func() {
ghttp.RespondWith(http.StatusOK, `{"info":{"version":"2.4.0"}}`),
)

tmpDir, err := os.MkdirTemp("", "")
tmpDir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain,
"-k",
Expand Down Expand Up @@ -267,20 +268,20 @@ var _ = Describe("download-product command", func() {

func fileContents(paths ...string) []byte {
path := filepath.Join(paths...)
contents, err := os.ReadFile(filepath.Join(path))
contents, err := ioutil.ReadFile(filepath.Join(path))
Expect(err).ToNot(HaveOccurred())
return contents
}

func createPivotalFile(productFileName, metadataFilename string) string {
tempfile, err := os.CreateTemp("", productFileName)
tempfile, err := ioutil.TempFile("", productFileName)
Expect(err).ToNot(HaveOccurred())

zipper := zip.NewWriter(tempfile)
file, err := zipper.Create("metadata/props.yml")
Expect(err).ToNot(HaveOccurred())

contents, err := os.ReadFile(metadataFilename)
contents, err := ioutil.ReadFile(metadataFilename)
Expect(err).ToNot(HaveOccurred())

_, err = file.Write(contents)
Expand Down
Loading

0 comments on commit dd0bf20

Please sign in to comment.