Skip to content

Commit

Permalink
remove deprecated methods and use alternative methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yharish991 committed Aug 5, 2024
1 parent 99e1185 commit ecadaea
Show file tree
Hide file tree
Showing 105 changed files with 502 additions and 535 deletions.
21 changes: 10 additions & 11 deletions acceptance/config_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package acceptance
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand All @@ -28,7 +27,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 := ioutil.ReadFile(pivotalFile)
contents, err := os.ReadFile(pivotalFile)
Expect(err).ToNot(HaveOccurred())
modTime := time.Now()

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

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

productSlug, productVersion := "example-product", "1.0-build.0"
Expand All @@ -111,7 +110,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 := ioutil.TempDir("", "")
outputDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

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

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

expectedYAML := `.properties.example_required_cert_collection:
Expand All @@ -149,7 +148,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 := ioutil.TempDir("", "")
outputDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

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

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

expectedYAML := `.properties.required_secret_collection:
Expand All @@ -188,7 +187,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 := ioutil.ReadFile(pivotalFile)
contents, err := os.ReadFile(pivotalFile)
Expect(err).ToNot(HaveOccurred())
modTime := time.Now()

Expand Down Expand Up @@ -263,7 +262,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 := ioutil.TempDir("", "")
outputDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

productSlug, productVersion := "another-example-product", "1.0-build.0"
Expand All @@ -286,7 +285,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 := ioutil.TempDir("", "")
outputDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

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

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

command := exec.Command(pathToMain,
Expand Down
10 changes: 5 additions & 5 deletions acceptance/configure_director_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package acceptance

import (
"io/ioutil"
"net/http"
"os"
"os/exec"

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

It("displays a helpful error message when using moved director properties", func() {
configFile, err := ioutil.TempFile("", "config.yml")
configFile, err := os.CreateTemp("", "config.yml")
Expect(err).ToNot(HaveOccurred())
_, err = configFile.WriteString(`{
"iaas-configuration": {
Expand Down Expand Up @@ -93,7 +93,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 = ioutil.TempFile("", "config.yml")
configFile, err = os.CreateTemp("", "config.yml")
Expect(err).ToNot(HaveOccurred())
_, err = configFile.WriteString(`{
"what is this": "key?"
Expand Down Expand Up @@ -282,7 +282,7 @@ iaas-configurations:
}
`)

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

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

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

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

import (
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -171,7 +170,7 @@ var _ = Describe("configure-product command", func() {
),
)

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

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

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

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

import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -62,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 := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "example-product.pivotal",
Expand Down Expand Up @@ -91,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 := ioutil.ReadFile(filepath.Join(tmpDir, "assign-stemcell.yml"))
contents, err := os.ReadFile(filepath.Join(tmpDir, "assign-stemcell.yml"))
Expect(err).ToNot(HaveOccurred())
Expect(string(contents)).To(MatchYAML(`{product: example-product, stemcell: "97.57"}`))

Expand Down
21 changes: 10 additions & 11 deletions acceptance/download_product_gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package acceptance
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -49,9 +48,9 @@ var _ = Describe("download-product command", func() {
}{}
err = json.Unmarshal([]byte(serviceAccountKey), &clientEmail)
Expect(err).ToNot(HaveOccurred())
authFile, err := ioutil.TempFile("", "")
authFile, err := os.CreateTemp("", "")
Expect(err).ToNot(HaveOccurred())
err = ioutil.WriteFile(authFile.Name(), []byte(serviceAccountKey), 0600)
err = os.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 @@ -69,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 := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "example-product.pivotal",
Expand All @@ -96,7 +95,7 @@ var _ = Describe("download-product command", func() {
Expect(err).ToNot(HaveOccurred())

By("ensuring an assign stemcell artifact is created")
contents, err := ioutil.ReadFile(filepath.Join(tmpDir, "assign-stemcell.yml"))
contents, err := os.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 @@ -129,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 := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand All @@ -155,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 := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand Down Expand Up @@ -187,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 := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
command := exec.Command(pathToMain, "download-product",
"--file-glob", "*.yml",
Expand Down Expand Up @@ -216,7 +215,7 @@ var _ = Describe("download-product command", func() {
})

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit ecadaea

Please sign in to comment.