diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000000..1e261449f4c --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,56 @@ +name: golangci-lint + +on: + push: + tags: + - "v9.*" + - "v8.*" + - "v7.*" + pull_request: + types: + - opened + - reopened + - synchronize + branches: + - main + - v9 + - v8 + - v7 + paths-ignore: + - "doc/**" + - ".gitpod.yml" + - "README.md" + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - uses: actions/checkout@v4 + with: + fetch-depth: '0' + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 + args: -v --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin + format: + name: Run go fmt + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + - name: Set Up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - name: Run go fmt + run: go fmt && git diff --exit-code diff --git a/.github/workflows/tests-unit.yml b/.github/workflows/tests-unit.yml index 5de82349550..51b23b8132c 100644 --- a/.github/workflows/tests-unit.yml +++ b/.github/workflows/tests-unit.yml @@ -26,23 +26,6 @@ defaults: shell: bash jobs: - lint: - name: Lint code - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v4 - - - name: Set Up Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - check-latest: true - - - name: Run go fmt - run: go fmt && git diff --exit-code - units: name: Units strategy: diff --git a/.golangci.json b/.golangci.json index d116b5a620b..342a9574c4b 100644 --- a/.golangci.json +++ b/.golangci.json @@ -1,10 +1,7 @@ { "run": { "concurrency": 4, - "timeout": "20m", - "skip-files": [ - "integration/helpers/fake_server.go" - ] + "timeout": "20m" }, "linters": { "disable-all": true, @@ -14,15 +11,16 @@ "errcheck", "staticcheck", "unused", - "structcheck", - "varcheck", - "ineffassign", - "deadcode" + "ineffassign" ] }, "linters-settings": {}, "issues": { "max-same-issue": 0, + "exclude-files": [ + "integration/helpers/fake_server.go", + "command/plugin/*.go$" + ], "exclude": [ "Error return value of `client.GetApplicationTasks` is not checked", "Error return value of `logger.output.Stop` is not checked", diff --git a/Makefile b/Makefile index 5350c48500b..949eb9be363 100644 --- a/Makefile +++ b/Makefile @@ -141,11 +141,9 @@ integration-tests-full-ci: install-test-deps integration-cleanup integration/shared/isolated integration/v7/isolated integration/shared/plugin integration/shared/experimental integration/v7/experimental integration/v7/push $(ginkgo_int) -flake-attempts $(FLAKE_ATTEMPTS) integration/shared/global integration/v7/global -lint: ## Runs all linters and formatters +lint: format ## Runs all linters and formatters @echo "Running linters..." - go list -f "{{.Dir}}" ./... \ - | grep -v -e "/cf/" -e "/fixtures/" -e "/assets/" -e "/plugin/" -e "/command/plugin" -e "fakes" \ - | xargs golangci-lint run + golangci-lint run --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin @echo "No lint errors!" # TODO: version specific tagging for all these builds diff --git a/actor/pluginaction/checksum_test.go b/actor/pluginaction/checksum_test.go index b1c5306f811..c3e4f0fdd82 100644 --- a/actor/pluginaction/checksum_test.go +++ b/actor/pluginaction/checksum_test.go @@ -1,7 +1,6 @@ package pluginaction_test import ( - "io/ioutil" "os" . "code.cloudfoundry.org/cli/actor/pluginaction" @@ -25,11 +24,11 @@ var _ = Describe("Checksums", func() { var file *os.File BeforeEach(func() { var err error - file, err = ioutil.TempFile("", "") + file, err = os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) defer file.Close() - err = ioutil.WriteFile(file.Name(), []byte("foo"), 0600) + err = os.WriteFile(file.Name(), []byte("foo"), 0600) Expect(err).NotTo(HaveOccurred()) }) diff --git a/actor/pluginaction/install.go b/actor/pluginaction/install.go index 9ca3421fd82..fece3960340 100644 --- a/actor/pluginaction/install.go +++ b/actor/pluginaction/install.go @@ -1,7 +1,6 @@ package pluginaction import ( - "io/ioutil" "os" "path/filepath" "sort" @@ -189,7 +188,7 @@ func (actor Actor) InstallPluginFromPath(path string, plugin configv3.Plugin) er } func makeTempFile(tempDir string) (*os.File, error) { - tempFile, err := ioutil.TempFile(tempDir, "") + tempFile, err := os.CreateTemp(tempDir, "") if err != nil { return nil, err } diff --git a/actor/pluginaction/install_test.go b/actor/pluginaction/install_test.go index f3552b63e75..7b4830dd52f 100644 --- a/actor/pluginaction/install_test.go +++ b/actor/pluginaction/install_test.go @@ -2,7 +2,6 @@ package pluginaction_test import ( "errors" - "io/ioutil" "os" "path/filepath" @@ -32,7 +31,7 @@ var _ = Describe("install actions", func() { actor = NewActor(fakeConfig, fakeClient) var err error - tempPluginDir, err = ioutil.TempDir("", "") + tempPluginDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) }) @@ -46,7 +45,7 @@ var _ = Describe("install actions", func() { var pluginPath string BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "") + tempFile, err := os.CreateTemp("", "") Expect(err).ToNot(HaveOccurred()) _, err = tempFile.WriteString("cthulhu") @@ -66,7 +65,7 @@ var _ = Describe("install actions", func() { copyPath, err := actor.CreateExecutableCopy(pluginPath, tempPluginDir) Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(copyPath) + contents, err := os.ReadFile(copyPath) Expect(err).ToNot(HaveOccurred()) Expect(contents).To(BeEquivalentTo("cthulhu")) }) @@ -101,14 +100,14 @@ var _ = Describe("install actions", func() { BeforeEach(func() { data = []byte("some test data") fakeClient.DownloadPluginStub = func(_ string, path string, _ plugin.ProxyReader) error { - err := ioutil.WriteFile(path, data, 0700) + err := os.WriteFile(path, data, 0700) Expect(err).ToNot(HaveOccurred()) return nil } }) It("returns the path to the file and the size", func() { Expect(downloadErr).ToNot(HaveOccurred()) - fileData, err := ioutil.ReadFile(path) + fileData, err := os.ReadFile(path) Expect(err).ToNot(HaveOccurred()) Expect(fileData).To(Equal(data)) @@ -139,7 +138,7 @@ var _ = Describe("install actions", func() { When("the file exists", func() { BeforeEach(func() { - pluginFile, err := ioutil.TempFile("", "") + pluginFile, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) err = pluginFile.Close() Expect(err).NotTo(HaveOccurred()) @@ -661,14 +660,14 @@ var _ = Describe("install actions", func() { }, } - pluginFile, err := ioutil.TempFile("", "") + pluginFile, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) err = pluginFile.Close() Expect(err).NotTo(HaveOccurred()) pluginPath = pluginFile.Name() - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) pluginHomeDir = filepath.Join(tempDir, ".cf", "plugin") diff --git a/actor/pluginaction/install_unix_test.go b/actor/pluginaction/install_unix_test.go index 343acd4a56f..5f0fa9b6113 100644 --- a/actor/pluginaction/install_unix_test.go +++ b/actor/pluginaction/install_unix_test.go @@ -4,7 +4,6 @@ package pluginaction_test import ( - "io/ioutil" "os" "path/filepath" @@ -26,7 +25,7 @@ var _ = Describe("install actions", func() { BeforeEach(func() { fakeConfig = new(pluginactionfakes.FakeConfig) var err error - tempPluginDir, err = ioutil.TempDir("", "") + tempPluginDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) actor = NewActor(fakeConfig, nil) }) @@ -41,7 +40,7 @@ var _ = Describe("install actions", func() { var pluginPath string BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "") + tempFile, err := os.CreateTemp("", "") Expect(err).ToNot(HaveOccurred()) _, err = tempFile.WriteString("cthulhu") @@ -86,14 +85,14 @@ var _ = Describe("install actions", func() { }, } - pluginFile, err := ioutil.TempFile("", "") + pluginFile, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) err = pluginFile.Close() Expect(err).NotTo(HaveOccurred()) pluginPath = pluginFile.Name() - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) pluginHomeDir = filepath.Join(tempDir, ".cf", "plugin") diff --git a/actor/pluginaction/install_windows_test.go b/actor/pluginaction/install_windows_test.go index e2576c93684..b62c3da5d8e 100644 --- a/actor/pluginaction/install_windows_test.go +++ b/actor/pluginaction/install_windows_test.go @@ -4,7 +4,6 @@ package pluginaction_test import ( - "io/ioutil" "os" . "code.cloudfoundry.org/cli/actor/pluginaction" @@ -23,7 +22,7 @@ var _ = Describe("install actions", func() { BeforeEach(func() { fakeConfig = new(pluginactionfakes.FakeConfig) var err error - tempPluginDir, err = ioutil.TempDir("", "") + tempPluginDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) actor = NewActor(fakeConfig, nil) }) @@ -38,7 +37,7 @@ var _ = Describe("install actions", func() { var pluginPath string BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "") + tempFile, err := os.CreateTemp("", "") Expect(err).ToNot(HaveOccurred()) _, err = tempFile.WriteString("cthulhu") diff --git a/actor/pluginaction/uninstall_test.go b/actor/pluginaction/uninstall_test.go index ab032e71178..944ee5c5075 100644 --- a/actor/pluginaction/uninstall_test.go +++ b/actor/pluginaction/uninstall_test.go @@ -2,7 +2,6 @@ package pluginaction_test import ( "errors" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -35,11 +34,11 @@ var _ = Describe("Plugin actor", func() { BeforeEach(func() { var err error - pluginHome, err = ioutil.TempDir("", "") + pluginHome, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) binaryPath = filepath.Join(pluginHome, "banana-faceman") - err = ioutil.WriteFile(binaryPath, nil, 0600) + err = os.WriteFile(binaryPath, nil, 0600) Expect(err).ToNot(HaveOccurred()) fakePluginUninstaller = new(pluginactionfakes.FakePluginUninstaller) @@ -188,7 +187,7 @@ var _ = Describe("Plugin actor", func() { Expect(err).ToNot(HaveOccurred()) err = os.Mkdir(binaryPath, 0700) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(binaryPath, "foooooo"), nil, 0500) + err = os.WriteFile(filepath.Join(binaryPath, "foooooo"), nil, 0500) Expect(err).ToNot(HaveOccurred()) }) diff --git a/actor/sharedaction/resource.go b/actor/sharedaction/resource.go index 944883be0eb..1a98ef16761 100644 --- a/actor/sharedaction/resource.go +++ b/actor/sharedaction/resource.go @@ -5,7 +5,6 @@ import ( "crypto/sha1" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -214,7 +213,7 @@ func (actor Actor) GatherDirectoryResources(sourceDir string) ([]Resource, error // filemode for user is forced to be readable and executable. func (actor Actor) ZipArchiveResources(sourceArchivePath string, filesToInclude []Resource) (string, error) { log.WithField("sourceArchive", sourceArchivePath).Info("zipping source files from archive") - zipFile, err := ioutil.TempFile("", "cf-cli-") + zipFile, err := os.CreateTemp("", "cf-cli-") if err != nil { return "", err } @@ -274,7 +273,7 @@ func (actor Actor) ZipArchiveResources(sourceArchivePath string, filesToInclude // filemode for user is forced to be readable and executable. func (actor Actor) ZipDirectoryResources(sourceDir string, filesToInclude []Resource) (string, error) { log.WithField("sourceDir", sourceDir).Info("zipping source files from directory") - zipFile, err := ioutil.TempFile("", "cf-cli-") + zipFile, err := os.CreateTemp("", "cf-cli-") if err != nil { return "", err } @@ -434,7 +433,7 @@ func (Actor) generateArchiveCFIgnoreMatcher(files []*zip.File) (*ignore.GitIgnor } defer fileReader.Close() - raw, err := ioutil.ReadAll(fileReader) + raw, err := io.ReadAll(fileReader) if err != nil { return nil, err } diff --git a/actor/sharedaction/resource_darwin_test.go b/actor/sharedaction/resource_darwin_test.go index 48e8b278d4f..107b564bc73 100644 --- a/actor/sharedaction/resource_darwin_test.go +++ b/actor/sharedaction/resource_darwin_test.go @@ -4,7 +4,6 @@ package sharedaction_test import ( - "io/ioutil" "os" "path/filepath" @@ -31,20 +30,20 @@ var _ = Describe("Resource Actions", func() { // tmpfile3 var err error - srcDir, err = ioutil.TempDir("", "v2-resource-actions") + srcDir, err = os.MkdirTemp("", "v2-resource-actions") Expect(err).ToNot(HaveOccurred()) subDir := filepath.Join(srcDir, "level1", "level2") err = os.MkdirAll(subDir, 0777) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0644) + err = os.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0644) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0751) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0751) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0655) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0655) Expect(err).ToNot(HaveOccurred()) err = os.Symlink("file-that-may-or-may-not-exist", filepath.Join(srcDir, "symlink1")) @@ -64,7 +63,7 @@ var _ = Describe("Resource Actions", func() { ) BeforeEach(func() { - tmpfile, err := ioutil.TempFile("", "example") + tmpfile, err := os.CreateTemp("", "example") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()).ToNot(HaveOccurred()) @@ -111,7 +110,7 @@ var _ = Describe("Resource Actions", func() { When("a symlink file points to an existing file", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, "file-that-may-or-may-not-exist"), []byte("Bananarama"), 0655) + err := os.WriteFile(filepath.Join(srcDir, "file-that-may-or-may-not-exist"), []byte("Bananarama"), 0655) Expect(err).ToNot(HaveOccurred()) }) diff --git a/actor/sharedaction/resource_linux_test.go b/actor/sharedaction/resource_linux_test.go index 7ef10775d96..1f717317f63 100644 --- a/actor/sharedaction/resource_linux_test.go +++ b/actor/sharedaction/resource_linux_test.go @@ -4,7 +4,6 @@ package sharedaction_test import ( - "io/ioutil" "os" "path/filepath" @@ -31,20 +30,20 @@ var _ = Describe("Resource Actions", func() { // tmpfile3 var err error - srcDir, err = ioutil.TempDir("", "v2-resource-actions") + srcDir, err = os.MkdirTemp("", "v2-resource-actions") Expect(err).ToNot(HaveOccurred()) subDir := filepath.Join(srcDir, "level1", "level2") err = os.MkdirAll(subDir, 0777) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0644) + err = os.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0644) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0751) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0751) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0655) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0655) Expect(err).ToNot(HaveOccurred()) err = os.Symlink("file-that-may-or-may-not-exist", filepath.Join(srcDir, "symlink1")) @@ -64,7 +63,7 @@ var _ = Describe("Resource Actions", func() { ) BeforeEach(func() { - tmpfile, err := ioutil.TempFile("", "example") + tmpfile, err := os.CreateTemp("", "example") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()).ToNot(HaveOccurred()) @@ -111,7 +110,7 @@ var _ = Describe("Resource Actions", func() { When("a symlink file points to an existing file", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, "file-that-may-or-may-not-exist"), []byte("Bananarama"), 0655) + err := os.WriteFile(filepath.Join(srcDir, "file-that-may-or-may-not-exist"), []byte("Bananarama"), 0655) Expect(err).ToNot(HaveOccurred()) }) diff --git a/actor/sharedaction/resource_test.go b/actor/sharedaction/resource_test.go index 96188bce3f9..1bfadd2309e 100644 --- a/actor/sharedaction/resource_test.go +++ b/actor/sharedaction/resource_test.go @@ -3,7 +3,6 @@ package sharedaction_test import ( "archive/zip" "io" - "io/ioutil" "os" "path/filepath" @@ -34,20 +33,20 @@ var _ = Describe("Resource Actions", func() { // tmpfile3 var err error - srcDir, err = ioutil.TempDir("", "resource-actions-test") + srcDir, err = os.MkdirTemp("", "resource-actions-test") Expect(err).ToNot(HaveOccurred()) subDir := filepath.Join(srcDir, "level1", "level2") err = os.MkdirAll(subDir, 0777) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0600) + err = os.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0600) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0600) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0600) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0600) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0600) Expect(err).ToNot(HaveOccurred()) relativePath, err := filepath.Rel(srcDir, subDir) @@ -69,7 +68,7 @@ var _ = Describe("Resource Actions", func() { Describe("SharedToV3Resource", func() { var returnedV3Resource V3Resource - var sharedResource = Resource{Filename: "file1", SHA1: "a43rknl", Mode: os.FileMode(644), Size: 100000} + var sharedResource = Resource{Filename: "file1", SHA1: "a43rknl", Mode: os.FileMode(0644), Size: 100000} JustBeforeEach(func() { returnedV3Resource = sharedResource.ToV3Resource() @@ -82,7 +81,7 @@ var _ = Describe("Resource Actions", func() { Value: "a43rknl", }, SizeInBytes: 100000, - Mode: os.FileMode(644), + Mode: os.FileMode(0644), })) }) @@ -97,7 +96,7 @@ var _ = Describe("Resource Actions", func() { Value: "a43rknl", }, SizeInBytes: 100000, - Mode: os.FileMode(644), + Mode: os.FileMode(0644), } JustBeforeEach(func() { @@ -105,7 +104,7 @@ var _ = Describe("Resource Actions", func() { }) It("returns a ccv3 Resource", func() { - Expect(returnedSharedResource).To(Equal(Resource{Filename: "file1", SHA1: "a43rknl", Mode: os.FileMode(644), Size: 100000})) + Expect(returnedSharedResource).To(Equal(Resource{Filename: "file1", SHA1: "a43rknl", Mode: os.FileMode(0644), Size: 100000})) }) }) @@ -137,7 +136,7 @@ var _ = Describe("Resource Actions", func() { When("the archive can be accessed properly", func() { BeforeEach(func() { - tmpfile, err := ioutil.TempFile("", "fake-archive") + tmpfile, err := os.CreateTemp("", "fake-archive") Expect(err).ToNot(HaveOccurred()) _, err = tmpfile.Write([]byte("123456")) Expect(err).ToNot(HaveOccurred()) @@ -176,7 +175,7 @@ var _ = Describe("Resource Actions", func() { ) BeforeEach(func() { - tmpfile, err := ioutil.TempFile("", "zip-archive-resources") + tmpfile, err := os.CreateTemp("", "zip-archive-resources") Expect(err).ToNot(HaveOccurred()) defer tmpfile.Close() archive = tmpfile.Name() @@ -429,7 +428,7 @@ func expectFileContentsToEqual(file *zip.File, expectedContents string) { Expect(err).ToNot(HaveOccurred()) defer reader.Close() - body, err := ioutil.ReadAll(reader) + body, err := io.ReadAll(reader) Expect(err).ToNot(HaveOccurred()) Expect(string(body)).To(Equal(expectedContents)) diff --git a/actor/sharedaction/resource_unix_test.go b/actor/sharedaction/resource_unix_test.go index 3892c07d871..1f19be1308f 100644 --- a/actor/sharedaction/resource_unix_test.go +++ b/actor/sharedaction/resource_unix_test.go @@ -4,7 +4,6 @@ package sharedaction_test import ( - "io/ioutil" "os" "path/filepath" @@ -33,20 +32,20 @@ var _ = Describe("Resource Actions", func() { // tmpfile3 var err error - srcDir, err = ioutil.TempDir("", "v2-resource-actions") + srcDir, err = os.MkdirTemp("", "v2-resource-actions") Expect(err).ToNot(HaveOccurred()) subDir := filepath.Join(srcDir, "level1", "level2") err = os.MkdirAll(subDir, 0777) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0644) + err = os.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0644) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0751) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0751) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0655) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0655) Expect(err).ToNot(HaveOccurred()) }) @@ -64,7 +63,7 @@ var _ = Describe("Resource Actions", func() { ) BeforeEach(func() { - tmpfile, err := ioutil.TempFile("", "example") + tmpfile, err := os.CreateTemp("", "example") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()).ToNot(HaveOccurred()) @@ -84,7 +83,7 @@ var _ = Describe("Resource Actions", func() { When("archive is empty", func() { BeforeEach(func() { var err error - srcDir, err = ioutil.TempDir("", "v2-resource-actions-empty") + srcDir, err = os.MkdirTemp("", "v2-resource-actions-empty") Expect(err).ToNot(HaveOccurred()) }) @@ -102,7 +101,7 @@ var _ = Describe("Resource Actions", func() { var symlinkToArchive string BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "symlink-to-archive") + tempFile, err := os.CreateTemp("", "symlink-to-archive") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).To(Succeed()) symlinkToArchive = tempFile.Name() @@ -136,7 +135,7 @@ var _ = Describe("Resource Actions", func() { When("a .cfignore file exists in the archive", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0655) + err := os.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0655) Expect(err).ToNot(HaveOccurred()) }) @@ -157,9 +156,9 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { for _, filename := range DefaultIgnoreLines { if filename != ".cfignore" { - err := ioutil.WriteFile(filepath.Join(srcDir, filename), nil, 0655) + err := os.WriteFile(filepath.Join(srcDir, filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) + err = os.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) } } @@ -206,7 +205,7 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { tmpDir = srcDir - tmpFile, err := ioutil.TempFile("", "symlink-file-") + tmpFile, err := os.CreateTemp("", "symlink-file-") Expect(err).ToNot(HaveOccurred()) Expect(tmpFile.Close()).To(Succeed()) @@ -236,7 +235,7 @@ var _ = Describe("Resource Actions", func() { When("a .cfignore file exists in the sourceDir", func() { Context("with relative paths", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0655) + err := os.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0655) Expect(err).ToNot(HaveOccurred()) }) @@ -254,7 +253,7 @@ var _ = Describe("Resource Actions", func() { Context("with absolute paths - where '/' == sourceDir", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("/level1/level2"), 0655) + err := os.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("/level1/level2"), 0655) Expect(err).ToNot(HaveOccurred()) }) @@ -275,9 +274,9 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { for _, filename := range DefaultIgnoreLines { if filename != ".cfignore" { - err := ioutil.WriteFile(filepath.Join(srcDir, filename), nil, 0655) + err := os.WriteFile(filepath.Join(srcDir, filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) + err = os.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) } } @@ -300,7 +299,7 @@ var _ = Describe("Resource Actions", func() { When("trace files are in the source directory", func() { BeforeEach(func() { traceFilePath := filepath.Join(srcDir, "i-am-trace.txt") - err := ioutil.WriteFile(traceFilePath, nil, 0655) + err := os.WriteFile(traceFilePath, nil, 0655) Expect(err).ToNot(HaveOccurred()) fakeConfig.VerboseReturns(false, []string{traceFilePath, "/some-other-path"}) @@ -326,7 +325,7 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { var err error - emptyDir, err = ioutil.TempDir("", "v2-resource-actions-empty") + emptyDir, err = os.MkdirTemp("", "v2-resource-actions-empty") Expect(err).ToNot(HaveOccurred()) }) diff --git a/actor/sharedaction/resource_windows_test.go b/actor/sharedaction/resource_windows_test.go index 60087143cdd..b29cf9858ca 100644 --- a/actor/sharedaction/resource_windows_test.go +++ b/actor/sharedaction/resource_windows_test.go @@ -1,7 +1,6 @@ package sharedaction_test import ( - "io/ioutil" "os" "path/filepath" @@ -30,20 +29,20 @@ var _ = Describe("Resource Actions", func() { // tmpfile3 var err error - srcDir, err = ioutil.TempDir("", "v2-resource-actions") + srcDir, err = os.MkdirTemp("", "v2-resource-actions") Expect(err).ToNot(HaveOccurred()) subDir := filepath.Join(srcDir, "level1", "level2") err = os.MkdirAll(subDir, 0777) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0666) + err = os.WriteFile(filepath.Join(subDir, "tmpFile1"), []byte("why hello"), 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0666) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile2"), []byte("Hello, Binky"), 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0666) + err = os.WriteFile(filepath.Join(srcDir, "tmpFile3"), []byte("Bananarama"), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -61,7 +60,7 @@ var _ = Describe("Resource Actions", func() { ) BeforeEach(func() { - tmpfile, err := ioutil.TempFile("", "gather-archive-resource-test") + tmpfile, err := os.CreateTemp("", "gather-archive-resource-test") Expect(err).ToNot(HaveOccurred()) defer tmpfile.Close() archive = tmpfile.Name() @@ -96,7 +95,7 @@ var _ = Describe("Resource Actions", func() { var symlinkToArchive string BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "symlink-to-archive") + tempFile, err := os.CreateTemp("", "symlink-to-archive") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).To(Succeed()) symlinkToArchive = tempFile.Name() @@ -130,7 +129,7 @@ var _ = Describe("Resource Actions", func() { When("a .cfignore file exists in the archive", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0655) + err := os.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0655) Expect(err).ToNot(HaveOccurred()) }) @@ -151,9 +150,9 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { for _, filename := range DefaultIgnoreLines { if filename != ".cfignore" { - err := ioutil.WriteFile(filepath.Join(srcDir, filename), nil, 0655) + err := os.WriteFile(filepath.Join(srcDir, filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) + err = os.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) } } @@ -213,7 +212,7 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { tmpDir = srcDir - tmpFile, err := ioutil.TempFile("", "symlink-file-") + tmpFile, err := os.CreateTemp("", "symlink-file-") Expect(err).ToNot(HaveOccurred()) Expect(tmpFile.Close()).To(Succeed()) @@ -243,7 +242,7 @@ var _ = Describe("Resource Actions", func() { When("a .cfignore file exists in the sourceDir", func() { Context("with relative paths", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0666) + err := os.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("level2"), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -261,7 +260,7 @@ var _ = Describe("Resource Actions", func() { Context("with absolute paths - where '/' == sourceDir", func() { BeforeEach(func() { - err := ioutil.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("/level1/level2"), 0666) + err := os.WriteFile(filepath.Join(srcDir, ".cfignore"), []byte("/level1/level2"), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -282,9 +281,9 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { for _, filename := range DefaultIgnoreLines { if filename != ".cfignore" { - err := ioutil.WriteFile(filepath.Join(srcDir, filename), nil, 0655) + err := os.WriteFile(filepath.Join(srcDir, filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) + err = os.WriteFile(filepath.Join(srcDir, "level1", filename), nil, 0655) Expect(err).ToNot(HaveOccurred()) } } @@ -307,7 +306,7 @@ var _ = Describe("Resource Actions", func() { When("trace files are in the source directory", func() { BeforeEach(func() { traceFilePath := filepath.Join(srcDir, "i-am-trace.txt") - err := ioutil.WriteFile(traceFilePath, nil, 0666) + err := os.WriteFile(traceFilePath, nil, 0666) Expect(err).ToNot(HaveOccurred()) fakeConfig.VerboseReturns(false, []string{traceFilePath, "C:\\some-other-path"}) @@ -333,7 +332,7 @@ var _ = Describe("Resource Actions", func() { BeforeEach(func() { var err error - emptyDir, err = ioutil.TempDir("", "v2-resource-actions-empty") + emptyDir, err = os.MkdirTemp("", "v2-resource-actions-empty") Expect(err).ToNot(HaveOccurred()) }) diff --git a/actor/sharedaction/sharedaction_suite_test.go b/actor/sharedaction/sharedaction_suite_test.go index 785d8f93c53..022001ef6e1 100644 --- a/actor/sharedaction/sharedaction_suite_test.go +++ b/actor/sharedaction/sharedaction_suite_test.go @@ -6,12 +6,11 @@ import ( "os" "path/filepath" "strings" + "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" log "github.com/sirupsen/logrus" - - "testing" ) func TestSharedAction(t *testing.T) { diff --git a/actor/v7action/auth.go b/actor/v7action/auth.go index c69d4836a90..aef734c2c66 100644 --- a/actor/v7action/auth.go +++ b/actor/v7action/auth.go @@ -97,7 +97,11 @@ func (actor Actor) isTokenRevocable(token string) bool { } payload := make(map[string]interface{}) - json.Unmarshal(jsonPayload, &payload) + err = json.Unmarshal(jsonPayload, &payload) + if err != nil { + return false + } + revocable, ok := payload["revocable"].(bool) if !ok { diff --git a/actor/v7action/buildpack_test.go b/actor/v7action/buildpack_test.go index 4ef71fd2376..8af4b5078e2 100644 --- a/actor/v7action/buildpack_test.go +++ b/actor/v7action/buildpack_test.go @@ -3,7 +3,6 @@ package v7action_test import ( "errors" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -512,7 +511,7 @@ var _ = Describe("Buildpack", func() { fakeDownloader = new(v7actionfakes.FakeDownloader) var err error - tmpDirPath, err = ioutil.TempDir("", "buildpackdir-") + tmpDirPath, err = os.MkdirTemp("", "buildpackdir-") Expect(err).ToNot(HaveOccurred()) }) @@ -550,13 +549,13 @@ var _ = Describe("Buildpack", func() { var tempFile *os.File BeforeEach(func() { var err error - inPath, err = ioutil.TempDir("", "buildpackdir-") + inPath, err = os.MkdirTemp("", "buildpackdir-") Expect(err).ToNot(HaveOccurred()) - tempFile, err = ioutil.TempFile(inPath, "foo") + tempFile, err = os.CreateTemp(inPath, "foo") Expect(err).ToNot(HaveOccurred()) - tmpDirPath, err = ioutil.TempDir("", "buildpackdir-") + tmpDirPath, err = os.MkdirTemp("", "buildpackdir-") Expect(err).ToNot(HaveOccurred()) }) @@ -577,10 +576,10 @@ var _ = Describe("Buildpack", func() { When("the buildpack path points to an empty directory", func() { BeforeEach(func() { var err error - inPath, err = ioutil.TempDir("", "some-empty-dir") + inPath, err = os.MkdirTemp("", "some-empty-dir") Expect(err).ToNot(HaveOccurred()) - tmpDirPath, err = ioutil.TempDir("", "buildpackdir-") + tmpDirPath, err = os.MkdirTemp("", "buildpackdir-") Expect(err).ToNot(HaveOccurred()) }) diff --git a/actor/v7action/buildpack_unix_test.go b/actor/v7action/buildpack_unix_test.go index cc7d551d437..96e2bc52f10 100644 --- a/actor/v7action/buildpack_unix_test.go +++ b/actor/v7action/buildpack_unix_test.go @@ -5,7 +5,6 @@ package v7action_test import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -36,14 +35,14 @@ var _ = Describe("Buildpack", func() { BeforeEach(func() { var err error - source, err = ioutil.TempDir("", "zipit-source-") + source, err = os.MkdirTemp("", "zipit-source-") Expect(err).ToNot(HaveOccurred()) - Expect(ioutil.WriteFile(filepath.Join(source, "file1"), []byte{}, 0700)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(source, "file2"), []byte{}, 0644)).To(Succeed()) - subDir, err = ioutil.TempDir(source, "zipit-subdir-") + Expect(os.WriteFile(filepath.Join(source, "file1"), []byte{}, 0700)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(source, "file2"), []byte{}, 0644)).To(Succeed()) + subDir, err = os.MkdirTemp(source, "zipit-subdir-") Expect(err).ToNot(HaveOccurred()) - Expect(ioutil.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0755)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0755)).To(Succeed()) p := filepath.FromSlash(fmt.Sprintf("buildpack-%s.zip", helpers.RandomName())) target, err = filepath.Abs(p) diff --git a/actor/v7action/buildpack_windows_test.go b/actor/v7action/buildpack_windows_test.go index 361142df8b2..7c28ae42803 100644 --- a/actor/v7action/buildpack_windows_test.go +++ b/actor/v7action/buildpack_windows_test.go @@ -5,7 +5,6 @@ package v7action_test import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -36,14 +35,14 @@ var _ = Describe("Buildpack", func() { BeforeEach(func() { var err error - source, err = ioutil.TempDir("", "zipit-source-") + source, err = os.MkdirTemp("", "zipit-source-") Expect(err).ToNot(HaveOccurred()) - ioutil.WriteFile(filepath.Join(source, "file1"), []byte{}, 0666) - ioutil.WriteFile(filepath.Join(source, "file2"), []byte{}, 0666) - subDir, err = ioutil.TempDir(source, "zipit-subdir-") + os.WriteFile(filepath.Join(source, "file1"), []byte{}, 0666) + os.WriteFile(filepath.Join(source, "file2"), []byte{}, 0666) + subDir, err = os.MkdirTemp(source, "zipit-subdir-") Expect(err).ToNot(HaveOccurred()) - ioutil.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0666) + os.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0666) p := filepath.FromSlash(fmt.Sprintf("buildpack-%s.zip", helpers.RandomName())) target, err = filepath.Abs(p) diff --git a/actor/v7action/curl.go b/actor/v7action/curl.go index 7e82c966fe0..dfae0ede22e 100644 --- a/actor/v7action/curl.go +++ b/actor/v7action/curl.go @@ -3,9 +3,9 @@ package v7action import ( "bufio" "fmt" - "io/ioutil" "net/http" "net/textproto" + "os" "strings" "code.cloudfoundry.org/cli/command/translatableerror" @@ -34,7 +34,7 @@ func (actor Actor) MakeCurlRequest( trimmedData := strings.Trim(string(data), `"'`) if strings.HasPrefix(trimmedData, "@") { trimmedData = strings.Trim(trimmedData[1:], `"'`) - requestBodyBytes, err = ioutil.ReadFile(trimmedData) + requestBodyBytes, err = os.ReadFile(trimmedData) if err != nil { return nil, nil, translatableerror.RequestCreationError{Err: err} } diff --git a/actor/v7action/curl_test.go b/actor/v7action/curl_test.go index 4d6f6ffeb48..6380e07d1ed 100644 --- a/actor/v7action/curl_test.go +++ b/actor/v7action/curl_test.go @@ -2,7 +2,6 @@ package v7action_test import ( "errors" - "io/ioutil" "net/http" "os" @@ -123,7 +122,7 @@ var _ = Describe("Curl Actions", func() { var tempFile string BeforeEach(func() { - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) tempFile = file.Name() @@ -156,7 +155,7 @@ var _ = Describe("Curl Actions", func() { var tempFile string BeforeEach(func() { - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) tempFile = file.Name() diff --git a/actor/v7action/package_test.go b/actor/v7action/package_test.go index 170e67f79d5..e4612e3992b 100644 --- a/actor/v7action/package_test.go +++ b/actor/v7action/package_test.go @@ -3,7 +3,6 @@ package v7action_test import ( "errors" "io" - "io/ioutil" "os" "strings" @@ -420,7 +419,7 @@ var _ = Describe("Package Actions", func() { When("bits path is a directory", func() { BeforeEach(func() { var err error - bitsPath, err = ioutil.TempDir("", "example") + bitsPath, err = os.MkdirTemp("", "example") Expect(err).ToNot(HaveOccurred()) }) @@ -642,7 +641,7 @@ var _ = Describe("Package Actions", func() { oldCurrentDir, err = os.Getwd() Expect(err).NotTo(HaveOccurred()) - appDir, err = ioutil.TempDir("", "example") + appDir, err = os.MkdirTemp("", "example") Expect(err).ToNot(HaveOccurred()) Expect(os.Chdir(appDir)).NotTo(HaveOccurred()) @@ -671,12 +670,12 @@ var _ = Describe("Package Actions", func() { When("bits path is an archive", func() { BeforeEach(func() { var err error - tempFile, err := ioutil.TempFile("", "bits-zip-test") + tempFile, err := os.CreateTemp("", "bits-zip-test") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).To(Succeed()) tempFilePath := tempFile.Name() - bitsPathFile, err := ioutil.TempFile("", "example") + bitsPathFile, err := os.CreateTemp("", "example") Expect(err).ToNot(HaveOccurred()) Expect(bitsPathFile.Close()).To(Succeed()) bitsPath = bitsPathFile.Name() @@ -745,10 +744,10 @@ var _ = Describe("Package Actions", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "example") + tempDir, err = os.MkdirTemp("", "example") Expect(err).ToNot(HaveOccurred()) - tempFile, err := ioutil.TempFile("", "example-file-") + tempFile, err := os.CreateTemp("", "example-file-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).To(Succeed()) @@ -774,12 +773,12 @@ var _ = Describe("Package Actions", func() { BeforeEach(func() { var err error - tempArchiveFile, err := ioutil.TempFile("", "bits-zip-test") + tempArchiveFile, err := os.CreateTemp("", "bits-zip-test") Expect(err).ToNot(HaveOccurred()) Expect(tempArchiveFile.Close()).To(Succeed()) tempArchiveFilePath := tempArchiveFile.Name() - archivePathFile, err := ioutil.TempFile("", "example") + archivePathFile, err := os.CreateTemp("", "example") Expect(err).ToNot(HaveOccurred()) Expect(archivePathFile.Close()).To(Succeed()) archivePath = archivePathFile.Name() @@ -788,7 +787,7 @@ var _ = Describe("Package Actions", func() { Expect(err).NotTo(HaveOccurred()) Expect(os.Remove(tempArchiveFilePath)).To(Succeed()) - tempFile, err := ioutil.TempFile("", "example-file-") + tempFile, err := os.CreateTemp("", "example-file-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).To(Succeed()) diff --git a/actor/v7action/security_group.go b/actor/v7action/security_group.go index 04ea216c7fc..fa09b9fa43d 100644 --- a/actor/v7action/security_group.go +++ b/actor/v7action/security_group.go @@ -2,7 +2,7 @@ package v7action import ( "encoding/json" - "io/ioutil" + "io" "os" "code.cloudfoundry.org/cli/actor/actionerror" @@ -389,7 +389,7 @@ func parsePath(path string) ([]byte, error) { return nil, err } - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return nil, err } diff --git a/actor/v7action/security_group_test.go b/actor/v7action/security_group_test.go index 883b99e49e4..f27e20434e6 100644 --- a/actor/v7action/security_group_test.go +++ b/actor/v7action/security_group_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "code.cloudfoundry.org/cli/actor/actionerror" @@ -193,7 +192,7 @@ var _ = Describe("Security Group Actions", func() { }, }, } - tempFile, executeErr = ioutil.TempFile("", "") + tempFile, executeErr = os.CreateTemp("", "") Expect(executeErr).ToNot(HaveOccurred()) filePath = tempFile.Name() @@ -1146,7 +1145,7 @@ var _ = Describe("Security Group Actions", func() { "destination": "10.10.10.0/24" } ]`) - tempFile, executeErr = ioutil.TempFile("", "") + tempFile, executeErr = os.CreateTemp("", "") Expect(executeErr).ToNot(HaveOccurred()) filePath = tempFile.Name() diff --git a/actor/v7action/service_instance.go b/actor/v7action/service_instance.go index b1fa9b68e44..616becf7a6f 100644 --- a/actor/v7action/service_instance.go +++ b/actor/v7action/service_instance.go @@ -270,17 +270,6 @@ func (actor Actor) PurgeServiceInstance(serviceInstanceName, spaceGUID string) ( } } -func (actor Actor) pollJob(jobURL ccv3.JobURL, wait bool) (ccv3.Warnings, error) { - switch { - case jobURL == "": - return ccv3.Warnings{}, nil - case wait: - return actor.CloudControllerClient.PollJob(jobURL) - default: - return actor.CloudControllerClient.PollJobForState(jobURL, constant.JobPolling) - } -} - func (actor Actor) getServiceInstanceByNameAndSpace(serviceInstanceName string, spaceGUID string, query ...ccv3.Query) (resources.ServiceInstance, ccv3.IncludedResources, ccv3.Warnings, error) { serviceInstance, includedResources, warnings, err := actor.CloudControllerClient.GetServiceInstanceByNameAndSpace(serviceInstanceName, spaceGUID, query...) switch e := err.(type) { diff --git a/actor/v7action/task.go b/actor/v7action/task.go index 0c7b2b9bd36..cdebf7d7c7d 100644 --- a/actor/v7action/task.go +++ b/actor/v7action/task.go @@ -1,11 +1,10 @@ package v7action import ( + "sort" "strconv" "time" - "sort" - "code.cloudfoundry.org/cli/actor/actionerror" "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" diff --git a/actor/v7pushaction/handle_app_path_override_test.go b/actor/v7pushaction/handle_app_path_override_test.go index 97b67df8ce4..20f3d8496fb 100644 --- a/actor/v7pushaction/handle_app_path_override_test.go +++ b/actor/v7pushaction/handle_app_path_override_test.go @@ -1,7 +1,6 @@ package v7pushaction_test import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -42,7 +41,7 @@ var _ = Describe("HandleAppPathOverride", func() { var relativeAppFilePath string BeforeEach(func() { - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) relativeAppFilePath = file.Name() defer file.Close() @@ -92,7 +91,7 @@ var _ = Describe("HandleAppPathOverride", func() { var cwd string var absoluteAppFilehandle *os.File BeforeEach(func() { - absoluteAppFilehandle, err = ioutil.TempFile("", "") + absoluteAppFilehandle, err = os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) defer absoluteAppFilehandle.Close() if runtime.GOOS == "windows" { diff --git a/actor/v7pushaction/setup_all_resources_for_push_plan_test.go b/actor/v7pushaction/setup_all_resources_for_push_plan_test.go index 6ad8efaf5cf..cb991961c19 100644 --- a/actor/v7pushaction/setup_all_resources_for_push_plan_test.go +++ b/actor/v7pushaction/setup_all_resources_for_push_plan_test.go @@ -2,7 +2,6 @@ package v7pushaction_test import ( "errors" - "io/ioutil" "os" "code.cloudfoundry.org/cli/actor/sharedaction" @@ -126,7 +125,7 @@ var _ = Describe("SetupAllResourcesForPushPlan", func() { var archivePath string BeforeEach(func() { - archive, err := ioutil.TempFile("", "push-plan-archive") + archive, err := os.CreateTemp("", "push-plan-archive") Expect(err).ToNot(HaveOccurred()) defer archive.Close() diff --git a/actor/v7pushaction/v7pushaction_suite_test.go b/actor/v7pushaction/v7pushaction_suite_test.go index 9d503fc13d7..2a68dddff26 100644 --- a/actor/v7pushaction/v7pushaction_suite_test.go +++ b/actor/v7pushaction/v7pushaction_suite_test.go @@ -2,9 +2,8 @@ package v7pushaction_test import ( "os" - "time" - "testing" + "time" . "code.cloudfoundry.org/cli/actor/v7pushaction" "code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes" diff --git a/api/cloudcontroller/ccv3/buildpack_test.go b/api/cloudcontroller/ccv3/buildpack_test.go index 11ffa9645f0..735a99fb0f3 100644 --- a/api/cloudcontroller/ccv3/buildpack_test.go +++ b/api/cloudcontroller/ccv3/buildpack_test.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "mime/multipart" "net/http" "strings" @@ -376,7 +375,7 @@ var _ = Describe("Buildpacks", func() { Expect(buildpackPart.FileName()).To(Equal("fake-buildpack.zip")) defer buildpackPart.Close() - partContents, err := ioutil.ReadAll(buildpackPart) + partContents, err := io.ReadAll(buildpackPart) Expect(err).ToNot(HaveOccurred()) Expect(string(partContents)).To(Equal(bpContent)) } @@ -461,7 +460,7 @@ var _ = Describe("Buildpacks", func() { defer GinkgoRecover() // Since this will be running in a thread if strings.HasSuffix(request.URL.String(), "/v3/buildpacks/some-buildpack-guid/upload") { - _, err := ioutil.ReadAll(request.Body) + _, err := io.ReadAll(request.Body) Expect(err).ToNot(HaveOccurred()) Expect(request.Body.Close()).ToNot(HaveOccurred()) return request.ResetBody() @@ -490,7 +489,7 @@ var _ = Describe("Buildpacks", func() { if strings.HasSuffix(request.URL.String(), "/v3/buildpacks/some-buildpack-guid/upload") { defer request.Body.Close() - readBytes, err := ioutil.ReadAll(request.Body) + readBytes, err := io.ReadAll(request.Body) Expect(err).ToNot(HaveOccurred()) Expect(len(readBytes)).To(BeNumerically(">", len(bpContent))) return expectedErr diff --git a/api/cloudcontroller/ccv3/client.go b/api/cloudcontroller/ccv3/client.go index 5a998f35154..ffb7ef5d933 100644 --- a/api/cloudcontroller/ccv3/client.go +++ b/api/cloudcontroller/ccv3/client.go @@ -9,7 +9,7 @@ // For more information on the Cloud Controller API see // https://apidocs.cloudfoundry.org/ // -// Method Naming Conventions +// # Method Naming Conventions // // The client takes a '' // approach to method names. If the and @@ -21,48 +21,50 @@ // word "Action" in the method name. // // For Example: -// Method Name: GetApplication -// Endpoint: /v3/applications/:guid -// Action Name: Get -// Top Level Endpoint: applications -// Return Value: Application -// -// Method Name: GetServiceInstances -// Endpoint: /v3/service_instances -// Action Name: Get -// Top Level Endpoint: service_instances -// Return Value: []ServiceInstance -// -// Method Name: GetSpaceServiceInstances -// Endpoint: /v3/spaces/:guid/service_instances -// Action Name: Get -// Top Level Endpoint: spaces -// Return Value: []ServiceInstance -// -// Method Name: CreateApplicationTask -// Endpoint: /v3/apps/:application_guid/task -// Action Name: Post -// Top Level Endpoint: apps -// Return Value: Task +// +// Method Name: GetApplication +// Endpoint: /v3/applications/:guid +// Action Name: Get +// Top Level Endpoint: applications +// Return Value: Application +// +// Method Name: GetServiceInstances +// Endpoint: /v3/service_instances +// Action Name: Get +// Top Level Endpoint: service_instances +// Return Value: []ServiceInstance +// +// Method Name: GetSpaceServiceInstances +// Endpoint: /v3/spaces/:guid/service_instances +// Action Name: Get +// Top Level Endpoint: spaces +// Return Value: []ServiceInstance +// +// Method Name: CreateApplicationTask +// Endpoint: /v3/apps/:application_guid/task +// Action Name: Post +// Top Level Endpoint: apps +// Return Value: Task // // Use the following table to determine which HTTP Command equates to which // Action Name: -// HTTP Command -> Action Name -// POST -> Create OR Update* -// GET -> Get -// PUT -> Update -// DELETE -> Delete -// PATCH -> Update +// +// HTTP Command -> Action Name +// POST -> Create OR Update* +// GET -> Get +// PUT -> Update +// DELETE -> Delete +// PATCH -> Update // // * - In some cases POSTs are updating resources, in these cases the method // should be called Update, not Create. // -// Method Locations +// # Method Locations // // Methods exist in the same file as their return type, regardless of which // endpoint they use. // -// Error Handling +// # Error Handling // // All error handling that requires parsing the error_code/code returned back // from the Cloud Controller should be placed in the errorWrapper. Everything diff --git a/api/cloudcontroller/ccv3/constant/godoc.go b/api/cloudcontroller/ccv3/constant/godoc.go index f45e50016f7..089f7458ea2 100644 --- a/api/cloudcontroller/ccv3/constant/godoc.go +++ b/api/cloudcontroller/ccv3/constant/godoc.go @@ -6,13 +6,14 @@ // exception is 'state' types, where the word 'state' is omitted. // // For Example: -// Constant Type: PackageType -// Enum Name: Bits -// Enum Value: "bits" -// const PackageTypeBits PackageType = "bits" // -// Constant Type: PackageState -// Enum Name: Expired -// Enum Value: "EXPIRED" -// const PackageExpired PackageState = "EXPIRED" +// Constant Type: PackageType +// Enum Name: Bits +// Enum Value: "bits" +// const PackageTypeBits PackageType = "bits" +// +// Constant Type: PackageState +// Enum Name: Expired +// Enum Value: "EXPIRED" +// const PackageExpired PackageState = "EXPIRED" package constant diff --git a/api/cloudcontroller/ccv3/droplet_test.go b/api/cloudcontroller/ccv3/droplet_test.go index 6a693d6d3fd..2e8f9eed293 100644 --- a/api/cloudcontroller/ccv3/droplet_test.go +++ b/api/cloudcontroller/ccv3/droplet_test.go @@ -3,7 +3,6 @@ package ccv3_test import ( "errors" "io" - "io/ioutil" "mime/multipart" "net/http" "strings" @@ -263,7 +262,7 @@ var _ = Describe("Droplet", func() { Expect(dropletPart.FileName()).To(Equal("fake-droplet.tgz")) defer dropletPart.Close() - partContents, err := ioutil.ReadAll(dropletPart) + partContents, err := io.ReadAll(dropletPart) Expect(err).ToNot(HaveOccurred()) Expect(string(partContents)).To(Equal(dropletContent)) } @@ -375,7 +374,7 @@ var _ = Describe("Droplet", func() { defer GinkgoRecover() // Since this will be running in a thread if strings.HasSuffix(request.URL.String(), "/v3/droplets/some-droplet-guid/upload") { - _, err := ioutil.ReadAll(request.Body) + _, err := io.ReadAll(request.Body) Expect(err).ToNot(HaveOccurred()) Expect(request.Body.Close()).ToNot(HaveOccurred()) return request.ResetBody() @@ -404,7 +403,7 @@ var _ = Describe("Droplet", func() { if strings.HasSuffix(request.URL.String(), "/v3/droplets/some-droplet-guid/upload") { defer request.Body.Close() - readBytes, err := ioutil.ReadAll(request.Body) + readBytes, err := io.ReadAll(request.Body) Expect(err).ToNot(HaveOccurred()) Expect(len(readBytes)).To(BeNumerically(">", len(dropletContent))) return expectedErr diff --git a/api/cloudcontroller/ccv3/errors_test.go b/api/cloudcontroller/ccv3/errors_test.go index 0fe7c021b4a..a5c92c32180 100644 --- a/api/cloudcontroller/ccv3/errors_test.go +++ b/api/cloudcontroller/ccv3/errors_test.go @@ -526,7 +526,7 @@ var _ = Describe("Error Wrapper", func() { Message: "A service instance called foo has already been shared with foo-space.", })) }) - }) + }) When("the buildpack is invalid", func() { BeforeEach(func() { diff --git a/api/cloudcontroller/ccv3/info.go b/api/cloudcontroller/ccv3/info.go index 8a2e694a18c..564834a8ed1 100644 --- a/api/cloudcontroller/ccv3/info.go +++ b/api/cloudcontroller/ccv3/info.go @@ -95,11 +95,6 @@ func (info Info) Login() string { return info.Links.Login.HREF } -// ccv3Link returns the HREF of the CloudController v3 API. -func (info Info) ccV3Link() string { - return info.Links.CCV3.HREF -} - // ResourceLinks represents the information returned back from /v3. type ResourceLinks map[string]resources.APILink diff --git a/api/cloudcontroller/ccv3/internal/routing.go b/api/cloudcontroller/ccv3/internal/routing.go index b6589de43ba..d25e810c222 100644 --- a/api/cloudcontroller/ccv3/internal/routing.go +++ b/api/cloudcontroller/ccv3/internal/routing.go @@ -11,18 +11,22 @@ import ( // Params map path keys to values. For example, if your route has the path // pattern: -// /person/:person_id/pets/:pet_type +// +// /person/:person_id/pets/:pet_type +// // Then a correct Params map would look like: -// router.Params{ -// "person_id": "123", -// "pet_type": "cats", -// } +// +// router.Params{ +// "person_id": "123", +// "pet_type": "cats", +// } type Params map[string]string // Route defines the property of a Cloud Controller V3 endpoint. // // Method can be one of the following: -// GET HEAD POST PUT PATCH DELETE CONNECT OPTIONS TRACE +// +// GET HEAD POST PUT PATCH DELETE CONNECT OPTIONS TRACE // // Path conforms to Pat-style pattern matching. The following docs are taken // from http://godoc.org/github.com/bmizerany/pat#PatternServeMux @@ -35,26 +39,36 @@ type Params map[string]string // string. // // Example pattern with one capture: -// /hello/:name +// +// /hello/:name +// // Will match: -// /hello/blake -// /hello/keith +// +// /hello/blake +// /hello/keith +// // Will not match: -// /hello/blake/ -// /hello/blake/foo -// /foo -// /foo/bar +// +// /hello/blake/ +// /hello/blake/foo +// /foo +// /foo/bar // // Example 2: -// /hello/:name/ +// +// /hello/:name/ +// // Will match: -// /hello/blake/ -// /hello/keith/foo -// /hello/blake -// /hello/keith +// +// /hello/blake/ +// /hello/keith/foo +// /hello/blake +// /hello/keith +// // Will not match: -// /foo -// /foo/bar +// +// /foo +// /foo/bar type Route struct { // Method is any valid HTTP method Method string diff --git a/api/cloudcontroller/ccv3/organization_test.go b/api/cloudcontroller/ccv3/organization_test.go index 14f8148cb7e..1b7800dffce 100644 --- a/api/cloudcontroller/ccv3/organization_test.go +++ b/api/cloudcontroller/ccv3/organization_test.go @@ -449,7 +449,7 @@ var _ = Describe("Organizations", func() { }` expectedBody := map[string]interface{}{ - "name": "some-org-name", + "name": "some-org-name", "suspended": false, } @@ -485,7 +485,7 @@ var _ = Describe("Organizations", func() { }` expectedBody := map[string]interface{}{ - "name": "some-org-name", + "name": "some-org-name", "suspended": false, } @@ -526,7 +526,7 @@ var _ = Describe("Organizations", func() { }` expectedBody := map[string]interface{}{ - "name": "some-org-name", + "name": "some-org-name", "suspended": false, } @@ -586,7 +586,7 @@ var _ = Describe("Organizations", func() { }` expectedBody := map[string]interface{}{ - "name": "some-org-name", + "name": "some-org-name", "suspended": false, "metadata": map[string]interface{}{ "labels": map[string]string{ diff --git a/api/cloudcontroller/ccv3/package_test.go b/api/cloudcontroller/ccv3/package_test.go index 2ef64f230c0..5cc627d2903 100644 --- a/api/cloudcontroller/ccv3/package_test.go +++ b/api/cloudcontroller/ccv3/package_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "mime/multipart" "net/http" "os" @@ -498,7 +497,7 @@ var _ = Describe("Package", func() { defer resourcesPart.Close() expectedJSON, err := json.Marshal(inputResources) Expect(err).NotTo(HaveOccurred()) - Expect(ioutil.ReadAll(resourcesPart)).To(MatchJSON(expectedJSON)) + Expect(io.ReadAll(resourcesPart)).To(MatchJSON(expectedJSON)) // Verify that the application bits are sent properly resourcesPart, err = requestReader.NextPart() @@ -508,7 +507,7 @@ var _ = Describe("Package", func() { Expect(resourcesPart.FileName()).To(Equal("package.zip")) defer resourcesPart.Close() - Expect(ioutil.ReadAll(resourcesPart)).To(Equal(readerBody)) + Expect(io.ReadAll(resourcesPart)).To(Equal(readerBody)) } }) @@ -542,7 +541,7 @@ var _ = Describe("Package", func() { defer resourcesPart.Close() expectedJSON, err := json.Marshal(inputResources) Expect(err).NotTo(HaveOccurred()) - Expect(ioutil.ReadAll(resourcesPart)).To(MatchJSON(expectedJSON)) + Expect(io.ReadAll(resourcesPart)).To(MatchJSON(expectedJSON)) // Verify that the application bits are not sent _, err = requestReader.NextPart() @@ -626,7 +625,7 @@ var _ = Describe("Package", func() { defer GinkgoRecover() // Since this will be running in a thread if strings.HasSuffix(request.URL.String(), "/v3/packages/package-guid/upload") { - _, err := ioutil.ReadAll(request.Body) + _, err := io.ReadAll(request.Body) Expect(err).ToNot(HaveOccurred()) Expect(request.Body.Close()).ToNot(HaveOccurred()) return request.ResetBody() @@ -657,7 +656,7 @@ var _ = Describe("Package", func() { if strings.HasSuffix(request.URL.String(), "/v3/packages/package-guid/upload") { defer request.Body.Close() - readBytes, err := ioutil.ReadAll(request.Body) + readBytes, err := io.ReadAll(request.Body) Expect(err).ToNot(HaveOccurred()) Expect(len(readBytes)).To(BeNumerically(">", UploadSize)) return expectedErr @@ -701,7 +700,7 @@ var _ = Describe("Package", func() { GUID: "package-guid", } - tempFile, err = ioutil.TempFile("", "package-upload") + tempFile, err = os.CreateTemp("", "package-upload") Expect(err).ToNot(HaveOccurred()) defer tempFile.Close() @@ -709,7 +708,7 @@ var _ = Describe("Package", func() { fileSize := 1024 contents := strings.Repeat("A", fileSize) - err = ioutil.WriteFile(tempFile.Name(), []byte(contents), 0666) + err = os.WriteFile(tempFile.Name(), []byte(contents), 0666) Expect(err).NotTo(HaveOccurred()) verifyHeaderAndBody := func(_ http.ResponseWriter, req *http.Request) { @@ -719,7 +718,7 @@ var _ = Describe("Package", func() { boundary := contentType[30:] defer req.Body.Close() - rawBody, err := ioutil.ReadAll(req.Body) + rawBody, err := io.ReadAll(req.Body) Expect(err).NotTo(HaveOccurred()) body := BufferWithBytes(rawBody) Expect(body).To(Say("--%s", boundary)) @@ -780,7 +779,7 @@ var _ = Describe("Package", func() { State: constant.PackageAwaitingUpload, } - tempFile, err = ioutil.TempFile("", "package-upload") + tempFile, err = os.CreateTemp("", "package-upload") Expect(err).ToNot(HaveOccurred()) defer tempFile.Close() @@ -788,7 +787,7 @@ var _ = Describe("Package", func() { fileSize := 1024 contents := strings.Repeat("A", fileSize) - err = ioutil.WriteFile(tempFile.Name(), []byte(contents), 0666) + err = os.WriteFile(tempFile.Name(), []byte(contents), 0666) Expect(err).NotTo(HaveOccurred()) response := ` { diff --git a/api/cloudcontroller/ccv3/route_binding_test.go b/api/cloudcontroller/ccv3/route_binding_test.go index 3b564c9fc07..6321d4faad2 100644 --- a/api/cloudcontroller/ccv3/route_binding_test.go +++ b/api/cloudcontroller/ccv3/route_binding_test.go @@ -193,7 +193,8 @@ var _ = Describe("RouteBinding", func() { ) It("makes the right request", func() { - client.DeleteRouteBinding(guid) + _, _, err := client.DeleteRouteBinding(guid) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) Expect(requester.MakeRequestArgsForCall(0)).To(Equal(RequestParams{ diff --git a/api/cloudcontroller/ccv3/service_credential_binding_test.go b/api/cloudcontroller/ccv3/service_credential_binding_test.go index 5f3e2fe2136..f78261ad690 100644 --- a/api/cloudcontroller/ccv3/service_credential_binding_test.go +++ b/api/cloudcontroller/ccv3/service_credential_binding_test.go @@ -209,7 +209,8 @@ var _ = Describe("Service Credential Bindings", func() { ) It("makes the right request", func() { - client.DeleteServiceCredentialBinding(guid) + _, _, err := client.DeleteServiceCredentialBinding(guid) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) Expect(requester.MakeRequestArgsForCall(0)).To(Equal(RequestParams{ @@ -258,7 +259,7 @@ var _ = Describe("Service Credential Bindings", func() { BeforeEach(func() { requester.MakeRequestCalls(func(params RequestParams) (JobURL, Warnings, error) { - json.Unmarshal([]byte(`{"credentials":{"foo":"bar"}}`), params.ResponseBody) + Expect(json.Unmarshal([]byte(`{"credentials":{"foo":"bar"}}`), params.ResponseBody)).To(Succeed()) return "", Warnings{"warning-1", "warning-2"}, nil }) }) diff --git a/api/cloudcontroller/ccv3/service_instance_test.go b/api/cloudcontroller/ccv3/service_instance_test.go index 0f61658f69c..f4ee3c427cd 100644 --- a/api/cloudcontroller/ccv3/service_instance_test.go +++ b/api/cloudcontroller/ccv3/service_instance_test.go @@ -285,13 +285,14 @@ var _ = Describe("Service Instance", func() { BeforeEach(func() { requester.MakeRequestCalls(func(params RequestParams) (JobURL, Warnings, error) { - json.Unmarshal([]byte(`{"foo":"bar"}`), params.ResponseBody) + Expect(json.Unmarshal([]byte(`{"foo":"bar"}`), params.ResponseBody)).To(Succeed()) return "", Warnings{"one", "two"}, nil }) }) It("makes the correct API request", func() { - client.GetServiceInstanceParameters(guid) + _, _, err := client.GetServiceInstanceParameters(guid) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) actualRequest := requester.MakeRequestArgsForCall(0) @@ -479,7 +480,8 @@ var _ = Describe("Service Instance", func() { ) It("makes the right request", func() { - client.DeleteServiceInstance(guid) + _, _, err := client.DeleteServiceInstance(guid) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) Expect(requester.MakeRequestArgsForCall(0)).To(Equal(RequestParams{ @@ -490,7 +492,8 @@ var _ = Describe("Service Instance", func() { When("there are query parameters", func() { It("passes them through", func() { - client.DeleteServiceInstance(guid, Query{Key: NameFilter, Values: []string{"foo"}}) + _, _, err := client.DeleteServiceInstance(guid, Query{Key: NameFilter, Values: []string{"foo"}}) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) Expect(requester.MakeRequestArgsForCall(0).Query).To(ConsistOf(Query{Key: NameFilter, Values: []string{"foo"}})) @@ -539,7 +542,8 @@ var _ = Describe("Service Instance", func() { }) It("makes the right request", func() { - client.ShareServiceInstanceToSpaces(serviceInstanceGUID, spaceGUIDs) + _, _, err := client.ShareServiceInstanceToSpaces(serviceInstanceGUID, spaceGUIDs) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) @@ -554,7 +558,7 @@ var _ = Describe("Service Instance", func() { When("the request succeeds", func() { BeforeEach(func() { requester.MakeRequestCalls(func(params RequestParams) (JobURL, Warnings, error) { - json.Unmarshal([]byte(`{"data":[{"guid":"some-space-guid"}, {"guid":"some-other-space-guid"}]}`), params.ResponseBody) + Expect(json.Unmarshal([]byte(`{"data":[{"guid":"some-space-guid"}, {"guid":"some-other-space-guid"}]}`), params.ResponseBody)).To(Succeed()) return "", Warnings{"fake-warning"}, nil }) }) @@ -594,7 +598,8 @@ var _ = Describe("Service Instance", func() { }) It("makes the right request", func() { - client.UnshareServiceInstanceFromSpace(serviceInstanceGUID, spaceGUID) + _, err := client.UnshareServiceInstanceFromSpace(serviceInstanceGUID, spaceGUID) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) Expect(requester.MakeRequestArgsForCall(0)).To(Equal(RequestParams{ @@ -642,7 +647,8 @@ var _ = Describe("Service Instance", func() { }) It("makes the right request", func() { - client.GetServiceInstanceSharedSpaces(serviceInstanceGUID) + _, _, err := client.GetServiceInstanceSharedSpaces(serviceInstanceGUID) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) @@ -664,7 +670,7 @@ var _ = Describe("Service Instance", func() { When("the request succeeds", func() { BeforeEach(func() { requester.MakeRequestCalls(func(params RequestParams) (JobURL, Warnings, error) { - jsonry.Unmarshal([]byte(`{ + Expect(jsonry.Unmarshal([]byte(`{ "data": [{"guid":"some-space-guid"},{"guid":"some-other-space-guid"}], "links": { "self": { @@ -703,7 +709,7 @@ var _ = Describe("Service Instance", func() { } ] } - }`), params.ResponseBody) + }`), params.ResponseBody)).To(Succeed()) return "", Warnings{"fake-warning"}, nil }) }) @@ -754,7 +760,8 @@ var _ = Describe("Service Instance", func() { }) It("makes the right request", func() { - client.GetServiceInstanceUsageSummary(serviceInstanceGUID) + _, _, err := client.GetServiceInstanceUsageSummary(serviceInstanceGUID) + Expect(err).NotTo(HaveOccurred()) Expect(requester.MakeRequestCallCount()).To(Equal(1)) @@ -766,7 +773,7 @@ var _ = Describe("Service Instance", func() { When("the request succeeds", func() { BeforeEach(func() { requester.MakeRequestCalls(func(params RequestParams) (JobURL, Warnings, error) { - jsonry.Unmarshal([]byte(`{ + Expect(jsonry.Unmarshal([]byte(`{ "usage_summary": [ { "space": { @@ -792,7 +799,7 @@ var _ = Describe("Service Instance", func() { "href": "https://api.example.org/v3/service_instances/some_instance_guid" } } - }`), params.ResponseBody) + }`), params.ResponseBody)).To(Succeed()) return "", Warnings{"fake-warning"}, nil }) }) diff --git a/api/cloudcontroller/cloud_controller_connection.go b/api/cloudcontroller/cloud_controller_connection.go index 7eb9c8d8b34..b5601a86ccd 100644 --- a/api/cloudcontroller/cloud_controller_connection.go +++ b/api/cloudcontroller/cloud_controller_connection.go @@ -2,14 +2,14 @@ package cloudcontroller import ( "crypto/x509" - "io/ioutil" + "errors" + "io" "net" "net/http" "net/url" "strings" "time" - "errors" "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" "code.cloudfoundry.org/cli/util" ) @@ -64,7 +64,7 @@ func (*CloudControllerConnection) handleStatusCodes(response *http.Response, pas if response.StatusCode == http.StatusNoContent { passedResponse.RawResponse = []byte("{}") } else { - rawBytes, err := ioutil.ReadAll(response.Body) + rawBytes, err := io.ReadAll(response.Body) if err != nil { return err } @@ -141,7 +141,7 @@ func (*CloudControllerConnection) processRequestErrors(request *http.Request, er } hostnameError := x509.HostnameError{} - if errors.As(err, &hostnameError) { + if errors.As(err, &hostnameError) { return ccerror.SSLValidationHostnameError{ Message: hostnameError.Error(), } diff --git a/api/cloudcontroller/cloudcontroller_suite_test.go b/api/cloudcontroller/cloudcontroller_suite_test.go index ce6355befaa..d8ad80d299b 100644 --- a/api/cloudcontroller/cloudcontroller_suite_test.go +++ b/api/cloudcontroller/cloudcontroller_suite_test.go @@ -3,12 +3,11 @@ package cloudcontroller_test import ( "bytes" "log" + "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" - - "testing" ) func TestCloudcontroller(t *testing.T) { diff --git a/api/cloudcontroller/wrapper/kubernetes_authentication_test.go b/api/cloudcontroller/wrapper/kubernetes_authentication_test.go index 1819146a7c8..0440fef84fd 100644 --- a/api/cloudcontroller/wrapper/kubernetes_authentication_test.go +++ b/api/cloudcontroller/wrapper/kubernetes_authentication_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "encoding/pem" "errors" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -136,7 +136,7 @@ var _ = Describe("KubernetesAuthentication", func() { actualReq, actualResp := wrappedConnection.MakeArgsForCall(0) Expect(actualResp.HTTPResponse).To(HaveHTTPStatus(http.StatusTeapot)) - body, err := ioutil.ReadAll(actualReq.Body) + body, err := io.ReadAll(actualReq.Body) Expect(err).NotTo(HaveOccurred()) Expect(string(body)).To(Equal("hello")) @@ -339,7 +339,7 @@ var _ = Describe("KubernetesAuthentication", func() { }) It("uses the exec command to generate the Bearer token", func() { - helpers.SkipIfWindows() + helpers.SkipIfWindows() Expect(makeErr).NotTo(HaveOccurred()) Expect(wrappedConnection.MakeCallCount()).To(Equal(1)) @@ -393,7 +393,7 @@ var _ = Describe("KubernetesAuthentication", func() { var tokenFilePath string BeforeEach(func() { - tokenFile, err := ioutil.TempFile("", "") + tokenFile, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) defer tokenFile.Close() _, err = tokenFile.Write(token) @@ -443,9 +443,9 @@ func base64Decode(encoded string) string { } func writeToFile(base64Data string) string { - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) - file.WriteString(base64Decode(base64Data)) + Expect(file.WriteString(base64Decode(base64Data))).To(Succeed()) Expect(file.Close()).To(Succeed()) return file.Name() } diff --git a/api/cloudcontroller/wrapper/request_logger.go b/api/cloudcontroller/wrapper/request_logger.go index e354cad2080..abebb85108c 100644 --- a/api/cloudcontroller/wrapper/request_logger.go +++ b/api/cloudcontroller/wrapper/request_logger.go @@ -2,7 +2,7 @@ package wrapper import ( "fmt" - "io/ioutil" + "io" "net/http" "sort" "strings" @@ -93,7 +93,7 @@ func (logger *RequestLogger) displayRequest(request *cloudcontroller.Request) er contentType := request.Header.Get("Content-Type") if request.Body != nil { if strings.Contains(contentType, "json") { - rawRequestBody, err := ioutil.ReadAll(request.Body) + rawRequestBody, err := io.ReadAll(request.Body) if err != nil { return err } @@ -102,7 +102,7 @@ func (logger *RequestLogger) displayRequest(request *cloudcontroller.Request) er return logger.output.DisplayJSONBody(rawRequestBody) } else if strings.Contains(contentType, "x-www-form-urlencoded") { - rawRequestBody, err := ioutil.ReadAll(request.Body) + rawRequestBody, err := io.ReadAll(request.Body) if err != nil { return err } diff --git a/api/cloudcontroller/wrapper/request_logger_test.go b/api/cloudcontroller/wrapper/request_logger_test.go index 93d64c7bd34..f105321c9a9 100644 --- a/api/cloudcontroller/wrapper/request_logger_test.go +++ b/api/cloudcontroller/wrapper/request_logger_test.go @@ -3,7 +3,7 @@ package wrapper_test import ( "bytes" "errors" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -135,7 +135,7 @@ var _ = Describe("Request Logger", func() { Expect(fakeOutput.DisplayJSONBodyCallCount()).To(BeNumerically(">=", 1)) Expect(fakeOutput.DisplayJSONBodyArgsForCall(0)).To(Equal([]byte("foo"))) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte("foo"))) }) @@ -149,7 +149,7 @@ var _ = Describe("Request Logger", func() { It("outputs the body", func() { Expect(makeErr).NotTo(HaveOccurred()) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte("foo"))) Expect(fakeOutput.DisplayMessageCallCount()).To(Equal(1)) diff --git a/api/cloudcontroller/wrapper/retry_request_test.go b/api/cloudcontroller/wrapper/retry_request_test.go index 69e0a56d4e2..118d285ae2a 100644 --- a/api/cloudcontroller/wrapper/retry_request_test.go +++ b/api/cloudcontroller/wrapper/retry_request_test.go @@ -2,7 +2,7 @@ package wrapper_test import ( "errors" - "io/ioutil" + "io" "net/http" "strings" @@ -37,7 +37,7 @@ var _ = Describe("Retry Request", func() { } fakeConnection.MakeStub = func(req *cloudcontroller.Request, passedResponse *cloudcontroller.Response) error { defer req.Body.Close() - body, readErr := ioutil.ReadAll(request.Body) + body, readErr := io.ReadAll(request.Body) Expect(readErr).ToNot(HaveOccurred()) Expect(string(body)).To(Equal(rawRequestBody)) return expectedErr diff --git a/api/cloudcontroller/wrapper/uaa_authentication_test.go b/api/cloudcontroller/wrapper/uaa_authentication_test.go index 09d3980f9f6..6302c91d3c9 100644 --- a/api/cloudcontroller/wrapper/uaa_authentication_test.go +++ b/api/cloudcontroller/wrapper/uaa_authentication_test.go @@ -2,7 +2,7 @@ package wrapper_test import ( "errors" - "io/ioutil" + "io" "net/http" "strings" "time" @@ -181,7 +181,7 @@ var _ = Describe("UAA Authentication", func() { body := strings.NewReader(expectedBody) request = cloudcontroller.NewRequest(&http.Request{ Header: http.Header{}, - Body: ioutil.NopCloser(body), + Body: io.NopCloser(body), }, body) inMemoryCache.SetAccessToken(invalidAccessToken) diff --git a/api/plugin/download_plugin.go b/api/plugin/download_plugin.go index c08e3ea344d..e6cf51da50c 100644 --- a/api/plugin/download_plugin.go +++ b/api/plugin/download_plugin.go @@ -1,6 +1,6 @@ package plugin -import "io/ioutil" +import "os" func (client *Client) DownloadPlugin(pluginURL string, path string, proxyReader ProxyReader) error { request, err := client.newGETRequest(pluginURL) @@ -14,7 +14,7 @@ func (client *Client) DownloadPlugin(pluginURL string, path string, proxyReader return err } - err = ioutil.WriteFile(path, response.RawResponse, 0700) + err = os.WriteFile(path, response.RawResponse, 0700) if err != nil { return err } diff --git a/api/plugin/download_plugin_test.go b/api/plugin/download_plugin_test.go index be153b71561..5261eba3b6d 100644 --- a/api/plugin/download_plugin_test.go +++ b/api/plugin/download_plugin_test.go @@ -2,7 +2,6 @@ package plugin_test import ( "io" - "io/ioutil" "net/http" "net/url" "os" @@ -24,7 +23,7 @@ var _ = Describe("DownloadPlugin", func() { BeforeEach(func() { client = NewTestClient() - tempFile, err := ioutil.TempFile("", "") + tempFile, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) tempPath = tempFile.Name() @@ -56,12 +55,12 @@ var _ = Describe("DownloadPlugin", func() { fakeProxyReader := new(pluginfakes.FakeProxyReader) fakeProxyReader.WrapStub = func(reader io.Reader) io.ReadCloser { - return ioutil.NopCloser(reader) + return io.NopCloser(reader) } err := client.DownloadPlugin(server.URL(), tempPath, fakeProxyReader) Expect(err).ToNot(HaveOccurred()) - fileData, err := ioutil.ReadFile(tempPath) + fileData, err := os.ReadFile(tempPath) Expect(err).ToNot(HaveOccurred()) Expect(fileData).To(Equal(data)) diff --git a/api/plugin/plugin_connection.go b/api/plugin/plugin_connection.go index 38cfe49e817..465be1bacd3 100644 --- a/api/plugin/plugin_connection.go +++ b/api/plugin/plugin_connection.go @@ -4,13 +4,12 @@ import ( "bytes" "crypto/x509" "encoding/json" + "errors" "io" - "io/ioutil" "net" "net/http" "net/url" "time" - "errors" "code.cloudfoundry.org/cli/api/plugin/pluginerror" "code.cloudfoundry.org/cli/util" @@ -74,7 +73,7 @@ func (*PluginConnection) handleStatusCodes(response *http.Response, passedRespon func (connection *PluginConnection) populateResponse(response *http.Response, passedResponse *Response, body io.ReadCloser) error { passedResponse.HTTPResponse = response - rawBytes, err := ioutil.ReadAll(body) + rawBytes, err := io.ReadAll(body) defer body.Close() if err != nil { return err diff --git a/api/plugin/plugin_connection_test.go b/api/plugin/plugin_connection_test.go index f1bf9af3482..ac1a8b36f56 100644 --- a/api/plugin/plugin_connection_test.go +++ b/api/plugin/plugin_connection_test.go @@ -3,7 +3,6 @@ package plugin_test import ( "fmt" "io" - "io/ioutil" "net/http" "runtime" "strings" @@ -33,7 +32,7 @@ var _ = Describe("Plugin Connection", func() { fakeProxyReader = new(pluginfakes.FakeProxyReader) fakeProxyReader.WrapStub = func(reader io.Reader) io.ReadCloser { - return ioutil.NopCloser(reader) + return io.NopCloser(reader) } }) diff --git a/api/plugin/plugin_suite_test.go b/api/plugin/plugin_suite_test.go index e188e117a93..fb573421058 100644 --- a/api/plugin/plugin_suite_test.go +++ b/api/plugin/plugin_suite_test.go @@ -3,13 +3,12 @@ package plugin_test import ( "bytes" "log" + "testing" . "code.cloudfoundry.org/cli/api/plugin" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" - - "testing" ) func TestPlugin(t *testing.T) { diff --git a/api/plugin/wrapper/request_logger.go b/api/plugin/wrapper/request_logger.go index c878d36e4b9..8903969fd09 100644 --- a/api/plugin/wrapper/request_logger.go +++ b/api/plugin/wrapper/request_logger.go @@ -2,7 +2,7 @@ package wrapper import ( "bytes" - "io/ioutil" + "io" "net/http" "sort" "time" @@ -90,13 +90,13 @@ func (logger *RequestLogger) displayRequest(request *http.Request) error { } if request.Body != nil && request.Header.Get("Content-Type") == "application/json" { - rawRequestBody, err := ioutil.ReadAll(request.Body) + rawRequestBody, err := io.ReadAll(request.Body) defer request.Body.Close() if err != nil { return err } - request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody)) + request.Body = io.NopCloser(bytes.NewBuffer(rawRequestBody)) err = logger.output.DisplayJSONBody(rawRequestBody) if err != nil { return err diff --git a/api/plugin/wrapper/request_logger_test.go b/api/plugin/wrapper/request_logger_test.go index 1a7c4b75a11..2b6a5fe1e4e 100644 --- a/api/plugin/wrapper/request_logger_test.go +++ b/api/plugin/wrapper/request_logger_test.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "net/http" "net/url" "time" @@ -132,7 +131,7 @@ var _ = Describe("Request Logger", func() { BeforeEach(func() { request.Header.Set("Content-Type", "application/json") - originalBody = ioutil.NopCloser(bytes.NewReader([]byte("foo"))) + originalBody = io.NopCloser(bytes.NewReader([]byte("foo"))) request.Body = originalBody }) @@ -142,7 +141,7 @@ var _ = Describe("Request Logger", func() { Expect(fakeOutput.DisplayJSONBodyCallCount()).To(BeNumerically(">=", 1)) Expect(fakeOutput.DisplayJSONBodyArgsForCall(0)).To(Equal([]byte("foo"))) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte("foo"))) }) @@ -198,7 +197,7 @@ var _ = Describe("Request Logger", func() { "AAAAA": {"first"}, "CCCCC": {"third"}, }, - Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"some-key":"some-value"}`))), + Body: io.NopCloser(bytes.NewReader([]byte(`{"some-key":"some-value"}`))), }, } }) @@ -249,7 +248,7 @@ var _ = Describe("Request Logger", func() { "AAAAA": {"first"}, "CCCCC": {"third"}, }, - Body: ioutil.NopCloser(bytes.NewReader([]byte(`not JSON`))), + Body: io.NopCloser(bytes.NewReader([]byte(`not JSON`))), }, } }) @@ -335,7 +334,7 @@ var _ = Describe("Request Logger", func() { "AAAAA": {"first"}, "CCCCC": {"third"}, }, - Body: ioutil.NopCloser(bytes.NewReader([]byte(`some-error-body`))), + Body: io.NopCloser(bytes.NewReader([]byte(`some-error-body`))), }, } }) diff --git a/api/plugin/wrapper/retry_request.go b/api/plugin/wrapper/retry_request.go index 83436bd5296..0af18b74dba 100644 --- a/api/plugin/wrapper/retry_request.go +++ b/api/plugin/wrapper/retry_request.go @@ -2,7 +2,7 @@ package wrapper import ( "bytes" - "io/ioutil" + "io" "net/http" "code.cloudfoundry.org/cli/api/plugin" @@ -28,7 +28,7 @@ func (retry *RetryRequest) Make(request *http.Request, passedResponse *plugin.Re var rawRequestBody []byte if request.Body != nil { - rawRequestBody, err = ioutil.ReadAll(request.Body) + rawRequestBody, err = io.ReadAll(request.Body) defer request.Body.Close() if err != nil { return err @@ -37,7 +37,7 @@ func (retry *RetryRequest) Make(request *http.Request, passedResponse *plugin.Re for i := 0; i < retry.maxRetries+1; i++ { if rawRequestBody != nil { - request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody)) + request.Body = io.NopCloser(bytes.NewBuffer(rawRequestBody)) } err = retry.connection.Make(request, passedResponse, proxyReader) if err == nil { diff --git a/api/plugin/wrapper/retry_request_test.go b/api/plugin/wrapper/retry_request_test.go index 6598f2f2a85..151c32b5a03 100644 --- a/api/plugin/wrapper/retry_request_test.go +++ b/api/plugin/wrapper/retry_request_test.go @@ -2,7 +2,7 @@ package wrapper_test import ( "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -22,7 +22,7 @@ var _ = Describe("Retry Request", func() { Expect(err).NotTo(HaveOccurred()) rawRequestBody := "banana pants" - request.Body = ioutil.NopCloser(strings.NewReader(rawRequestBody)) + request.Body = io.NopCloser(strings.NewReader(rawRequestBody)) response := &plugin.Response{ HTTPResponse: &http.Response{ @@ -36,7 +36,7 @@ var _ = Describe("Retry Request", func() { } fakeConnection.MakeStub = func(req *http.Request, passedResponse *plugin.Response, proxyReader plugin.ProxyReader) error { defer req.Body.Close() - body, readErr := ioutil.ReadAll(request.Body) + body, readErr := io.ReadAll(request.Body) Expect(readErr).ToNot(HaveOccurred()) Expect(string(body)).To(Equal(rawRequestBody)) return expectedErr diff --git a/api/plugin/wrapper/wrapper_suite_test.go b/api/plugin/wrapper/wrapper_suite_test.go index 8e4a829554f..c63da4999de 100644 --- a/api/plugin/wrapper/wrapper_suite_test.go +++ b/api/plugin/wrapper/wrapper_suite_test.go @@ -3,12 +3,11 @@ package wrapper_test import ( "bytes" "log" + "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" - - "testing" ) func TestPlugin(t *testing.T) { diff --git a/api/router/router_connection.go b/api/router/router_connection.go index 999ec889946..c5e8ebbc4bd 100644 --- a/api/router/router_connection.go +++ b/api/router/router_connection.go @@ -4,7 +4,7 @@ import ( "bytes" "crypto/x509" "encoding/json" - "io/ioutil" + "io" "net" "net/http" "net/url" @@ -71,7 +71,7 @@ func (*RouterConnection) handleStatusCodes(httpResponse *http.Response, response func (connection *RouterConnection) populateResponse(httpResponse *http.Response, responseToPopulate *Response) error { responseToPopulate.HTTPResponse = httpResponse - rawBytes, err := ioutil.ReadAll(httpResponse.Body) + rawBytes, err := io.ReadAll(httpResponse.Body) defer httpResponse.Body.Close() if err != nil { return err diff --git a/api/router/router_suite_test.go b/api/router/router_suite_test.go index 17ef20c2851..483f3bbb725 100644 --- a/api/router/router_suite_test.go +++ b/api/router/router_suite_test.go @@ -4,13 +4,12 @@ import ( "bytes" "log" "net/url" + "testing" "code.cloudfoundry.org/cli/api/router" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" - - "testing" ) func TestRouter(t *testing.T) { diff --git a/api/router/wrapper/request_logger.go b/api/router/wrapper/request_logger.go index e843d158aab..9f7b4206ea9 100644 --- a/api/router/wrapper/request_logger.go +++ b/api/router/wrapper/request_logger.go @@ -2,7 +2,7 @@ package wrapper import ( "fmt" - "io/ioutil" + "io" "net/http" "sort" "strings" @@ -93,7 +93,7 @@ func (logger *RequestLogger) displayRequest(request *router.Request) error { contentType := request.Header.Get("Content-Type") if request.Body != nil { if strings.Contains(contentType, "json") { - rawRequestBody, err := ioutil.ReadAll(request.Body) + rawRequestBody, err := io.ReadAll(request.Body) if err != nil { return err } @@ -102,7 +102,7 @@ func (logger *RequestLogger) displayRequest(request *router.Request) error { return logger.output.DisplayJSONBody(rawRequestBody) } else if strings.Contains(contentType, "x-www-form-urlencoded") { - rawRequestBody, err := ioutil.ReadAll(request.Body) + rawRequestBody, err := io.ReadAll(request.Body) if err != nil { return err } diff --git a/api/router/wrapper/request_logger_test.go b/api/router/wrapper/request_logger_test.go index 38327611e3f..ac025e02d7c 100644 --- a/api/router/wrapper/request_logger_test.go +++ b/api/router/wrapper/request_logger_test.go @@ -3,7 +3,7 @@ package wrapper_test import ( "bytes" "errors" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -135,7 +135,7 @@ var _ = Describe("Request Logger", func() { Expect(fakeOutput.DisplayJSONBodyCallCount()).To(BeNumerically(">=", 1)) Expect(fakeOutput.DisplayJSONBodyArgsForCall(0)).To(Equal([]byte("foo"))) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte("foo"))) }) @@ -149,7 +149,7 @@ var _ = Describe("Request Logger", func() { It("outputs the body", func() { Expect(makeErr).NotTo(HaveOccurred()) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte("foo"))) Expect(fakeOutput.DisplayMessageCallCount()).To(Equal(1)) diff --git a/api/router/wrapper/uaa_authentication_test.go b/api/router/wrapper/uaa_authentication_test.go index fc15f3a5dbb..73320125a9d 100644 --- a/api/router/wrapper/uaa_authentication_test.go +++ b/api/router/wrapper/uaa_authentication_test.go @@ -2,7 +2,7 @@ package wrapper_test import ( "errors" - "io/ioutil" + "io" "net/http" "strings" @@ -118,12 +118,12 @@ var _ = Describe("UAA Authentication", func() { body := strings.NewReader(expectedBody) request = router.NewRequest(&http.Request{ Header: http.Header{}, - Body: ioutil.NopCloser(body), + Body: io.NopCloser(body), }, body) makeCount := 0 fakeConnection.MakeStub = func(request *router.Request, response *router.Response) error { - body, err := ioutil.ReadAll(request.Body) + body, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(string(body)).To(Equal(expectedBody)) diff --git a/api/shared/wrap_for_cf_on_k8s_test.go b/api/shared/wrap_for_cf_on_k8s_test.go index 1c8d8695aeb..f79b6050919 100644 --- a/api/shared/wrap_for_cf_on_k8s_test.go +++ b/api/shared/wrap_for_cf_on_k8s_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "encoding/pem" "errors" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -136,7 +136,7 @@ var _ = Describe("WrapForCFOnK8sAuth", func() { actualReq := wrappedRoundTripper.RoundTripArgsForCall(0) - body, err := ioutil.ReadAll(actualReq.Body) + body, err := io.ReadAll(actualReq.Body) Expect(err).NotTo(HaveOccurred()) Expect(string(body)).To(Equal("hello")) @@ -396,7 +396,7 @@ var _ = Describe("WrapForCFOnK8sAuth", func() { var tokenFilePath string BeforeEach(func() { - tokenFile, err := ioutil.TempFile("", "") + tokenFile, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) defer tokenFile.Close() _, err = tokenFile.Write(token) @@ -446,9 +446,10 @@ func base64Decode(encoded string) string { } func writeToFile(base64Data string) string { - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") + Expect(err).NotTo(HaveOccurred()) + _, err = file.WriteString(base64Decode(base64Data)) Expect(err).NotTo(HaveOccurred()) - file.WriteString(base64Decode(base64Data)) Expect(file.Close()).To(Succeed()) return file.Name() } diff --git a/api/uaa/auth.go b/api/uaa/auth.go index fa208611e75..1e9ddf6a26e 100644 --- a/api/uaa/auth.go +++ b/api/uaa/auth.go @@ -109,7 +109,11 @@ func (client Client) getJtiFromToken(token string) (string, error) { } payload := make(map[string]interface{}) - json.Unmarshal(jsonPayload, &payload) + err = json.Unmarshal(jsonPayload, &payload) + if err != nil { + return "", err + } + jti, ok := payload["jti"].(string) if !ok { diff --git a/api/uaa/constant/package.go b/api/uaa/constant/package.go index fd0648153c5..acf4aecfb8d 100644 --- a/api/uaa/constant/package.go +++ b/api/uaa/constant/package.go @@ -6,13 +6,14 @@ // exception is 'state' types, where the word 'state' is omitted. // // For Example: -// Constant Type: PackageType -// Enum Name: Bits -// Enum Value: "bits" -// const PackageTypeBits PackageType = "bits" // -// Constant Type: PackageState -// Enum Name: Expired -// Enum Value: "EXPIRED" -// const PackageExpired PackageState = "EXPIRED" +// Constant Type: PackageType +// Enum Name: Bits +// Enum Value: "bits" +// const PackageTypeBits PackageType = "bits" +// +// Constant Type: PackageState +// Enum Name: Expired +// Enum Value: "EXPIRED" +// const PackageExpired PackageState = "EXPIRED" package constant diff --git a/api/uaa/internal/routing.go b/api/uaa/internal/routing.go index 7bdbba163d7..2cbd948ce0c 100644 --- a/api/uaa/internal/routing.go +++ b/api/uaa/internal/routing.go @@ -11,18 +11,22 @@ import ( // Params map path keys to values. For example, if your route has the path // pattern: -// /person/:person_id/pets/:pet_type +// +// /person/:person_id/pets/:pet_type +// // Then a correct Params map would look like: -// router.Params{ -// "person_id": "123", -// "pet_type": "cats", -// } +// +// router.Params{ +// "person_id": "123", +// "pet_type": "cats", +// } type Params map[string]string // Route defines the property of a Cloud Controller V3 endpoint. // // Method can be one of the following: -// GET HEAD POST PUT PATCH DELETE CONNECT OPTIONS TRACE +// +// GET HEAD POST PUT PATCH DELETE CONNECT OPTIONS TRACE // // Path conforms to Pat-style pattern matching. The following docs are taken // from http://godoc.org/github.com/bmizerany/pat#PatternServeMux @@ -35,26 +39,36 @@ type Params map[string]string // string. // // Example pattern with one capture: -// /hello/:name +// +// /hello/:name +// // Will match: -// /hello/blake -// /hello/keith +// +// /hello/blake +// /hello/keith +// // Will not match: -// /hello/blake/ -// /hello/blake/foo -// /foo -// /foo/bar +// +// /hello/blake/ +// /hello/blake/foo +// /foo +// /foo/bar // // Example 2: -// /hello/:name/ +// +// /hello/:name/ +// // Will match: -// /hello/blake/ -// /hello/keith/foo -// /hello/blake -// /hello/keith +// +// /hello/blake/ +// /hello/keith/foo +// /hello/blake +// /hello/keith +// // Will not match: -// /foo -// /foo/bar +// +// /foo +// /foo/bar type Route struct { // Name is a key specifying which HTTP route the router should associate with // the endpoint at runtime. diff --git a/api/uaa/uaa_connection.go b/api/uaa/uaa_connection.go index 39b3726778c..69c6be93fd2 100644 --- a/api/uaa/uaa_connection.go +++ b/api/uaa/uaa_connection.go @@ -4,12 +4,12 @@ import ( "bytes" "crypto/x509" "encoding/json" - "io/ioutil" + "errors" + "io" "net" "net/http" "net/url" "time" - "errors" "code.cloudfoundry.org/cli/util" ) @@ -74,7 +74,7 @@ func (*UAAConnection) handleStatusCodes(response *http.Response, passedResponse func (connection *UAAConnection) populateResponse(response *http.Response, passedResponse *Response) error { passedResponse.HTTPResponse = response - rawBytes, err := ioutil.ReadAll(response.Body) + rawBytes, err := io.ReadAll(response.Body) defer response.Body.Close() if err != nil { return err diff --git a/api/uaa/wrapper/request_logger.go b/api/uaa/wrapper/request_logger.go index e68a8ad3f8d..8e034252114 100644 --- a/api/uaa/wrapper/request_logger.go +++ b/api/uaa/wrapper/request_logger.go @@ -2,7 +2,7 @@ package wrapper import ( "bytes" - "io/ioutil" + "io" "net/http" "regexp" "sort" @@ -91,13 +91,13 @@ func (logger *RequestLogger) displayRequest(request *http.Request) error { } if request.Body != nil { - rawRequestBody, err := ioutil.ReadAll(request.Body) + rawRequestBody, err := io.ReadAll(request.Body) defer request.Body.Close() if err != nil { return err } - request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody)) + request.Body = io.NopCloser(bytes.NewBuffer(rawRequestBody)) if request.Header.Get("Content-Type") == "application/json" { err = logger.output.DisplayJSONBody(rawRequestBody) } else { diff --git a/api/uaa/wrapper/request_logger_test.go b/api/uaa/wrapper/request_logger_test.go index 57ba35041bc..b7b0f036faa 100644 --- a/api/uaa/wrapper/request_logger_test.go +++ b/api/uaa/wrapper/request_logger_test.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "net/http" "net/url" "time" @@ -156,7 +155,7 @@ var _ = Describe("Request Logger", func() { When("the body is not JSON", func() { BeforeEach(func() { - originalBody = ioutil.NopCloser(bytes.NewReader([]byte("foo"))) + originalBody = io.NopCloser(bytes.NewReader([]byte("foo"))) request.Body = originalBody }) @@ -166,7 +165,7 @@ var _ = Describe("Request Logger", func() { Expect(fakeOutput.DisplayBodyCallCount()).To(BeNumerically(">=", 1)) Expect(fakeOutput.DisplayBodyArgsForCall(0)).To(Equal([]byte("foo"))) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte("foo"))) }) @@ -177,7 +176,7 @@ var _ = Describe("Request Logger", func() { BeforeEach(func() { jsonBody = `{"some-key": "some-value"}` - originalBody = ioutil.NopCloser(bytes.NewReader([]byte(jsonBody))) + originalBody = io.NopCloser(bytes.NewReader([]byte(jsonBody))) request.Body = originalBody request.Header.Add("Content-Type", "application/json") }) @@ -188,7 +187,7 @@ var _ = Describe("Request Logger", func() { Expect(fakeOutput.DisplayJSONBodyCallCount()).To(BeNumerically(">=", 1)) Expect(fakeOutput.DisplayJSONBodyArgsForCall(0)).To(Equal([]byte(jsonBody))) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte(jsonBody))) }) diff --git a/api/uaa/wrapper/retry_request.go b/api/uaa/wrapper/retry_request.go index 538752f77d3..fa5c1103533 100644 --- a/api/uaa/wrapper/retry_request.go +++ b/api/uaa/wrapper/retry_request.go @@ -2,7 +2,7 @@ package wrapper import ( "bytes" - "io/ioutil" + "io" "net/http" "code.cloudfoundry.org/cli/api/uaa" @@ -28,7 +28,7 @@ func (retry *RetryRequest) Make(request *http.Request, passedResponse *uaa.Respo var rawRequestBody []byte if request.Body != nil { - rawRequestBody, err = ioutil.ReadAll(request.Body) + rawRequestBody, err = io.ReadAll(request.Body) defer request.Body.Close() if err != nil { return err @@ -37,7 +37,7 @@ func (retry *RetryRequest) Make(request *http.Request, passedResponse *uaa.Respo for i := 0; i < retry.maxRetries+1; i++ { if rawRequestBody != nil { - request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody)) + request.Body = io.NopCloser(bytes.NewBuffer(rawRequestBody)) } err = retry.connection.Make(request, passedResponse) if err == nil { diff --git a/api/uaa/wrapper/retry_request_test.go b/api/uaa/wrapper/retry_request_test.go index f953f355c43..7c0270dec97 100644 --- a/api/uaa/wrapper/retry_request_test.go +++ b/api/uaa/wrapper/retry_request_test.go @@ -1,7 +1,7 @@ package wrapper_test import ( - "io/ioutil" + "io" "net/http" "strings" @@ -20,7 +20,7 @@ var _ = Describe("Retry Request", func() { Expect(err).NotTo(HaveOccurred()) rawRequestBody := "banana pants" - request.Body = ioutil.NopCloser(strings.NewReader(rawRequestBody)) + request.Body = io.NopCloser(strings.NewReader(rawRequestBody)) response := &uaa.Response{ HTTPResponse: &http.Response{ @@ -34,7 +34,7 @@ var _ = Describe("Retry Request", func() { } fakeConnection.MakeStub = func(req *http.Request, passedResponse *uaa.Response) error { defer req.Body.Close() - body, readErr := ioutil.ReadAll(request.Body) + body, readErr := io.ReadAll(request.Body) Expect(readErr).ToNot(HaveOccurred()) Expect(string(body)).To(Equal(rawRequestBody)) return expectedErr diff --git a/api/uaa/wrapper/uaa_authentication.go b/api/uaa/wrapper/uaa_authentication.go index 10b1268e704..96bc7e64d03 100644 --- a/api/uaa/wrapper/uaa_authentication.go +++ b/api/uaa/wrapper/uaa_authentication.go @@ -2,7 +2,7 @@ package wrapper import ( "bytes" - "io/ioutil" + "io" "net/http" "strings" @@ -54,13 +54,13 @@ func (t *UAAAuthentication) Make(request *http.Request, passedResponse *uaa.Resp var rawRequestBody []byte if request.Body != nil { - rawRequestBody, err = ioutil.ReadAll(request.Body) + rawRequestBody, err = io.ReadAll(request.Body) defer request.Body.Close() if err != nil { return err } - request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody)) + request.Body = io.NopCloser(bytes.NewBuffer(rawRequestBody)) if skipAuthenticationHeader(request, rawRequestBody) { return t.connection.Make(request, passedResponse) @@ -80,7 +80,7 @@ func (t *UAAAuthentication) Make(request *http.Request, passedResponse *uaa.Resp t.cache.SetRefreshToken(tokens.RefreshToken) if rawRequestBody != nil { - request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody)) + request.Body = io.NopCloser(bytes.NewBuffer(rawRequestBody)) } request.Header.Set("Authorization", t.cache.AccessToken()) return t.connection.Make(request, passedResponse) diff --git a/api/uaa/wrapper/uaa_authentication_test.go b/api/uaa/wrapper/uaa_authentication_test.go index 6b3c3abe269..055dac1f799 100644 --- a/api/uaa/wrapper/uaa_authentication_test.go +++ b/api/uaa/wrapper/uaa_authentication_test.go @@ -3,7 +3,7 @@ package wrapper_test import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -113,13 +113,13 @@ var _ = Describe("UAA Authentication", func() { request, err := http.NewRequest( http.MethodGet, server.URL(), - ioutil.NopCloser(strings.NewReader(expectedBody)), + io.NopCloser(strings.NewReader(expectedBody)), ) Expect(err).NotTo(HaveOccurred()) makeCount := 0 fakeConnection.MakeStub = func(request *http.Request, response *uaa.Response) error { - body, readErr := ioutil.ReadAll(request.Body) + body, readErr := io.ReadAll(request.Body) Expect(readErr).NotTo(HaveOccurred()) Expect(string(body)).To(Equal(expectedBody)) diff --git a/api/uaa/wrapper/wrapper_suite_test.go b/api/uaa/wrapper/wrapper_suite_test.go index b74befb120a..7e400a74abc 100644 --- a/api/uaa/wrapper/wrapper_suite_test.go +++ b/api/uaa/wrapper/wrapper_suite_test.go @@ -3,12 +3,11 @@ package wrapper_test import ( "bytes" "log" + "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" - - "testing" ) func TestUAA(t *testing.T) { diff --git a/cf/flags/stringSlice.go b/cf/flags/stringSlice.go index bac798714da..5e809b163b8 100644 --- a/cf/flags/stringSlice.go +++ b/cf/flags/stringSlice.go @@ -1,6 +1,6 @@ package flags -//StringSlice flag can be define multiple times in the arguments +// StringSlice flag can be define multiple times in the arguments type StringSliceFlag struct { Name string Value []string diff --git a/cf/net/http_client.go b/cf/net/http_client.go index 978c31e5b3c..8f6411cd697 100644 --- a/cf/net/http_client.go +++ b/cf/net/http_client.go @@ -3,12 +3,12 @@ package net import ( _ "crypto/sha512" // #82254112: http://bridge.grumpy-troll.org/2014/05/golang-tls-comodo/ "crypto/x509" + asErrors "errors" "fmt" "net" "net/http" "net/url" "strings" - asErrors "errors" "code.cloudfoundry.org/cli/cf/errors" . "code.cloudfoundry.org/cli/cf/i18n" @@ -84,13 +84,13 @@ func WrapNetworkErrors(host string, err error) error { } if innerErr != nil { - if asErrors.As(innerErr, &x509.UnknownAuthorityError{}){ + if asErrors.As(innerErr, &x509.UnknownAuthorityError{}) { return errors.NewInvalidSSLCert(host, T("unknown authority")) } - if asErrors.As(innerErr, &x509.HostnameError{}){ + if asErrors.As(innerErr, &x509.HostnameError{}) { return errors.NewInvalidSSLCert(host, T("not valid for the requested host")) } - if asErrors.As(innerErr, &x509.CertificateInvalidError{}){ + if asErrors.As(innerErr, &x509.CertificateInvalidError{}) { return errors.NewInvalidSSLCert(host, "") } typedInnerErr := new(net.OpError) diff --git a/cf/util/downloader/file_download.go b/cf/util/downloader/file_download.go index 567a9c9d664..8f5c41e0e7c 100644 --- a/cf/util/downloader/file_download.go +++ b/cf/util/downloader/file_download.go @@ -29,7 +29,7 @@ func NewDownloader(saveDir string) Downloader { } } -//this func returns byte written, filename and error +// this func returns byte written, filename and error func (d *downloader) DownloadFile(url string) (int64, string, error) { c := http.Client{ Transport: &http.Transport{ diff --git a/cf/util/glob/glob.go b/cf/util/glob/glob.go index 860ac68718a..e30edd0be85 100644 --- a/cf/util/glob/glob.go +++ b/cf/util/glob/glob.go @@ -9,10 +9,10 @@ import ( // matching against paths. // // Glob notation: -// - `?` matches a single char in a single path component -// - `*` matches zero or more chars in a single path component -// - `**` matches zero or more chars in zero or more components -// - any other sequence matches itself +// - `?` matches a single char in a single path component +// - `*` matches zero or more chars in a single path component +// - `**` matches zero or more chars in zero or more components +// - any other sequence matches itself type Glob struct { pattern string // original glob pattern regexp *regexp.Regexp // compiled regexp @@ -27,9 +27,9 @@ func mustBuildRe(p string) *regexp.Regexp { var globRe = mustBuildRe(`(` + charPat + `|[\*\?])`) // Supports unix/ruby-style glob patterns: -// - `?` matches a single char in a single path component -// - `*` matches zero or more chars in a single path component -// - `**` matches zero or more chars in zero or more components +// - `?` matches a single char in a single path component +// - `*` matches zero or more chars in a single path component +// - `**` matches zero or more chars in zero or more components func translateGlob(pat string) (string, error) { if !globRe.MatchString(pat) { return "", Error(pat) diff --git a/cf/util/testhelpers/io/io.go b/cf/util/testhelpers/io/io.go index 571232151d4..6a66f439ae9 100644 --- a/cf/util/testhelpers/io/io.go +++ b/cf/util/testhelpers/io/io.go @@ -59,10 +59,10 @@ func CaptureOutput(block func()) []string { } /* - The reason we're doing is that you can't write an infinite amount of bytes into a pipe. - On some platforms, the limit is fairly high; on other platforms, the limit is infuriatingly small - (looking at you, Windows). To counteract this, we need to read in a goroutine from one end of - the pipe and return the result across a channel. +The reason we're doing is that you can't write an infinite amount of bytes into a pipe. +On some platforms, the limit is fairly high; on other platforms, the limit is infuriatingly small +(looking at you, Windows). To counteract this, we need to read in a goroutine from one end of +the pipe and return the result across a channel. */ func captureOutputAsynchronously(doneWriting <-chan bool, result chan<- []string, reader io.Reader) { var readingString string diff --git a/command/common/help_command.go b/command/common/help_command.go index 23e9b429e0d..60aea1586d9 100644 --- a/command/common/help_command.go +++ b/command/common/help_command.go @@ -214,10 +214,10 @@ func (cmd HelpCommand) displayCommonCommands() { func (cmd HelpCommand) displayCommand() error { cmdInfo, err := cmd.Actor.CommandInfoByName(Commands, cmd.OptionalArgs.CommandName) if err != nil { - if err, ok := err.(actionerror.InvalidCommandError); ok { + if err1, ok := err.(actionerror.InvalidCommandError); ok { var found bool if cmdInfo, found = cmd.findPlugin(); !found { - return err + return err1 } } else { return err diff --git a/command/common/install_plugin_command.go b/command/common/install_plugin_command.go index 16a51682fad..b119bb6d1e5 100644 --- a/command/common/install_plugin_command.go +++ b/command/common/install_plugin_command.go @@ -1,7 +1,6 @@ package common import ( - "io/ioutil" "os" "runtime" "strings" @@ -79,7 +78,7 @@ func (cmd InstallPluginCommand) Execute([]string) (err error) { log.WithField("PluginHome", cmd.Config.PluginHome()).Info("making plugin dir") var tempPluginDir string - tempPluginDir, err = ioutil.TempDir(cmd.Config.PluginHome(), "temp") + tempPluginDir, err = os.MkdirTemp(cmd.Config.PluginHome(), "temp") log.WithField("tempPluginDir", tempPluginDir).Debug("making tempPluginDir dir") defer func() { diff --git a/command/common/install_plugin_command_test.go b/command/common/install_plugin_command_test.go index 24880301f35..af2a80b01ea 100644 --- a/command/common/install_plugin_command_test.go +++ b/command/common/install_plugin_command_test.go @@ -2,7 +2,6 @@ package common_test import ( "errors" - "io/ioutil" "os" "code.cloudfoundry.org/cli/actor/actionerror" @@ -47,7 +46,7 @@ var _ = Describe("install-plugin command", func() { } var err error - pluginHome, err = ioutil.TempDir("", "some-pluginhome") + pluginHome, err = os.MkdirTemp("", "some-pluginhome") Expect(err).NotTo(HaveOccurred()) fakeConfig.PluginHomeReturns(pluginHome) diff --git a/command/common/install_plugin_from_repo_command_test.go b/command/common/install_plugin_from_repo_command_test.go index b9e61609492..a6d49af0ca4 100644 --- a/command/common/install_plugin_from_repo_command_test.go +++ b/command/common/install_plugin_from_repo_command_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math/rand" "os" "runtime" @@ -56,7 +55,7 @@ var _ = Describe("install-plugin command", func() { } var err error - pluginHome, err = ioutil.TempDir("", "some-pluginhome") + pluginHome, err = os.MkdirTemp("", "some-pluginhome") Expect(err).ToNot(HaveOccurred()) fakeConfig.PluginHomeReturns(pluginHome) binaryName = helpers.PrefixedRandomName("bin") diff --git a/command/flag/credentials_or_json.go b/command/flag/credentials_or_json.go index d4beca680c3..af667374f9e 100644 --- a/command/flag/credentials_or_json.go +++ b/command/flag/credentials_or_json.go @@ -3,7 +3,7 @@ package flag import ( "encoding/json" "fmt" - "io/ioutil" + "os" "strings" "code.cloudfoundry.org/cli/types" @@ -54,7 +54,7 @@ func canParseAsJSON(input string) (value map[string]interface{}, ok bool) { } func canParseFileAsJSON(input string) (value map[string]interface{}, ok bool, parseError error) { - contents, err := ioutil.ReadFile(input) + contents, err := os.ReadFile(input) if err != nil { return } diff --git a/command/flag/docker.go b/command/flag/docker.go index 5bab908f3d2..c5d8ace34b3 100644 --- a/command/flag/docker.go +++ b/command/flag/docker.go @@ -3,7 +3,7 @@ package flag import ( "fmt" - "github.com/docker/distribution/reference" + "github.com/distribution/reference" flags "github.com/jessevdk/go-flags" ) diff --git a/command/flag/flag_suite_test.go b/command/flag/flag_suite_test.go index 9bed6008825..8f8a5ad234d 100644 --- a/command/flag/flag_suite_test.go +++ b/command/flag/flag_suite_test.go @@ -1,13 +1,11 @@ package flag_test import ( - "io/ioutil" "os" + "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) func TestFlag(t *testing.T) { @@ -19,7 +17,7 @@ var tempDir string var _ = BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "cf-cli-") + tempDir, err = os.MkdirTemp("", "cf-cli-") Expect(err).ToNot(HaveOccurred()) }) @@ -29,7 +27,7 @@ var _ = AfterEach(func() { }) func tempFile(data string) string { - tempFile, err := ioutil.TempFile(tempDir, "") + tempFile, err := os.CreateTemp(tempDir, "") Expect(err).ToNot(HaveOccurred()) _, err = tempFile.WriteString(data) Expect(err).ToNot(HaveOccurred()) diff --git a/command/flag/path.go b/command/flag/path.go index b23b8b433ab..610c2ddccc4 100644 --- a/command/flag/path.go +++ b/command/flag/path.go @@ -3,7 +3,6 @@ package flag import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -106,7 +105,7 @@ func (p *JSONOrFileWithValidation) UnmarshalFlag(pathOrJSON string) error { _, err := os.Stat(pathOrJSON) if err == nil { - jsonBytes, err = ioutil.ReadFile(pathOrJSON) + jsonBytes, err = os.ReadFile(pathOrJSON) if err != nil { return errorToReturn } diff --git a/command/flag/path_test.go b/command/flag/path_test.go index 00df2b26b18..ddbb6f688ed 100644 --- a/command/flag/path_test.go +++ b/command/flag/path_test.go @@ -2,7 +2,6 @@ package flag_test import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -94,12 +93,12 @@ var _ = Describe("path types", func() { ) BeforeEach(func() { - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) os.Setenv("HOME", tempDir) for _, filename := range []string{"abc", "def"} { - err = ioutil.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) + err = os.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) Expect(err).ToNot(HaveOccurred()) } @@ -144,12 +143,12 @@ var _ = Describe("path types", func() { ) BeforeEach(func() { - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) os.Setenv("HOME", tempDir) for _, filename := range []string{"abc", "def"} { - err = ioutil.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) + err = os.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) Expect(err).ToNot(HaveOccurred()) } @@ -181,14 +180,14 @@ var _ = Describe("path types", func() { currentDir, err = os.Getwd() Expect(err).ToNot(HaveOccurred()) - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) err = os.Chdir(tempDir) Expect(err).ToNot(HaveOccurred()) for _, filename := range []string{"abc", "abd", "~abd", "tfg", "ABCD"} { - err = ioutil.WriteFile(filename, []byte{}, 0400) + err = os.WriteFile(filename, []byte{}, 0400) Expect(err).ToNot(HaveOccurred()) } @@ -484,12 +483,12 @@ var _ = Describe("path types", func() { ) BeforeEach(func() { - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) os.Setenv("HOME", tempDir) for _, filename := range []string{"abc", "def"} { - err = ioutil.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) + err = os.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) Expect(err).ToNot(HaveOccurred()) } @@ -534,12 +533,12 @@ var _ = Describe("path types", func() { ) BeforeEach(func() { - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) os.Setenv("HOME", tempDir) for _, filename := range []string{"abc", "def"} { - err = ioutil.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) + err = os.WriteFile(filepath.Join(tempDir, filename), []byte{}, 0400) Expect(err).ToNot(HaveOccurred()) } diff --git a/command/plugin/plugins_command_test.go b/command/plugin/plugins_command_test.go index 699abd804ef..381a51a5659 100644 --- a/command/plugin/plugins_command_test.go +++ b/command/plugin/plugins_command_test.go @@ -1,7 +1,6 @@ package plugin_test import ( - "io/ioutil" "os" "code.cloudfoundry.org/cli/actor/actionerror" @@ -138,11 +137,11 @@ var _ = Describe("plugins Command", func() { cmd.Checksum = true var err error - file, err = ioutil.TempFile("", "") + file, err = os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) defer file.Close() - err = ioutil.WriteFile(file.Name(), []byte("some-text"), 0600) + err = os.WriteFile(file.Name(), []byte("some-text"), 0600) Expect(err).NotTo(HaveOccurred()) plugins[0].Location = file.Name() diff --git a/command/plugin/shared/rpc.go b/command/plugin/shared/rpc.go index 0a9fa550607..0565fc5b002 100644 --- a/command/plugin/shared/rpc.go +++ b/command/plugin/shared/rpc.go @@ -3,12 +3,11 @@ package shared import ( "fmt" "io" + netrpc "net/rpc" "os" "os/exec" "time" - netrpc "net/rpc" - "code.cloudfoundry.org/cli/cf/commandregistry" "code.cloudfoundry.org/cli/cf/trace" "code.cloudfoundry.org/cli/plugin/rpc" diff --git a/command/ui.go b/command/ui.go index aedbe168ed4..6c479b8385f 100644 --- a/command/ui.go +++ b/command/ui.go @@ -8,6 +8,7 @@ import ( ) // UI is the interface to STDOUT, STDERR, and STDIN. +// //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . UI type UI interface { DeferText(template string, data ...map[string]interface{}) diff --git a/command/v7/create_app_manifest_command.go b/command/v7/create_app_manifest_command.go index 69d8652b50b..4a8e745f029 100644 --- a/command/v7/create_app_manifest_command.go +++ b/command/v7/create_app_manifest_command.go @@ -2,7 +2,6 @@ package v7 import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -66,7 +65,7 @@ func (cmd CreateAppManifestCommand) Execute(args []string) error { pathToYAMLFile = filepath.Join(cmd.PWD, fmt.Sprintf("%s_manifest.yml", appName)) } - err = ioutil.WriteFile(pathToYAMLFile, manifestBytes, 0666) + err = os.WriteFile(pathToYAMLFile, manifestBytes, 0666) if err != nil { return translatableerror.FileCreationError{Err: err} } diff --git a/command/v7/create_app_manifest_command_test.go b/command/v7/create_app_manifest_command_test.go index 0ecbe58b63e..eec45881d0c 100644 --- a/command/v7/create_app_manifest_command_test.go +++ b/command/v7/create_app_manifest_command_test.go @@ -2,7 +2,6 @@ package v7_test import ( "errors" - "io/ioutil" "os" "path/filepath" "regexp" @@ -103,7 +102,7 @@ var _ = Describe("create-app-manifest Command", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "create-app-manifest-unit") + tempDir, err = os.MkdirTemp("", "create-app-manifest-unit") Expect(err).ToNot(HaveOccurred()) cmd.PWD = tempDir @@ -124,7 +123,7 @@ var _ = Describe("create-app-manifest Command", func() { Expect(appArg).To(Equal("some-app")) Expect(spaceArg).To(Equal("some-space-guid")) - fileContents, err := ioutil.ReadFile(pathToYAMLFile) + fileContents, err := os.ReadFile(pathToYAMLFile) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal(yamlContents)) }) @@ -157,7 +156,7 @@ var _ = Describe("create-app-manifest Command", func() { Expect(appArg).To(Equal("some-app")) Expect(spaceArg).To(Equal("some-space-guid")) - fileContents, err := ioutil.ReadFile(flagPath) + fileContents, err := os.ReadFile(flagPath) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal(yamlContents)) }) diff --git a/command/v7/create_buildpack_command.go b/command/v7/create_buildpack_command.go index 526fdc83474..9b64dfbab36 100644 --- a/command/v7/create_buildpack_command.go +++ b/command/v7/create_buildpack_command.go @@ -1,7 +1,6 @@ package v7 import ( - "io/ioutil" "os" "time" @@ -48,7 +47,7 @@ func (cmd CreateBuildpackCommand) Execute(args []string) error { }) downloader := download.NewDownloader(time.Second * 30) - tmpDirPath, err := ioutil.TempDir("", "buildpack-dir-") + tmpDirPath, err := os.MkdirTemp("", "buildpack-dir-") if err != nil { return err } diff --git a/command/v7/create_service_broker_command.go b/command/v7/create_service_broker_command.go index 798539f3f57..61341bb8a70 100644 --- a/command/v7/create_service_broker_command.go +++ b/command/v7/create_service_broker_command.go @@ -18,7 +18,6 @@ type CreateServiceBrokerCommand struct { UpdateIfExists bool `long:"update-if-exists" description:"If the broker already exists, update it rather than failing. Ignores --space-scoped."` usage any `usage:"CF_NAME create-service-broker SERVICE_BROKER USERNAME PASSWORD URL [--space-scoped]\n CF_NAME create-service-broker SERVICE_BROKER USERNAME URL [--space-scoped] (omit password to specify interactively or via environment variable)\n\nWARNING:\n Providing your password as a command line option is highly discouraged\n Your password may be visible to others and may be recorded in your shell history"` relatedCommands any `related_commands:"enable-service-access, service-brokers, target"` - envPassword any `environmentName:"CF_BROKER_PASSWORD" environmentDescription:"Password associated with user. Overridden if PASSWORD argument is provided" environmentDefault:"password"` } func (cmd *CreateServiceBrokerCommand) Execute(args []string) error { diff --git a/command/v7/curl_command.go b/command/v7/curl_command.go index 8f8d3be40d3..764c5075254 100644 --- a/command/v7/curl_command.go +++ b/command/v7/curl_command.go @@ -1,8 +1,8 @@ package v7 import ( - "io/ioutil" "net/http/httputil" + "os" "code.cloudfoundry.org/cli/command/flag" "code.cloudfoundry.org/cli/command/translatableerror" @@ -48,7 +48,7 @@ func (cmd CurlCommand) Execute(args []string) error { bytesToWrite = append(bytesToWrite, responseBodyBytes...) if cmd.OutputFile != "" { - err = ioutil.WriteFile(cmd.OutputFile.String(), bytesToWrite, 0666) + err = os.WriteFile(cmd.OutputFile.String(), bytesToWrite, 0666) if err != nil { return translatableerror.FileCreationError{Err: err} } diff --git a/command/v7/curl_command_test.go b/command/v7/curl_command_test.go index 0a68d266d8d..e7fc9fe8a89 100644 --- a/command/v7/curl_command_test.go +++ b/command/v7/curl_command_test.go @@ -2,7 +2,6 @@ package v7_test import ( "errors" - "io/ioutil" "net/http" "os" @@ -110,7 +109,7 @@ var _ = Describe("curl Command", func() { When("an output file is given", func() { BeforeEach(func() { - outputFile, err := ioutil.TempFile("", "") + outputFile, err := os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) outputFileName := outputFile.Name() cmd.OutputFile = flag.Path(outputFileName) @@ -121,7 +120,7 @@ var _ = Describe("curl Command", func() { }) It("writes the output to the file", func() { - fileContents, err := ioutil.ReadFile(string(cmd.OutputFile)) + fileContents, err := os.ReadFile(string(cmd.OutputFile)) Expect(string(fileContents)).To(Equal("sarah, teal, and reid were here")) Expect(err).ToNot(HaveOccurred()) }) @@ -132,7 +131,7 @@ var _ = Describe("curl Command", func() { }) It("includes the headers in the output", func() { - fileContents, err := ioutil.ReadFile(string(cmd.OutputFile)) + fileContents, err := os.ReadFile(string(cmd.OutputFile)) Expect(string(fileContents)).To(ContainSubstring("X-Name: athleisure")) Expect(string(fileContents)).To(ContainSubstring("sarah, teal, and reid were here")) Expect(err).ToNot(HaveOccurred()) diff --git a/command/v7/download_droplet_command.go b/command/v7/download_droplet_command.go index 0b4b55cb6a0..a04e4a94bcc 100644 --- a/command/v7/download_droplet_command.go +++ b/command/v7/download_droplet_command.go @@ -2,7 +2,6 @@ package v7 import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -90,7 +89,7 @@ func (cmd DownloadDropletCommand) Execute(args []string) error { } } - err = ioutil.WriteFile(pathToDroplet, rawDropletBytes, 0666) + err = os.WriteFile(pathToDroplet, rawDropletBytes, 0666) if err != nil { return translatableerror.DropletFileError{Err: err} } diff --git a/command/v7/download_droplet_command_test.go b/command/v7/download_droplet_command_test.go index dc67c935173..3db2c2db9fd 100644 --- a/command/v7/download_droplet_command_test.go +++ b/command/v7/download_droplet_command_test.go @@ -3,7 +3,6 @@ package v7_test import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -108,7 +107,7 @@ var _ = Describe("download-droplet Command", func() { Expect(appArg).To(Equal("some-app")) Expect(spaceGUIDArg).To(Equal("some-space-guid")) - fileContents, err := ioutil.ReadFile(pathToDropletFile) + fileContents, err := os.ReadFile(pathToDropletFile) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal("some-droplet-bytes")) }) @@ -150,7 +149,7 @@ var _ = Describe("download-droplet Command", func() { Expect(appArg).To(Equal("some-app")) Expect(spaceGUIDArg).To(Equal("some-space-guid")) - fileContents, err := ioutil.ReadFile(pathToDropletFile) + fileContents, err := os.ReadFile(pathToDropletFile) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal("some-droplet-bytes")) }) @@ -180,7 +179,7 @@ var _ = Describe("download-droplet Command", func() { It("creates a droplet tarball at the specified path", func() { Expect(executeErr).ToNot(HaveOccurred()) - fileContents, err := ioutil.ReadFile(filePath) + fileContents, err := os.ReadFile(filePath) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal("some-droplet")) }) @@ -199,7 +198,7 @@ var _ = Describe("download-droplet Command", func() { BeforeEach(func() { var err error - tmpDir, err = ioutil.TempDir("", "droplets") + tmpDir, err = os.MkdirTemp("", "droplets") Expect(err).NotTo(HaveOccurred()) setFlag(&cmd, "--path", tmpDir) @@ -214,7 +213,7 @@ var _ = Describe("download-droplet Command", func() { It("creates a droplet tarball at the specified path", func() { Expect(executeErr).ToNot(HaveOccurred()) - fileContents, err := ioutil.ReadFile(filepath.Join(tmpDir, "droplet_some-droplet-guid.tgz")) + fileContents, err := os.ReadFile(filepath.Join(tmpDir, "droplet_some-droplet-guid.tgz")) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal("some-droplet")) }) diff --git a/command/v7/enable_ssh_command.go b/command/v7/enable_ssh_command.go index 8c671cdf280..dcb8f9044e4 100644 --- a/command/v7/enable_ssh_command.go +++ b/command/v7/enable_ssh_command.go @@ -75,4 +75,3 @@ func (cmd *EnableSSHCommand) Execute(args []string) error { return nil } - diff --git a/command/v7/logout_command.go b/command/v7/logout_command.go index 0e7850c977f..9d909238584 100644 --- a/command/v7/logout_command.go +++ b/command/v7/logout_command.go @@ -38,7 +38,10 @@ func (cmd LogoutCommand) Execute(args []string) error { "Username": user.Name, }) - cmd.Actor.RevokeAccessAndRefreshTokens() + err = cmd.Actor.RevokeAccessAndRefreshTokens() + if err != nil { + return err + } cmd.Config.UnsetUserInformation() cmd.UI.DisplayOK() diff --git a/command/v7/move_route_command.go b/command/v7/move_route_command.go index 4ba150568d1..d9425362b78 100644 --- a/command/v7/move_route_command.go +++ b/command/v7/move_route_command.go @@ -64,7 +64,7 @@ func (cmd MoveRouteCommand) Execute(args []string) error { } destinationOrg, warnings, err := cmd.Actor.GetOrganizationByName(destinationOrgName) - + cmd.UI.DisplayWarnings(warnings) if err != nil { if _, ok := err.(actionerror.OrganizationNotFoundError); ok { cmd.UI.DisplayText("Can not transfer ownership of route:") @@ -73,6 +73,7 @@ func (cmd MoveRouteCommand) Execute(args []string) error { } targetedSpace, warnings, err := cmd.Actor.GetSpaceByNameAndOrganization(cmd.DestinationSpace, destinationOrg.GUID) + cmd.UI.DisplayWarnings(warnings) if err != nil { if _, ok := err.(actionerror.SpaceNotFoundError); ok { cmd.UI.DisplayText("Can not transfer ownership of route:") @@ -91,6 +92,7 @@ func (cmd MoveRouteCommand) Execute(args []string) error { route.GUID, targetedSpace.GUID, ) + cmd.UI.DisplayWarnings(warnings) if err != nil { return err diff --git a/command/v7/rename_service_command.go b/command/v7/rename_service_command.go index f298e75c307..8380d564cb0 100644 --- a/command/v7/rename_service_command.go +++ b/command/v7/rename_service_command.go @@ -1,10 +1,11 @@ package v7 import ( + "strings" + "code.cloudfoundry.org/cli/actor/actionerror" "code.cloudfoundry.org/cli/command/flag" "code.cloudfoundry.org/cli/command/translatableerror" - "strings" ) type RenameServiceCommand struct { diff --git a/command/v7/revision_command_test.go b/command/v7/revision_command_test.go index ef20e4b8bdf..2b31c71045f 100644 --- a/command/v7/revision_command_test.go +++ b/command/v7/revision_command_test.go @@ -46,7 +46,7 @@ var _ = Describe("revision Command", func() { }) JustBeforeEach(func() { - cmd.Execute(nil) + Expect(cmd.Execute(nil)).To(Succeed()) }) It("displays the experimental warning", func() { diff --git a/command/v7/service_command_test.go b/command/v7/service_command_test.go index dfddade6749..cddd13ac087 100644 --- a/command/v7/service_command_test.go +++ b/command/v7/service_command_test.go @@ -348,7 +348,7 @@ var _ = Describe("service command", func() { ServiceBrokerName: serviceBrokerName, SharedStatus: v7action.SharedStatus{ IsSharedToOtherSpaces: true, - UsageSummary: []v7action.UsageSummaryWithSpaceAndOrg{{"shared-to-space", "some-org", 3}}, + UsageSummary: []v7action.UsageSummaryWithSpaceAndOrg{{SpaceName: "shared-to-space", OrganizationName: "some-org", BoundAppCount: 3}}, }, }, v7action.Warnings{"warning one", "warning two"}, diff --git a/command/v7/share_route_command.go b/command/v7/share_route_command.go index 8f36268da50..36f07fa27f7 100644 --- a/command/v7/share_route_command.go +++ b/command/v7/share_route_command.go @@ -64,6 +64,7 @@ func (cmd ShareRouteCommand) Execute(args []string) error { } destinationOrg, warnings, err := cmd.Actor.GetOrganizationByName(destinationOrgName) + cmd.UI.DisplayWarnings(warnings) if err != nil { if _, ok := err.(actionerror.OrganizationNotFoundError); ok { @@ -73,6 +74,7 @@ func (cmd ShareRouteCommand) Execute(args []string) error { } targetedSpace, warnings, err := cmd.Actor.GetSpaceByNameAndOrganization(cmd.DestinationSpace, destinationOrg.GUID) + cmd.UI.DisplayWarnings(warnings) if err != nil { if _, ok := err.(actionerror.SpaceNotFoundError); ok { cmd.UI.DisplayText("Can not share route:") diff --git a/command/v7/unbind_service_command.go b/command/v7/unbind_service_command.go index ccf2f134fd7..4030d17da40 100644 --- a/command/v7/unbind_service_command.go +++ b/command/v7/unbind_service_command.go @@ -52,8 +52,6 @@ func (cmd UnbindServiceCommand) Execute(args []string) error { cmd.UI.DisplayText("Unbinding in progress. Use 'cf service {{.ServiceInstanceName}}' to check operation status.", cmd.names()) return nil } - - return nil } func (cmd UnbindServiceCommand) Usage() string { diff --git a/command/v7/unbind_service_command_test.go b/command/v7/unbind_service_command_test.go index b9f96903539..b050354cc76 100644 --- a/command/v7/unbind_service_command_test.go +++ b/command/v7/unbind_service_command_test.go @@ -6,7 +6,7 @@ import ( "code.cloudfoundry.org/cli/actor/actionerror" "code.cloudfoundry.org/cli/actor/v7action" "code.cloudfoundry.org/cli/command/commandfakes" - "code.cloudfoundry.org/cli/command/v7" + v7 "code.cloudfoundry.org/cli/command/v7" "code.cloudfoundry.org/cli/command/v7/v7fakes" "code.cloudfoundry.org/cli/util/configv3" "code.cloudfoundry.org/cli/util/ui" diff --git a/command/v7/unshare_route_command.go b/command/v7/unshare_route_command.go index c25934b9746..982da124f53 100644 --- a/command/v7/unshare_route_command.go +++ b/command/v7/unshare_route_command.go @@ -64,6 +64,7 @@ func (cmd UnshareRouteCommand) Execute(args []string) error { } destinationOrg, warnings, err := cmd.Actor.GetOrganizationByName(destinationOrgName) + cmd.UI.DisplayWarnings(warnings) if err != nil { if _, ok := err.(actionerror.OrganizationNotFoundError); ok { @@ -73,6 +74,7 @@ func (cmd UnshareRouteCommand) Execute(args []string) error { } targetedSpace, warnings, err := cmd.Actor.GetSpaceByNameAndOrganization(cmd.DestinationSpace, destinationOrg.GUID) + cmd.UI.DisplayWarnings(warnings) if err != nil { if _, ok := err.(actionerror.SpaceNotFoundError); ok { cmd.UI.DisplayText("Can not unshare route:") diff --git a/command/v7/unshare_service_command_test.go b/command/v7/unshare_service_command_test.go index 0b814c1523f..f1c96855132 100644 --- a/command/v7/unshare_service_command_test.go +++ b/command/v7/unshare_service_command_test.go @@ -219,7 +219,7 @@ var _ = Describe("unshare-service command", func() { When("getting the username fails", func() { BeforeEach(func() { - input.Write([]byte("y\n")) + Expect(input.Write([]byte("y\n"))).To(Succeed()) fakeActor.GetCurrentUserReturns(configv3.User{}, errors.New("boom")) }) diff --git a/command/v7/update_buildpack_command.go b/command/v7/update_buildpack_command.go index b0e40dee66b..8b71321d87d 100644 --- a/command/v7/update_buildpack_command.go +++ b/command/v7/update_buildpack_command.go @@ -1,7 +1,6 @@ package v7 import ( - "io/ioutil" "os" "time" @@ -96,7 +95,7 @@ func (cmd UpdateBuildpackCommand) validateSetup() (configv3.User, error) { func (cmd UpdateBuildpackCommand) prepareBuildpackBits() (string, string, error) { downloader := download.NewDownloader(time.Second * 30) - tmpDirPath, err := ioutil.TempDir("", "buildpack-dir-") + tmpDirPath, err := os.MkdirTemp("", "buildpack-dir-") if err != nil { return "", "", err } diff --git a/command/v7/update_service_broker_command.go b/command/v7/update_service_broker_command.go index 7c236dadf31..cc1feb1d06d 100644 --- a/command/v7/update_service_broker_command.go +++ b/command/v7/update_service_broker_command.go @@ -12,7 +12,6 @@ type UpdateServiceBrokerCommand struct { PositionalArgs flag.ServiceBrokerArgs `positional-args:"yes"` usage any `usage:"CF_NAME update-service-broker SERVICE_BROKER USERNAME PASSWORD URL\n CF_NAME update-service-broker SERVICE_BROKER USERNAME URL (omit password to specify interactively or via environment variable)\n\nWARNING:\n Providing your password as a command line option is highly discouraged\n Your password may be visible to others and may be recorded in your shell history"` relatedCommands any `related_commands:"rename-service-broker, service-brokers"` - envPassword any `environmentName:"CF_BROKER_PASSWORD" environmentDescription:"Password associated with user. Overridden if PASSWORD argument is provided" environmentDefault:"password"` } func (cmd UpdateServiceBrokerCommand) Execute(args []string) error { diff --git a/command/v7/v7_suite_test.go b/command/v7/v7_suite_test.go index 58e5cf35736..0095f28f9a1 100644 --- a/command/v7/v7_suite_test.go +++ b/command/v7/v7_suite_test.go @@ -4,13 +4,12 @@ import ( "fmt" "reflect" "strings" + "testing" uuid "github.com/nu7hatch/gouuid" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" log "github.com/sirupsen/logrus" - - "testing" ) func TestV3(t *testing.T) { diff --git a/go.mod b/go.mod index d1d75be7b20..dcbd75f417d 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/cloudfoundry/bosh-cli v6.4.1+incompatible github.com/creack/pty v1.1.21 github.com/cyphar/filepath-securejoin v0.2.5 - github.com/docker/distribution v2.8.3+incompatible + github.com/distribution/reference v0.5.0 github.com/fatih/color v1.17.0 github.com/google/go-querystring v1.1.0 github.com/jessevdk/go-flags v1.5.0 @@ -41,6 +41,7 @@ require ( github.com/vito/go-interact v0.0.0-20171111012221-fa338ed9e9ec golang.org/x/crypto v0.23.0 golang.org/x/net v0.25.0 + golang.org/x/term v0.20.0 golang.org/x/text v0.15.0 gopkg.in/cheggaaa/pb.v1 v1.0.28 gopkg.in/yaml.v2 v2.4.0 @@ -57,7 +58,6 @@ require ( github.com/cloudfoundry/bosh-utils v0.0.385 // indirect github.com/cppforlife/go-patch v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/distribution/reference v0.5.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect @@ -81,7 +81,6 @@ require ( golang.org/x/oauth2 v0.17.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.20.0 // indirect - golang.org/x/term v0.20.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.20.0 // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/go.sum b/go.sum index 0072ac75e3a..8dfaf5cae0c 100644 --- a/go.sum +++ b/go.sum @@ -65,8 +65,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= -github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= -github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/drewolson/testflight v1.0.0/go.mod h1:t9oKuuEohRGLb80SWX+uxJHuhX98B7HnojqtW+Ryq30= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/i18n/resources/i18n_resources.go b/i18n/resources/i18n_resources.go index ac21975801a..0abbe9999de 100644 --- a/i18n/resources/i18n_resources.go +++ b/i18n/resources/i18n_resources.go @@ -345,11 +345,13 @@ var _bindata = map[string]func() (*asset, error){ // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png +// +// data/ +// foo.txt +// img/ +// a.png +// b.png +// // then AssetDir("data") would return []string{"foo.txt", "img"} // AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("foo.txt") and AssetDir("notexist") would return an error diff --git a/integration/assets/go_calls_ruby/Godeps/Godeps.json b/integration/assets/go_calls_ruby/Godeps/Godeps.json index bc04af789ec..bf330213be7 100644 --- a/integration/assets/go_calls_ruby/Godeps/Godeps.json +++ b/integration/assets/go_calls_ruby/Godeps/Godeps.json @@ -1,6 +1,6 @@ { - "ImportPath": "github.com/cloudfoundry/cf-acceptance-tests/assets/go_calls_ruby", - "GoVersion": "go1.*", - "GodepVersion": "v79", - "Deps": [] + "ImportPath": "github.com/cloudfoundry/cf-acceptance-tests/assets/go_calls_ruby", + "GoVersion": "go1.*", + "GodepVersion": "v79", + "Deps": [] } diff --git a/integration/assets/hydrabroker/integrationtest/integrationtest_test.go b/integration/assets/hydrabroker/integrationtest/integrationtest_test.go index 2da29948bb4..a71bbbcc8a8 100644 --- a/integration/assets/hydrabroker/integrationtest/integrationtest_test.go +++ b/integration/assets/hydrabroker/integrationtest/integrationtest_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -57,7 +56,7 @@ var _ = Describe("Integration Test For Hydrabroker", func() { Expect(err).NotTo(HaveOccurred()) expectStatusCode(response, http.StatusBadRequest) - b, err := ioutil.ReadAll(response.Body) + b, err := io.ReadAll(response.Body) Expect(err).NotTo(HaveOccurred()) Expect(string(b)).To(ContainSubstring("Error:Field validation for 'Username' failed on the 'min' tag")) }) @@ -617,7 +616,7 @@ var _ = Describe("Integration Test For Hydrabroker", func() { func expectStatusCode(response *http.Response, statusCode int) { ExpectWithOffset(1, response.StatusCode).To(Equal(statusCode), func() string { - b, err := ioutil.ReadAll(response.Body) + b, err := io.ReadAll(response.Body) if err == nil { response.Body.Close() return "Body: " + string(b) @@ -670,7 +669,7 @@ func toJSON(input interface{}) io.Reader { } func fromJSON(input io.ReadCloser, output interface{}) { - b, err := ioutil.ReadAll(input) + b, err := io.ReadAll(input) Expect(err).NotTo(HaveOccurred()) err = input.Close() diff --git a/integration/helpers/app.go b/integration/helpers/app.go index 14314c7679c..1943ddbacc8 100644 --- a/integration/helpers/app.go +++ b/integration/helpers/app.go @@ -4,7 +4,6 @@ import ( "archive/zip" "fmt" "io" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -40,10 +39,10 @@ func WithHelloWorldApp(f func(dir string)) { defer os.RemoveAll(dir) tempfile := filepath.Join(dir, "index.html") - err := ioutil.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %d", rand.Int())), 0666) + err := os.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %d", rand.Int())), 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) + err = os.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) Expect(err).ToNot(HaveOccurred()) f(dir) @@ -57,18 +56,18 @@ func WithMultiEndpointApp(f func(dir string)) { defer os.RemoveAll(dir) tempfile := filepath.Join(dir, "index.html") - err := ioutil.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %d", rand.Int())), 0666) + err := os.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %d", rand.Int())), 0666) Expect(err).ToNot(HaveOccurred()) tempfile = filepath.Join(dir, "other_endpoint.html") - err = ioutil.WriteFile(tempfile, []byte("other endpoint"), 0666) + err = os.WriteFile(tempfile, []byte("other endpoint"), 0666) Expect(err).ToNot(HaveOccurred()) tempfile = filepath.Join(dir, "third_endpoint.html") - err = ioutil.WriteFile(tempfile, []byte("third endpoint"), 0666) + err = os.WriteFile(tempfile, []byte("third endpoint"), 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) + err = os.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) Expect(err).ToNot(HaveOccurred()) f(dir) @@ -76,7 +75,7 @@ func WithMultiEndpointApp(f func(dir string)) { func WithSidecarApp(f func(dir string), appName string) { withSidecarManifest := func(dir string) { - err := ioutil.WriteFile(filepath.Join(dir, "manifest.yml"), []byte(fmt.Sprintf(`--- + err := os.WriteFile(filepath.Join(dir, "manifest.yml"), []byte(fmt.Sprintf(`--- applications: - name: %s sidecars: @@ -94,7 +93,7 @@ applications: func WithTaskApp(f func(dir string), appName string) { withTaskManifest := func(dir string) { - err := ioutil.WriteFile(filepath.Join(dir, "manifest.yml"), []byte(fmt.Sprintf(`--- + err := os.WriteFile(filepath.Join(dir, "manifest.yml"), []byte(fmt.Sprintf(`--- applications: - name: %s processes: @@ -119,7 +118,7 @@ func WithNoResourceMatchedApp(f func(dir string)) { tempfile := filepath.Join(dir, "index.html") - err := ioutil.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %s", strings.Repeat("a", 65*1024))), 0666) + err := os.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %s", strings.Repeat("a", 65*1024))), 0666) Expect(err).ToNot(HaveOccurred()) f(dir) @@ -136,7 +135,7 @@ func WithProcfileApp(f func(dir string)) { dir := TempDirAbsolutePath("", "simple-ruby-app") defer os.RemoveAll(dir) - err := ioutil.WriteFile(filepath.Join(dir, "Procfile"), []byte(`--- + err := os.WriteFile(filepath.Join(dir, "Procfile"), []byte(`--- web: ruby -run -e httpd . -p $PORT console: bundle exec irb`, ), 0666) @@ -144,14 +143,14 @@ console: bundle exec irb`, //TODO: Remove the ruby version once bundler issue(https://github.com/rubygems/rubygems/issues/6280) // is solved - err = ioutil.WriteFile(filepath.Join(dir, "Gemfile"), []byte(`source 'http://rubygems.org' + err = os.WriteFile(filepath.Join(dir, "Gemfile"), []byte(`source 'http://rubygems.org' ruby '~> 3.0' gem 'irb' gem 'webrick'`, ), 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "Gemfile.lock"), []byte(` + err = os.WriteFile(filepath.Join(dir, "Gemfile.lock"), []byte(` GEM remote: http://rubygems.org/ specs: @@ -181,15 +180,15 @@ func WithCrashingApp(f func(dir string)) { dir := TempDirAbsolutePath("", "crashing-ruby-app") defer os.RemoveAll(dir) - err := ioutil.WriteFile(filepath.Join(dir, "Procfile"), []byte(`--- + err := os.WriteFile(filepath.Join(dir, "Procfile"), []byte(`--- web: bogus bogus`, ), 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "Gemfile"), nil, 0666) + err = os.WriteFile(filepath.Join(dir, "Gemfile"), nil, 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "Gemfile.lock"), []byte(` + err = os.WriteFile(filepath.Join(dir, "Gemfile.lock"), []byte(` GEM specs: @@ -215,10 +214,10 @@ func WithBananaPantsApp(f func(dir string)) { defer os.RemoveAll(dir) tempfile := filepath.Join(dir, "index.html") - err := ioutil.WriteFile(tempfile, []byte("Banana Pants"), 0666) + err := os.WriteFile(tempfile, []byte("Banana Pants"), 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) + err = os.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) Expect(err).ToNot(HaveOccurred()) f(dir) @@ -229,10 +228,10 @@ func WithEmptyFilesApp(f func(dir string)) { defer os.RemoveAll(dir) tempfile := filepath.Join(dir, "index.html") - err := ioutil.WriteFile(tempfile, nil, 0666) + err := os.WriteFile(tempfile, nil, 0666) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) + err = os.WriteFile(filepath.Join(dir, "Staticfile"), nil, 0666) Expect(err).ToNot(HaveOccurred()) f(dir) @@ -257,12 +256,12 @@ func AppJSON(appName string) string { func WriteManifest(path string, manifest map[string]interface{}) { body, err := yaml.Marshal(manifest) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(path, body, 0666) + err = os.WriteFile(path, body, 0666) Expect(err).ToNot(HaveOccurred()) } func ReadManifest(path string) map[string]interface{} { - manifestBytes, err := ioutil.ReadFile(path) + manifestBytes, err := os.ReadFile(path) Expect(err).ToNot(HaveOccurred()) var manifest map[string]interface{} err = yaml.Unmarshal(manifestBytes, &manifest) diff --git a/integration/helpers/buildpack.go b/integration/helpers/buildpack.go index e6f023b75b0..0540c92cfe0 100644 --- a/integration/helpers/buildpack.go +++ b/integration/helpers/buildpack.go @@ -3,7 +3,6 @@ package helpers import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" @@ -14,7 +13,7 @@ import ( // MakeBuildpackArchive makes a simple buildpack zip for a given stack. func MakeBuildpackArchive(stackName string) string { - archiveFile, err := ioutil.TempFile("", "buildpack-archive-file-") + archiveFile, err := os.CreateTemp("", "buildpack-archive-file-") Expect(err).ToNot(HaveOccurred()) err = archiveFile.Close() Expect(err).ToNot(HaveOccurred()) @@ -23,12 +22,12 @@ func MakeBuildpackArchive(stackName string) string { archiveName := archiveFile.Name() + ".zip" - dir, err := ioutil.TempDir("", "buildpack-dir-") + dir, err := os.MkdirTemp("", "buildpack-dir-") Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(dir) manifest := filepath.Join(dir, "manifest.yml") - err = ioutil.WriteFile(manifest, []byte(fmt.Sprintf("stack: %s", stackName)), 0666) + err = os.WriteFile(manifest, []byte(fmt.Sprintf("stack: %s", stackName)), 0666) Expect(err).ToNot(HaveOccurred()) err = Zipit(dir, archiveName, "") diff --git a/integration/helpers/config.go b/integration/helpers/config.go index b830dfa10f6..a7d63dcc781 100644 --- a/integration/helpers/config.go +++ b/integration/helpers/config.go @@ -2,7 +2,6 @@ package helpers import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -31,7 +30,7 @@ func TurnOffExperimental() { // the created directory through GinkgoWriter. func SetHomeDir() string { var err error - homeDir, err := ioutil.TempDir("", "cli-integration-test") + homeDir, err := os.MkdirTemp("", "cli-integration-test") Expect(err).NotTo(HaveOccurred()) setHomeDirsTo(homeDir, homeDir) @@ -102,7 +101,7 @@ func SetConfig(cb func(conf *configv3.Config)) { func SetConfigContent(dir string, rawConfig string) { err := os.MkdirAll(filepath.Join(dir), 0777) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(dir, "config.json"), []byte(rawConfig), 0644) + err = os.WriteFile(filepath.Join(dir, "config.json"), []byte(rawConfig), 0644) Expect(err).ToNot(HaveOccurred()) } diff --git a/integration/helpers/fake_data.go b/integration/helpers/fake_data.go index 88e378a765e..a8ded756457 100644 --- a/integration/helpers/fake_data.go +++ b/integration/helpers/fake_data.go @@ -3,9 +3,10 @@ package helpers import ( "embed" "fmt" + "net/http" + . "github.com/onsi/gomega" "github.com/onsi/gomega/ghttp" - "net/http" ) //go:embed fixtures diff --git a/integration/helpers/file.go b/integration/helpers/file.go index 769c717f322..fe5b49a0ee3 100644 --- a/integration/helpers/file.go +++ b/integration/helpers/file.go @@ -1,7 +1,6 @@ package helpers import ( - "io/ioutil" "os" "path/filepath" "strings" @@ -18,7 +17,7 @@ func ConvertPathToRegularExpression(path string) string { // TempFileWithContent writes a temp file with given content and return the // file name. func TempFileWithContent(contents string) string { - tempFile, err := ioutil.TempFile("", "*") + tempFile, err := os.CreateTemp("", "*") Expect(err).NotTo(HaveOccurred()) defer tempFile.Close() @@ -29,10 +28,10 @@ func TempFileWithContent(contents string) string { return tempFile.Name() } -// TempDirAbsolutePath wraps `ioutil.TempDir`, ensuring symlinks are expanded +// TempDirAbsolutePath wraps `os.MkdirTemp`, ensuring symlinks are expanded // before returning the path func TempDirAbsolutePath(dir string, prefix string) string { - tempDir, err := ioutil.TempDir(dir, prefix) + tempDir, err := os.MkdirTemp(dir, prefix) Expect(err).NotTo(HaveOccurred()) tempDir, err = filepath.EvalSymlinks(tempDir) @@ -41,7 +40,7 @@ func TempDirAbsolutePath(dir string, prefix string) string { return tempDir } -// TempFileAbsolutePath wraps `ioutil.TempFile`, ensuring symlinks are expanded +// TempFileAbsolutePath wraps `os.CreateTemp`, ensuring symlinks are expanded // before returning the path func TempFileAbsolutePath(dir string, pattern string) *os.File { var ( @@ -56,7 +55,7 @@ func TempFileAbsolutePath(dir string, pattern string) *os.File { absoluteDir, err = filepath.EvalSymlinks(dir) Expect(err).NotTo(HaveOccurred()) } - tempFile, err := ioutil.TempFile(absoluteDir, pattern) + tempFile, err := os.CreateTemp(absoluteDir, pattern) Expect(err).NotTo(HaveOccurred()) return tempFile diff --git a/integration/helpers/package.go b/integration/helpers/package.go index 305b87961b9..8a9b6a72ee7 100644 --- a/integration/helpers/package.go +++ b/integration/helpers/package.go @@ -2,7 +2,6 @@ package helpers import ( "fmt" - "io/ioutil" "os" "regexp" @@ -15,7 +14,7 @@ import ( // VerifyAppPackageContentsV3 verifies the contents of a V3 app package by downloading the package zip and // verifying the zipped files match the passed files. func VerifyAppPackageContentsV3(appName string, files ...string) { - tmpZipFilepath, err := ioutil.TempFile("", "") + tmpZipFilepath, err := os.CreateTemp("", "") defer os.Remove(tmpZipFilepath.Name()) Expect(err).ToNot(HaveOccurred()) @@ -60,7 +59,7 @@ func downloadFirstAppPackage(appName string, tmpZipFilepath string) { // VerifyAppPackageContentsV2 verifies the contents of a V2 app package by downloading the package zip and // verifying the zipped files match the passed files. func VerifyAppPackageContentsV2(appName string, files ...string) { - tmpZipFilepath, err := ioutil.TempFile("", "") + tmpZipFilepath, err := os.CreateTemp("", "") defer os.Remove(tmpZipFilepath.Name()) Expect(err).ToNot(HaveOccurred()) diff --git a/integration/helpers/plugin_repo.go b/integration/helpers/plugin_repo.go index 57d1fdab057..105d77e4c52 100644 --- a/integration/helpers/plugin_repo.go +++ b/integration/helpers/plugin_repo.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "log" "net/http" "os" @@ -104,7 +103,7 @@ func (pluginRepoServer *PluginRepositoryServerWithPlugin) Init(pluginType string jsonBytes, err := json.Marshal(pluginRepo) Expect(err).ToNot(HaveOccurred()) - pluginData, err := ioutil.ReadFile(pluginPath) + pluginData, err := os.ReadFile(pluginPath) Expect(err).ToNot(HaveOccurred()) repoServer.AppendHandlers( diff --git a/integration/helpers/security_group.go b/integration/helpers/security_group.go index 893f5239677..3e6dc0903a4 100644 --- a/integration/helpers/security_group.go +++ b/integration/helpers/security_group.go @@ -3,7 +3,6 @@ package helpers import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" @@ -27,7 +26,7 @@ func NewSecurityGroup(name string, protocol string, destination string, ports *s // CreateSecurityGroup Creates a new security group on the API using the 'cf create-security-group' func CreateSecurityGroup(s resources.SecurityGroup) { - dir, err := ioutil.TempDir("", "simple-security-group") + dir, err := os.MkdirTemp("", "simple-security-group") Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(dir) @@ -36,7 +35,7 @@ func CreateSecurityGroup(s resources.SecurityGroup) { securityGroup, err := json.Marshal(s.Rules) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(tempfile, securityGroup, 0666) + err = os.WriteFile(tempfile, securityGroup, 0666) Expect(err).ToNot(HaveOccurred()) Eventually(CF("create-security-group", s.Name, tempfile)).Should(Exit(0)) } diff --git a/integration/helpers/servicebrokerstub/app_config.go b/integration/helpers/servicebrokerstub/app_config.go index 6b5be604565..c4f3911188a 100644 --- a/integration/helpers/servicebrokerstub/app_config.go +++ b/integration/helpers/servicebrokerstub/app_config.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "code.cloudfoundry.org/cli/integration/assets/hydrabroker/config" @@ -55,7 +54,7 @@ func (s *ServiceBrokerStub) requestNewBrokerRoute() { resp, err := http.DefaultClient.Do(req) Expect(err).ToNot(HaveOccurred()) - responseBody, err := ioutil.ReadAll(resp.Body) + responseBody, err := io.ReadAll(resp.Body) Expect(err).ToNot(HaveOccurred()) Expect(resp.StatusCode).To( Equal(http.StatusCreated), diff --git a/integration/helpers/set_env_command.go b/integration/helpers/set_env_command.go index 23c624cb220..83514ae9ba0 100644 --- a/integration/helpers/set_env_command.go +++ b/integration/helpers/set_env_command.go @@ -2,6 +2,8 @@ package helpers import ( "encoding/json" + + . "github.com/onsi/gomega" ) func GetsDefaultEnvVarValue(stream []byte) string { @@ -11,7 +13,7 @@ func GetsDefaultEnvVarValue(stream []byte) string { } `json:"var"` }{} - json.Unmarshal(stream, &envVariableJSON) + Expect(json.Unmarshal(stream, &envVariableJSON)).To(Succeed()) return envVariableJSON.Var.SomeEnvVar } diff --git a/integration/helpers/ssh_command.go b/integration/helpers/ssh_command.go index df9bda85d90..560f7051cde 100644 --- a/integration/helpers/ssh_command.go +++ b/integration/helpers/ssh_command.go @@ -2,6 +2,8 @@ package helpers import ( "encoding/json" + + . "github.com/onsi/gomega" ) func GetsEnablementValue(stream []byte) bool { @@ -9,7 +11,7 @@ func GetsEnablementValue(stream []byte) bool { Enabled bool `json:"enabled"` }{} - json.Unmarshal(stream, &enablementResponse) + Expect(json.Unmarshal(stream, &enablementResponse)).To(Succeed()) return enablementResponse.Enabled } diff --git a/integration/helpers/stack.go b/integration/helpers/stack.go index bc148e6c2aa..34fa24439bc 100644 --- a/integration/helpers/stack.go +++ b/integration/helpers/stack.go @@ -2,7 +2,6 @@ package helpers import ( "encoding/json" - "fmt" "strings" diff --git a/integration/helpers/version.go b/integration/helpers/version.go index 1546cfea686..d299b000f75 100644 --- a/integration/helpers/version.go +++ b/integration/helpers/version.go @@ -4,7 +4,7 @@ import ( "crypto/tls" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "strconv" @@ -56,7 +56,7 @@ func IsUAAVersionAtLeast(minVersion string) bool { defer resp.Body.Close() if resp.StatusCode == http.StatusOK { - bodyBytes, err2 := ioutil.ReadAll(resp.Body) + bodyBytes, err2 := io.ReadAll(resp.Body) Expect(err2).ToNot(HaveOccurred()) version := &UAAVersion{} diff --git a/integration/shared/global/global_suite_test.go b/integration/shared/global/global_suite_test.go index 487d0db8e43..d049a732d40 100644 --- a/integration/shared/global/global_suite_test.go +++ b/integration/shared/global/global_suite_test.go @@ -2,14 +2,13 @@ package global import ( "fmt" + "testing" "time" "code.cloudfoundry.org/cli/integration/helpers" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) const ( diff --git a/integration/shared/isolated/config_test.go b/integration/shared/isolated/config_test.go index f8dc92da996..5da2d52ed19 100644 --- a/integration/shared/isolated/config_test.go +++ b/integration/shared/isolated/config_test.go @@ -1,7 +1,7 @@ package isolated import ( - "io/ioutil" + "os" "path/filepath" helpers "code.cloudfoundry.org/cli/integration/helpers" @@ -40,7 +40,7 @@ var _ = Describe("Config", func() { When("lingering tmp files exist from previous failed attempts to write the config", func() { BeforeEach(func() { for i := 0; i < 3; i++ { - tmpFile, err := ioutil.TempFile(configDir, "temp-config") + tmpFile, err := os.CreateTemp(configDir, "temp-config") Expect(err).ToNot(HaveOccurred()) tmpFile.Close() } diff --git a/integration/shared/plugin/install_plugin_command_test.go b/integration/shared/plugin/install_plugin_command_test.go index 52ad2b261e7..db0da47d6c0 100644 --- a/integration/shared/plugin/install_plugin_command_test.go +++ b/integration/shared/plugin/install_plugin_command_test.go @@ -3,7 +3,6 @@ package plugin import ( "bytes" "fmt" - "io/ioutil" "log" "net/http" "os" @@ -25,7 +24,7 @@ var _ = Describe("install-plugin command", func() { ) AfterEach(func() { - pluginsHomeDirContents, err := ioutil.ReadDir(filepath.Join(homeDir, ".cf", "plugins")) + pluginsHomeDirContents, err := os.ReadDir(filepath.Join(homeDir, ".cf", "plugins")) if os.IsNotExist(err) { return } @@ -88,7 +87,7 @@ var _ = Describe("install-plugin command", func() { cfPluginHome = os.Getenv("CF_PLUGIN_HOME") var err error - newPluginHome, err = ioutil.TempDir("", "plugin-temp-dir") + newPluginHome, err = os.MkdirTemp("", "plugin-temp-dir") Expect(err).ToNot(HaveOccurred()) Expect(os.RemoveAll(newPluginHome)) @@ -231,7 +230,7 @@ var _ = Describe("install-plugin command", func() { When("the file is not an executable", func() { BeforeEach(func() { - badPlugin, err := ioutil.TempFile("", "") + badPlugin, err := os.CreateTemp("", "") Expect(err).ToNot(HaveOccurred()) pluginPath = badPlugin.Name() err = badPlugin.Close() @@ -662,7 +661,7 @@ var _ = Describe("install-plugin command", func() { ) var err error - pluginData, err = ioutil.ReadFile(pluginPath) + pluginData, err = os.ReadFile(pluginPath) Expect(err).ToNot(HaveOccurred()) server.AppendHandlers( CombineHandlers( @@ -771,7 +770,7 @@ var _ = Describe("install-plugin command", func() { pluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/non_plugin") Expect(err).ToNot(HaveOccurred()) - pluginData, err := ioutil.ReadFile(pluginPath) + pluginData, err := os.ReadFile(pluginPath) Expect(err).ToNot(HaveOccurred()) server.AppendHandlers( CombineHandlers( @@ -811,7 +810,7 @@ var _ = Describe("install-plugin command", func() { ) var err error - pluginData, err = ioutil.ReadFile(pluginPath) + pluginData, err = os.ReadFile(pluginPath) Expect(err).ToNot(HaveOccurred()) server.AppendHandlers( CombineHandlers( diff --git a/integration/v7/global/create_buildpack_command_test.go b/integration/v7/global/create_buildpack_command_test.go index f697e58bf03..474dab02cfd 100644 --- a/integration/v7/global/create_buildpack_command_test.go +++ b/integration/v7/global/create_buildpack_command_test.go @@ -2,7 +2,6 @@ package global import ( "bytes" - "io/ioutil" "log" "net/http" "os" @@ -84,9 +83,9 @@ var _ = Describe("create buildpack command", func() { When("zipping the directory succeeds", func() { BeforeEach(func() { var err error - buildpackDir, err = ioutil.TempDir("", "buildpackdir-") + buildpackDir, err = os.MkdirTemp("", "buildpackdir-") Expect(err).ToNot(HaveOccurred()) - file, err := ioutil.TempFile(buildpackDir, "myfile-") + file, err := os.CreateTemp(buildpackDir, "myfile-") Expect(err).ToNot(HaveOccurred()) defer file.Close() }) @@ -104,7 +103,7 @@ var _ = Describe("create buildpack command", func() { When("the specified directory is empty", func() { BeforeEach(func() { var err error - buildpackDir, err = ioutil.TempDir("", "empty-") + buildpackDir, err = os.MkdirTemp("", "empty-") Expect(err).ToNot(HaveOccurred()) }) diff --git a/integration/v7/global/create_security_group_command_test.go b/integration/v7/global/create_security_group_command_test.go index e0ff1afed9b..d701ce2a853 100644 --- a/integration/v7/global/create_security_group_command_test.go +++ b/integration/v7/global/create_security_group_command_test.go @@ -1,7 +1,6 @@ package global import ( - "io/ioutil" "os" "path/filepath" "strings" @@ -28,7 +27,7 @@ var _ = Describe("create-security-group command", func() { dir = helpers.TempDirAbsolutePath("", "security-group") tempPath = filepath.Join(dir, "tmpfile.json") - err := ioutil.WriteFile(tempPath, []byte(`[{ + err := os.WriteFile(tempPath, []byte(`[{ "protocol": "tcp", "destination": "10.0.11.0/24", "ports": "80,443", @@ -105,7 +104,7 @@ var _ = Describe("create-security-group command", func() { When("the security group path has invalid JSON", func() { BeforeEach(func() { - err := ioutil.WriteFile(tempPath, []byte("Invalid JSON!"), 0666) + err := os.WriteFile(tempPath, []byte("Invalid JSON!"), 0666) Expect(err).ToNot(HaveOccurred()) }) diff --git a/integration/v7/global/global_suite_test.go b/integration/v7/global/global_suite_test.go index 487d0db8e43..d049a732d40 100644 --- a/integration/v7/global/global_suite_test.go +++ b/integration/v7/global/global_suite_test.go @@ -2,14 +2,13 @@ package global import ( "fmt" + "testing" "time" "code.cloudfoundry.org/cli/integration/helpers" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) const ( diff --git a/integration/v7/global/update_buildpack_command_test.go b/integration/v7/global/update_buildpack_command_test.go index 7780ca36b0e..789473d2043 100644 --- a/integration/v7/global/update_buildpack_command_test.go +++ b/integration/v7/global/update_buildpack_command_test.go @@ -2,7 +2,6 @@ package global import ( "bytes" - "io/ioutil" "log" "net/http" "os" @@ -293,7 +292,7 @@ var _ = Describe("update-buildpack command", func() { When("the buildpack path is an empty directory", func() { BeforeEach(func() { var err error - buildpackPath, err = ioutil.TempDir("", "create-buildpack-test-") + buildpackPath, err = os.MkdirTemp("", "create-buildpack-test-") Expect(err).ToNot(HaveOccurred()) }) @@ -312,9 +311,9 @@ var _ = Describe("update-buildpack command", func() { When("the path is a buildpack directory", func() { BeforeEach(func() { var err error - buildpackPath, err = ioutil.TempDir("", "create-buildpack-test-") + buildpackPath, err = os.MkdirTemp("", "create-buildpack-test-") Expect(err).ToNot(HaveOccurred()) - file, err := ioutil.TempFile(buildpackPath, "") + file, err := os.CreateTemp(buildpackPath, "") Expect(err).ToNot(HaveOccurred()) defer file.Close() }) diff --git a/integration/v7/global/update_security_group_command_test.go b/integration/v7/global/update_security_group_command_test.go index 44c2fc94a6b..5f86b6710f5 100644 --- a/integration/v7/global/update_security_group_command_test.go +++ b/integration/v7/global/update_security_group_command_test.go @@ -2,7 +2,6 @@ package global import ( "encoding/json" - "io/ioutil" "os" "path/filepath" @@ -56,7 +55,7 @@ var _ = Describe("update-security-group command", func() { }, } - tmpRulesDir, err = ioutil.TempDir("", "spam-security-group") + tmpRulesDir, err = os.MkdirTemp("", "spam-security-group") Expect(err).ToNot(HaveOccurred()) updatedRulesPath = filepath.Join(tmpRulesDir, "spam-security-group.json") @@ -64,7 +63,7 @@ var _ = Describe("update-security-group command", func() { securityGroup, err := json.Marshal(updatedSecurityGroupRules) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(updatedRulesPath, securityGroup, 0666) + err = os.WriteFile(updatedRulesPath, securityGroup, 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -121,7 +120,7 @@ var _ = Describe("update-security-group command", func() { When("the JSON file with the security group's rules is not JSON", func() { BeforeEach(func() { - err = ioutil.WriteFile(updatedRulesPath, []byte("I'm definitely not JSON"), 0666) + err = os.WriteFile(updatedRulesPath, []byte("I'm definitely not JSON"), 0666) Expect(err).ToNot(HaveOccurred()) }) It("displays a an incorrect JSON format message and fails", func() { diff --git a/integration/v7/isolated/api_command_test.go b/integration/v7/isolated/api_command_test.go index 638a7b4ed0a..8496aa903d5 100644 --- a/integration/v7/isolated/api_command_test.go +++ b/integration/v7/isolated/api_command_test.go @@ -2,7 +2,6 @@ package isolated import ( "encoding/json" - "io/ioutil" "net/http" "os" "os/exec" @@ -106,7 +105,7 @@ var _ = Describe("api command", func() { Eventually(session).Should(Say("OK")) Eventually(session).Should(Exit(0)) - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) var configFile configv3.JSONConfig @@ -243,7 +242,7 @@ var _ = Describe("api command", func() { Expect(err).NotTo(HaveOccurred()) Eventually(session).Should(Exit(0)) - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) var configFile configv3.JSONConfig @@ -274,7 +273,7 @@ var _ = Describe("api command", func() { session := helpers.CF("api", apiURL) Eventually(session).Should(Exit(0)) - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) var configFile configv3.JSONConfig @@ -296,7 +295,7 @@ var _ = Describe("api command", func() { Eventually(session).Should(Exit(0)) - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) var configFile configv3.JSONConfig @@ -316,7 +315,7 @@ var _ = Describe("api command", func() { } Eventually(session).Should(Exit(0)) - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) var configFile configv3.JSONConfig diff --git a/integration/v7/isolated/app_command_test.go b/integration/v7/isolated/app_command_test.go index 4f840779acc..a3109ceca54 100644 --- a/integration/v7/isolated/app_command_test.go +++ b/integration/v7/isolated/app_command_test.go @@ -2,10 +2,9 @@ package isolated import ( "fmt" - "io/ioutil" - "path/filepath" - + "os" "path" + "path/filepath" . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" "code.cloudfoundry.org/cli/integration/helpers" @@ -105,7 +104,7 @@ applications: - route: %s.%s `, appName, appName, domainName)) manifestPath := filepath.Join(appDir, "manifest.yml") - err := ioutil.WriteFile(manifestPath, manifestContents, 0666) + err := os.WriteFile(manifestPath, manifestContents, 0666) Expect(err).ToNot(HaveOccurred()) // Create manifest @@ -358,7 +357,7 @@ applications: - route: %s:1024 `, appName, tcpDomain.Name)) manifestPath := filepath.Join(appDir, "manifest.yml") - err := ioutil.WriteFile(manifestPath, manifestContents, 0666) + err := os.WriteFile(manifestPath, manifestContents, 0666) Expect(err).ToNot(HaveOccurred()) // Create manifest diff --git a/integration/v7/isolated/apply_manifest_command_test.go b/integration/v7/isolated/apply_manifest_command_test.go index 2e9db1642f3..82df22e0e7e 100644 --- a/integration/v7/isolated/apply_manifest_command_test.go +++ b/integration/v7/isolated/apply_manifest_command_test.go @@ -2,7 +2,6 @@ package isolated import ( "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -274,7 +273,7 @@ var _ = Describe("apply-manifest command", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ @@ -310,7 +309,7 @@ var _ = Describe("apply-manifest command", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ diff --git a/integration/v7/isolated/auth_command_test.go b/integration/v7/isolated/auth_command_test.go index 4ecc062d165..34d5e967aa8 100644 --- a/integration/v7/isolated/auth_command_test.go +++ b/integration/v7/isolated/auth_command_test.go @@ -2,7 +2,7 @@ package isolated import ( "encoding/json" - "io/ioutil" + "os" "path/filepath" "code.cloudfoundry.org/cli/api/uaa/uaaversion" @@ -234,7 +234,7 @@ var _ = Describe("auth command", func() { session := helpers.CF("auth", clientID, clientSecret, "--client-credentials") Eventually(session).Should(Exit(0)) - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) Expect(string(rawConfig)).ToNot(ContainSubstring(clientSecret)) diff --git a/integration/v7/isolated/copy_source_command_test.go b/integration/v7/isolated/copy_source_command_test.go index cd5660e488b..c44701a6090 100644 --- a/integration/v7/isolated/copy_source_command_test.go +++ b/integration/v7/isolated/copy_source_command_test.go @@ -2,7 +2,7 @@ package isolated import ( "fmt" - "io/ioutil" + "io" "net/http" . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" @@ -73,7 +73,7 @@ var _ = Describe("copy-source command", func() { resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(body)).To(MatchRegexp("hello world")) }) @@ -147,7 +147,7 @@ var _ = Describe("copy-source command", func() { resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(body)).To(MatchRegexp("hello world")) }) @@ -194,7 +194,7 @@ var _ = Describe("copy-source command", func() { resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(body)).To(MatchRegexp("hello world")) }) @@ -312,7 +312,7 @@ var _ = Describe("copy-source command", func() { resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(body)).To(MatchRegexp("hello world")) }) @@ -353,7 +353,7 @@ var _ = Describe("copy-source command", func() { resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(body)).To(MatchRegexp("hello world")) }) @@ -394,7 +394,7 @@ var _ = Describe("copy-source command", func() { resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(body)).To(MatchRegexp("hello world")) }) diff --git a/integration/v7/isolated/create_app_manifest_command_test.go b/integration/v7/isolated/create_app_manifest_command_test.go index 13d86ac5237..9e6be584d7c 100644 --- a/integration/v7/isolated/create_app_manifest_command_test.go +++ b/integration/v7/isolated/create_app_manifest_command_test.go @@ -2,7 +2,6 @@ package isolated import ( "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -118,7 +117,7 @@ var _ = Describe("create-app-manifest command", func() { Eventually(session).Should(Say("OK")) Eventually(session).Should(Exit(0)) - createdFile, err := ioutil.ReadFile(manifestFilePath) + createdFile, err := os.ReadFile(manifestFilePath) Expect(err).ToNot(HaveOccurred()) Expect(createdFile).To(MatchRegexp("---")) Expect(createdFile).To(MatchRegexp("applications:")) @@ -163,7 +162,7 @@ var _ = Describe("create-app-manifest command", func() { Eventually(session).Should(Say("OK")) Eventually(session).Should(Exit(0)) - createdFile, err := ioutil.ReadFile(newFile) + createdFile, err := os.ReadFile(newFile) Expect(err).ToNot(HaveOccurred()) Expect(createdFile).To(MatchRegexp("---")) Expect(createdFile).To(MatchRegexp("applications:")) @@ -188,7 +187,7 @@ var _ = Describe("create-app-manifest command", func() { Eventually(session).Should(Say("OK")) Eventually(session).Should(Exit(0)) - createdFile, err := ioutil.ReadFile(existingFile) + createdFile, err := os.ReadFile(existingFile) Expect(err).ToNot(HaveOccurred()) Expect(createdFile).To(MatchRegexp("---")) Expect(createdFile).To(MatchRegexp("applications:")) diff --git a/integration/v7/isolated/create_package_cfignore_test.go b/integration/v7/isolated/create_package_cfignore_test.go index 9641984ec0b..a1ebe0b89c6 100644 --- a/integration/v7/isolated/create_package_cfignore_test.go +++ b/integration/v7/isolated/create_package_cfignore_test.go @@ -1,7 +1,6 @@ package isolated import ( - "io/ioutil" "os" "path/filepath" @@ -35,43 +34,43 @@ var _ = Describe("create-package with .cfignore", func() { It("pushes all the files except .cfignore and files ignored by default", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, nil, 0666) + err = os.WriteFile(cfIgnoreFilePath, nil, 0666) Expect(err).ToNot(HaveOccurred()) darcsFile := filepath.Join(appDir, "_darcs") - err = ioutil.WriteFile(darcsFile, nil, 0666) + err = os.WriteFile(darcsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) dsFile := filepath.Join(appDir, ".DS_Store") - err = ioutil.WriteFile(dsFile, nil, 0666) + err = os.WriteFile(dsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitFile := filepath.Join(appDir, ".git") - err = ioutil.WriteFile(gitFile, nil, 0666) + err = os.WriteFile(gitFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitIgnoreFile := filepath.Join(appDir, ".gitignore") - err = ioutil.WriteFile(gitIgnoreFile, nil, 0666) + err = os.WriteFile(gitIgnoreFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) hgFile := filepath.Join(appDir, ".hg") - err = ioutil.WriteFile(hgFile, nil, 0666) + err = os.WriteFile(hgFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) manifestFile := filepath.Join(appDir, "manifest.yml") - err = ioutil.WriteFile(manifestFile, nil, 0666) + err = os.WriteFile(manifestFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) svnFile := filepath.Join(appDir, ".svn") - err = ioutil.WriteFile(svnFile, nil, 0666) + err = os.WriteFile(svnFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-app", appName)).Should(Exit(0)) @@ -88,15 +87,15 @@ var _ = Describe("create-package with .cfignore", func() { It("does not push those files", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) Expect(err).ToNot(HaveOccurred()) Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-app", appName)).Should(Exit(0)) @@ -112,15 +111,15 @@ var _ = Describe("create-package with .cfignore", func() { It("does not push those files", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) Expect(err).ToNot(HaveOccurred()) Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-app", appName)).Should(Exit(0)) @@ -137,18 +136,18 @@ var _ = Describe("create-package with .cfignore", func() { BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) Expect(err).ToNot(HaveOccurred()) - tmpfile, err := ioutil.TempFile("", "push-archive-integration") + tmpfile, err := os.CreateTemp("", "push-archive-integration") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()) @@ -183,7 +182,7 @@ var _ = Describe("create-package with .cfignore", func() { It("does not push it", func() { helpers.WithHelloWorldApp(func(appDir string) { traceFilePath := filepath.Join(appDir, "i-am-trace.txt") - err := ioutil.WriteFile(traceFilePath, nil, 0666) + err := os.WriteFile(traceFilePath, nil, 0666) Expect(err).ToNot(HaveOccurred()) previousEnv = os.Getenv("CF_TRACE") @@ -203,39 +202,39 @@ var _ = Describe("create-package with .cfignore", func() { It("pushes all the files except for the files ignored by default", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) darcsFile := filepath.Join(appDir, "_darcs") - err = ioutil.WriteFile(darcsFile, nil, 0666) + err = os.WriteFile(darcsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) dsFile := filepath.Join(appDir, ".DS_Store") - err = ioutil.WriteFile(dsFile, nil, 0666) + err = os.WriteFile(dsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitFile := filepath.Join(appDir, ".git") - err = ioutil.WriteFile(gitFile, nil, 0666) + err = os.WriteFile(gitFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitIgnoreFile := filepath.Join(appDir, ".gitignore") - err = ioutil.WriteFile(gitIgnoreFile, nil, 0666) + err = os.WriteFile(gitIgnoreFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) hgFile := filepath.Join(appDir, ".hg") - err = ioutil.WriteFile(hgFile, nil, 0666) + err = os.WriteFile(hgFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) manifestFile := filepath.Join(appDir, "manifest.yml") - err = ioutil.WriteFile(manifestFile, nil, 0666) + err = os.WriteFile(manifestFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) svnFile := filepath.Join(appDir, ".svn") - err = ioutil.WriteFile(svnFile, nil, 0666) + err = os.WriteFile(svnFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-app", appName)).Should(Exit(0)) diff --git a/integration/v7/isolated/create_package_command_test.go b/integration/v7/isolated/create_package_command_test.go index 9b890cc22cc..3342faceabd 100644 --- a/integration/v7/isolated/create_package_command_test.go +++ b/integration/v7/isolated/create_package_command_test.go @@ -1,7 +1,6 @@ package isolated import ( - "io/ioutil" "os" "regexp" @@ -142,7 +141,7 @@ var _ = Describe("create-package command", func() { BeforeEach(func() { var err error - emptyDir, err = ioutil.TempDir("", "integration-push-path-empty") + emptyDir, err = os.MkdirTemp("", "integration-push-path-empty") Expect(err).ToNot(HaveOccurred()) }) @@ -172,7 +171,7 @@ var _ = Describe("create-package command", func() { BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { - tmpfile, err := ioutil.TempFile("", "package-archive-integration") + tmpfile, err := os.CreateTemp("", "package-archive-integration") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()) @@ -203,7 +202,7 @@ var _ = Describe("create-package command", func() { var symlinkPath string BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "symlink-") + tempFile, err := os.CreateTemp("", "symlink-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).To(Succeed()) @@ -239,7 +238,7 @@ var _ = Describe("create-package command", func() { BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { - tmpfile, err := ioutil.TempFile("", "package-archive-integration") + tmpfile, err := os.CreateTemp("", "package-archive-integration") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()) @@ -248,7 +247,7 @@ var _ = Describe("create-package command", func() { Expect(err).ToNot(HaveOccurred()) }) - tempFile, err := ioutil.TempFile("", "symlink-to-archive-") + tempFile, err := os.CreateTemp("", "symlink-to-archive-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).To(Succeed()) diff --git a/integration/v7/isolated/create_service_command_test.go b/integration/v7/isolated/create_service_command_test.go index e35aa6f28fc..3dc0c32206b 100644 --- a/integration/v7/isolated/create_service_command_test.go +++ b/integration/v7/isolated/create_service_command_test.go @@ -1,7 +1,6 @@ package isolated import ( - "io/ioutil" "os" "path/filepath" "time" @@ -347,7 +346,7 @@ var _ = Describe("create-service command", func() { BeforeEach(func() { var err error - emptyDir, err = ioutil.TempDir("", "") + emptyDir, err = os.MkdirTemp("", "") Expect(err).NotTo(HaveOccurred()) }) diff --git a/integration/v7/isolated/curl_command_test.go b/integration/v7/isolated/curl_command_test.go index d61be0ebedf..701a46d71b5 100644 --- a/integration/v7/isolated/curl_command_test.go +++ b/integration/v7/isolated/curl_command_test.go @@ -2,7 +2,6 @@ package isolated import ( "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -320,7 +319,7 @@ var _ = Describe("curl command", func() { BeforeEach(func() { var err error - dir, err = ioutil.TempDir("", "curl-command") + dir, err = os.MkdirTemp("", "curl-command") Expect(err).ToNot(HaveOccurred()) filePath = filepath.Join(dir, "request_body.json") @@ -328,7 +327,7 @@ var _ = Describe("curl command", func() { spaceName = helpers.NewSpaceName() jsonBody := fmt.Sprintf(`{"name":"%s", "organization_guid":"%s"}`, spaceName, orgGUID) - err = ioutil.WriteFile(filePath, []byte(jsonBody), 0666) + err = os.WriteFile(filePath, []byte(jsonBody), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -385,13 +384,13 @@ var _ = Describe("curl command", func() { When("--output is passed with a file name", func() { It("writes the response headers and body to the file", func() { - outFile, err := ioutil.TempFile("", "output*.json") + outFile, err := os.CreateTemp("", "output*.json") Expect(err).ToNot(HaveOccurred()) session := helpers.CF("curl", "/v2/apps", "-i", "--output", outFile.Name()) Eventually(session).Should(Exit(0)) Eventually(session).Should(Say("OK")) - body, err := ioutil.ReadFile(outFile.Name()) + body, err := os.ReadFile(outFile.Name()) Expect(err).ToNot(HaveOccurred()) contents := string(body) @@ -413,7 +412,7 @@ var _ = Describe("curl command", func() { var tempDir, traceFile, outFile string BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "") + tempDir, err = os.MkdirTemp("", "") Expect(err).ToNot(HaveOccurred()) traceFile = filepath.Join(tempDir, "trace.log") outFile = filepath.Join(tempDir, "output") @@ -427,11 +426,11 @@ var _ = Describe("curl command", func() { session := helpers.CFWithEnv(map[string]string{"CF_TRACE": traceFile}, "curl", "/v2/apps", "--output", outFile) Eventually(session).Should(Exit(0)) - outBytes, err := ioutil.ReadFile(outFile) + outBytes, err := os.ReadFile(outFile) Expect(err).ToNot(HaveOccurred()) Expect(string(outBytes)).To(MatchJSON(expectedJSON)) - traceBytes, err := ioutil.ReadFile(traceFile) + traceBytes, err := os.ReadFile(traceFile) Expect(err).ToNot(HaveOccurred()) Expect(traceBytes).To(ContainSubstring("REQUEST: ")) Expect(traceBytes).To(ContainSubstring("HTTP/1.1 200 OK")) @@ -467,7 +466,7 @@ var _ = Describe("curl command", func() { BeforeEach(func() { var err error - dir, err = ioutil.TempDir("", "curl-command") + dir, err = os.MkdirTemp("", "curl-command") Expect(err).ToNot(HaveOccurred()) filePath = filepath.Join(dir, "request_body.json") @@ -475,7 +474,7 @@ var _ = Describe("curl command", func() { spaceName = helpers.NewSpaceName() jsonBody = fmt.Sprintf(`{"name":"%s", "organization_guid":"%s"}`, spaceName, orgGUID) - err = ioutil.WriteFile(filePath, []byte(jsonBody), 0666) + err = os.WriteFile(filePath, []byte(jsonBody), 0666) Expect(err).ToNot(HaveOccurred()) }) diff --git a/integration/v7/isolated/download_droplet_command_test.go b/integration/v7/isolated/download_droplet_command_test.go index 6a701730c01..8fbe350ea71 100644 --- a/integration/v7/isolated/download_droplet_command_test.go +++ b/integration/v7/isolated/download_droplet_command_test.go @@ -1,7 +1,6 @@ package isolated import ( - "io/ioutil" "os" "path/filepath" "regexp" @@ -129,7 +128,7 @@ var _ = Describe("download-droplet command", func() { When("a path to a directory is provided", func() { BeforeEach(func() { - tmpDir, err := ioutil.TempDir("", "droplets") + tmpDir, err := os.MkdirTemp("", "droplets") Expect(err).NotTo(HaveOccurred()) dropletPath = tmpDir }) @@ -148,7 +147,7 @@ var _ = Describe("download-droplet command", func() { When("a path to a file is provided", func() { BeforeEach(func() { - tmpDir, err := ioutil.TempDir("", "droplets") + tmpDir, err := os.MkdirTemp("", "droplets") Expect(err).NotTo(HaveOccurred()) dropletPath = filepath.Join(tmpDir, "my-droplet.tgz") }) diff --git a/integration/v7/isolated/login_command_test.go b/integration/v7/isolated/login_command_test.go index fb113921e50..34081b40051 100644 --- a/integration/v7/isolated/login_command_test.go +++ b/integration/v7/isolated/login_command_test.go @@ -3,9 +3,9 @@ package isolated import ( "encoding/json" "fmt" - "io/ioutil" "net/http" "net/url" + "os" "path/filepath" "regexp" @@ -114,7 +114,7 @@ var _ = Describe("login command", func() { Eventually(session).Should(Exit(0)) }) It("writes fields to the config file when targeting an API", func() { - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) var configFile configv3.JSONConfig diff --git a/integration/v7/isolated/oauth_client_test.go b/integration/v7/isolated/oauth_client_test.go index ccf182b5a86..9d7e9ee834b 100644 --- a/integration/v7/isolated/oauth_client_test.go +++ b/integration/v7/isolated/oauth_client_test.go @@ -1,7 +1,6 @@ package isolated import ( - "io/ioutil" "os" "path/filepath" "regexp" @@ -15,7 +14,7 @@ import ( ) func fileAsString(path string) string { - configBytes, err := ioutil.ReadFile(path) + configBytes, err := os.ReadFile(path) Expect(err).ToNot(HaveOccurred()) return string(configBytes) @@ -24,7 +23,7 @@ func fileAsString(path string) string { func replaceConfig(path string, old string, new string) { r := regexp.MustCompile(old) newConfig := r.ReplaceAllString(fileAsString(path), new) - err := ioutil.WriteFile(path, []byte(newConfig), 0600) + err := os.WriteFile(path, []byte(newConfig), 0600) Expect(err).ToNot(HaveOccurred()) } diff --git a/integration/v7/isolated/restage_command_test.go b/integration/v7/isolated/restage_command_test.go index 96860b5b2dc..d70a8e11796 100644 --- a/integration/v7/isolated/restage_command_test.go +++ b/integration/v7/isolated/restage_command_test.go @@ -2,7 +2,6 @@ package isolated import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -175,7 +174,7 @@ applications: - route: %s.%s `, appName, appName, domainName)) manifestPath := filepath.Join(appDir, "manifest.yml") - err := ioutil.WriteFile(manifestPath, manifestContents, 0666) + err := os.WriteFile(manifestPath, manifestContents, 0666) Expect(err).ToNot(HaveOccurred()) Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) diff --git a/integration/v7/isolated/rollback_command_test.go b/integration/v7/isolated/rollback_command_test.go index b5523c40741..7410f4d2b42 100644 --- a/integration/v7/isolated/rollback_command_test.go +++ b/integration/v7/isolated/rollback_command_test.go @@ -2,7 +2,7 @@ package isolated import ( "fmt" - "io/ioutil" + "os" "path/filepath" . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" @@ -92,7 +92,7 @@ applications: - route: %s.%s `, appName, appName, domainName)) manifestPath := filepath.Join(appDir, "manifest.yml") - err := ioutil.WriteFile(manifestPath, manifestContents, 0666) + err := os.WriteFile(manifestPath, manifestContents, 0666) Expect(err).ToNot(HaveOccurred()) Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) diff --git a/integration/v7/isolated/start_command_test.go b/integration/v7/isolated/start_command_test.go index f6c5eb8c65d..6a6403c564a 100644 --- a/integration/v7/isolated/start_command_test.go +++ b/integration/v7/isolated/start_command_test.go @@ -2,13 +2,12 @@ package isolated import ( "fmt" + "regexp" "strings" . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" "code.cloudfoundry.org/cli/integration/helpers" - "regexp" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gbytes" diff --git a/integration/v7/isolated/verbose_flag_test.go b/integration/v7/isolated/verbose_flag_test.go index 0201a9cde24..3497177a270 100644 --- a/integration/v7/isolated/verbose_flag_test.go +++ b/integration/v7/isolated/verbose_flag_test.go @@ -1,7 +1,6 @@ package isolated import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -23,7 +22,7 @@ var _ = Describe("Verbose", func() { DescribeTable("displays verbose output to terminal", func(env string, configTrace string, flag bool) { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) @@ -89,7 +88,7 @@ var _ = Describe("Verbose", func() { DescribeTable("displays verbose output to multiple files", func(env string, configTrace string, flag bool, location []string) { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) @@ -127,7 +126,7 @@ var _ = Describe("Verbose", func() { Eventually(session).Should(Exit(1)) for _, filePath := range location { - contents, err := ioutil.ReadFile(tmpDir + filePath) + contents, err := os.ReadFile(tmpDir + filePath) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(MatchRegexp("REQUEST:")) @@ -180,7 +179,7 @@ var _ = Describe("Verbose", func() { DescribeTable("displays verbose output to terminal", func(env string, configTrace string, flag bool) { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) @@ -239,7 +238,7 @@ var _ = Describe("Verbose", func() { DescribeTable("displays verbose output to multiple files", func(env string, configTrace string, location []string) { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) @@ -273,7 +272,7 @@ var _ = Describe("Verbose", func() { Eventually(session).Should(Exit()) for _, filePath := range location { - contents, err := ioutil.ReadFile(tmpDir + filePath) + contents, err := os.ReadFile(tmpDir + filePath) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(MatchRegexp("REQUEST:")) Expect(string(contents)).To(MatchRegexp("RESPONSE:")) @@ -313,7 +312,7 @@ var _ = Describe("Verbose", func() { Describe("uaa", func() { When("the user does not provide the -v flag, the CF_TRACE env var, or the --trace config option", func() { It("should not log requests", func() { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) @@ -332,7 +331,7 @@ var _ = Describe("Verbose", func() { When("the user provides the -v flag", func() { It("should log requests and redact cookies", func() { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) @@ -351,7 +350,7 @@ var _ = Describe("Verbose", func() { Describe("ssh", func() { When("the user is not in verbose mode", func() { It("should not log requests", func() { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) @@ -368,7 +367,7 @@ var _ = Describe("Verbose", func() { When("the user is in verbose mode", func() { It("should redact their one time ssh code", func() { - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") defer os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) diff --git a/integration/v7/push/app_start_timeout_flag_test.go b/integration/v7/push/app_start_timeout_flag_test.go index 32e1f109405..0317157618e 100644 --- a/integration/v7/push/app_start_timeout_flag_test.go +++ b/integration/v7/push/app_start_timeout_flag_test.go @@ -2,7 +2,6 @@ package push import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -23,7 +22,7 @@ var _ = Describe("push with health check timeout flag", func() { BeforeEach(func() { appName = helpers.NewAppName() var err error - tempDir, err = ioutil.TempDir("", "create-manifest") + tempDir, err = os.MkdirTemp("", "create-manifest") Expect(err).ToNot(HaveOccurred()) manifestFilePath = filepath.Join(tempDir, fmt.Sprintf("%s_manifest.yml", appName)) @@ -57,7 +56,7 @@ var _ = Describe("push with health check timeout flag", func() { "create-app-manifest", appName) Eventually(session).Should(Exit(0)) - createdFile, err := ioutil.ReadFile(manifestFilePath) + createdFile, err := os.ReadFile(manifestFilePath) Expect(err).ToNot(HaveOccurred()) Expect(createdFile).To(MatchRegexp("---")) diff --git a/integration/v7/push/cfignore_test.go b/integration/v7/push/cfignore_test.go index 8b31ddef3a9..0e676f96dae 100644 --- a/integration/v7/push/cfignore_test.go +++ b/integration/v7/push/cfignore_test.go @@ -1,7 +1,6 @@ package push import ( - "io/ioutil" "os" "path/filepath" @@ -36,35 +35,35 @@ var _ = Describe("push with .cfignore", func() { It("pushes all the files except .cfignore", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, nil, 0666) + err = os.WriteFile(cfIgnoreFilePath, nil, 0666) Expect(err).ToNot(HaveOccurred()) darcsFile := filepath.Join(appDir, "_darcs") - err = ioutil.WriteFile(darcsFile, nil, 0666) + err = os.WriteFile(darcsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) dsFile := filepath.Join(appDir, ".DS_Store") - err = ioutil.WriteFile(dsFile, nil, 0666) + err = os.WriteFile(dsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitFile := filepath.Join(appDir, ".git") - err = ioutil.WriteFile(gitFile, nil, 0666) + err = os.WriteFile(gitFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitIgnoreFile := filepath.Join(appDir, ".gitignore") - err = ioutil.WriteFile(gitIgnoreFile, nil, 0666) + err = os.WriteFile(gitIgnoreFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) hgFile := filepath.Join(appDir, ".hg") - err = ioutil.WriteFile(hgFile, nil, 0666) + err = os.WriteFile(hgFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) manifestFile := filepath.Join(appDir, "manifest.yml") @@ -78,7 +77,7 @@ var _ = Describe("push with .cfignore", func() { ) svnFile := filepath.Join(appDir, ".svn") - err = ioutil.WriteFile(svnFile, nil, 0666) + err = os.WriteFile(svnFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) @@ -94,15 +93,15 @@ var _ = Describe("push with .cfignore", func() { It("does not push those files", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) @@ -117,15 +116,15 @@ var _ = Describe("push with .cfignore", func() { It("does not push those files", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.CF("push", appName, "-p", appDir) @@ -141,18 +140,18 @@ var _ = Describe("push with .cfignore", func() { BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) Expect(err).ToNot(HaveOccurred()) - tmpfile, err := ioutil.TempFile("", "push-archive-integration") + tmpfile, err := os.CreateTemp("", "push-archive-integration") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()) @@ -186,7 +185,7 @@ var _ = Describe("push with .cfignore", func() { It("does not push it", func() { helpers.WithHelloWorldApp(func(appDir string) { traceFilePath := filepath.Join(appDir, "i-am-trace.txt") - err := ioutil.WriteFile(traceFilePath, nil, 0666) + err := os.WriteFile(traceFilePath, nil, 0666) Expect(err).ToNot(HaveOccurred()) previousEnv = os.Getenv("CF_TRACE") @@ -205,31 +204,31 @@ var _ = Describe("push with .cfignore", func() { It("pushes all the files except for the files ignored by default", func() { helpers.WithHelloWorldApp(func(appDir string) { file1 := filepath.Join(appDir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(appDir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) darcsFile := filepath.Join(appDir, "_darcs") - err = ioutil.WriteFile(darcsFile, nil, 0666) + err = os.WriteFile(darcsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) dsFile := filepath.Join(appDir, ".DS_Store") - err = ioutil.WriteFile(dsFile, nil, 0666) + err = os.WriteFile(dsFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitFile := filepath.Join(appDir, ".git") - err = ioutil.WriteFile(gitFile, nil, 0666) + err = os.WriteFile(gitFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) gitIgnoreFile := filepath.Join(appDir, ".gitignore") - err = ioutil.WriteFile(gitIgnoreFile, nil, 0666) + err = os.WriteFile(gitIgnoreFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) hgFile := filepath.Join(appDir, ".hg") - err = ioutil.WriteFile(hgFile, nil, 0666) + err = os.WriteFile(hgFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) manifestFile := filepath.Join(appDir, "manifest.yml") @@ -243,7 +242,7 @@ var _ = Describe("push with .cfignore", func() { ) svnFile := filepath.Join(appDir, ".svn") - err = ioutil.WriteFile(svnFile, nil, 0666) + err = os.WriteFile(svnFile, nil, 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) diff --git a/integration/v7/push/combination_manifest_and_flag_test.go b/integration/v7/push/combination_manifest_and_flag_test.go index 3b89bc02b8d..78410af2962 100644 --- a/integration/v7/push/combination_manifest_and_flag_test.go +++ b/integration/v7/push/combination_manifest_and_flag_test.go @@ -1,7 +1,6 @@ package push import ( - "io/ioutil" "os" "path/filepath" "regexp" @@ -154,7 +153,7 @@ var _ = Describe("push with a simple manifest and flags", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "combination-manifest-with-p") + tempDir, err = os.MkdirTemp("", "combination-manifest-with-p") Expect(err).ToNot(HaveOccurred()) helpers.WriteManifest(filepath.Join(tempDir, "manifest.yml"), map[string]interface{}{ diff --git a/integration/v7/push/docker_test.go b/integration/v7/push/docker_test.go index 3c4e99c350e..6cdce941a64 100644 --- a/integration/v7/push/docker_test.go +++ b/integration/v7/push/docker_test.go @@ -1,7 +1,7 @@ package push import ( - "io/ioutil" + "os" "path/filepath" "code.cloudfoundry.org/cli/integration/helpers" @@ -20,7 +20,7 @@ var _ = Describe("pushing docker images", func() { BeforeEach(func() { appName = helpers.PrefixedRandomName("app") var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) }) diff --git a/integration/v7/push/droplet_flag_test.go b/integration/v7/push/droplet_flag_test.go index 3294f22be34..cf7378bc802 100644 --- a/integration/v7/push/droplet_flag_test.go +++ b/integration/v7/push/droplet_flag_test.go @@ -2,7 +2,6 @@ package push import ( "fmt" - "io/ioutil" "os" "code.cloudfoundry.org/cli/integration/helpers" @@ -24,7 +23,7 @@ var _ = Describe("--droplet flag", func() { appName = helpers.NewAppName() helpers.WithHelloWorldApp(func(appDir string) { - tmpfile, err := ioutil.TempFile("", "dropletFile*.tgz") + tmpfile, err := os.CreateTemp("", "dropletFile*.tgz") Expect(err).ToNot(HaveOccurred()) dropletPath = tmpfile.Name() Expect(tmpfile.Close()).ToNot(HaveOccurred()) @@ -77,7 +76,7 @@ var _ = Describe("--droplet flag", func() { When("the droplet bits path is not a gzipped tarball", func() { It("fails with a helpful error message", func() { - nonTgzFile, err := ioutil.TempFile("", "dropletFile*.txt") + nonTgzFile, err := os.CreateTemp("", "dropletFile*.txt") Expect(err).ToNot(HaveOccurred()) session := helpers.CF(PushCommandName, appName, "--droplet", nonTgzFile.Name()) Eventually(session).Should(Say(`FAILED`)) diff --git a/integration/v7/push/ignore_app_files_test.go b/integration/v7/push/ignore_app_files_test.go index e78f869643e..877a33f89c0 100644 --- a/integration/v7/push/ignore_app_files_test.go +++ b/integration/v7/push/ignore_app_files_test.go @@ -1,7 +1,7 @@ package push import ( - "io/ioutil" + "os" "path/filepath" "code.cloudfoundry.org/cli/integration/helpers" @@ -26,15 +26,15 @@ var _ = Describe("ignoring files while gathering resources", func() { It("pushes all the files", func() { helpers.WithHelloWorldApp(func(dir string) { file1 := filepath.Join(dir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(dir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(dir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, nil, 0666) + err = os.WriteFile(cfIgnoreFilePath, nil, 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp, "--no-start") @@ -50,15 +50,15 @@ var _ = Describe("ignoring files while gathering resources", func() { It("does not push those files", func() { helpers.WithHelloWorldApp(func(dir string) { file1 := filepath.Join(dir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(dir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(dir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp, "--no-start") @@ -73,15 +73,15 @@ var _ = Describe("ignoring files while gathering resources", func() { It("does not push those files", func() { helpers.WithHelloWorldApp(func(dir string) { file1 := filepath.Join(dir, "file1") - err := ioutil.WriteFile(file1, nil, 0666) + err := os.WriteFile(file1, nil, 0666) Expect(err).ToNot(HaveOccurred()) file2 := filepath.Join(dir, "file2") - err = ioutil.WriteFile(file2, nil, 0666) + err = os.WriteFile(file2, nil, 0666) Expect(err).ToNot(HaveOccurred()) cfIgnoreFilePath := filepath.Join(dir, ".cfignore") - err = ioutil.WriteFile(cfIgnoreFilePath, []byte("/file*"), 0666) + err = os.WriteFile(cfIgnoreFilePath, []byte("/file*"), 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp, "--no-start") @@ -98,7 +98,7 @@ var _ = Describe("ignoring files while gathering resources", func() { It("does not push it", func() { helpers.WithHelloWorldApp(func(dir string) { traceFilePath := filepath.Join(dir, "i-am-trace.txt") - err := ioutil.WriteFile(traceFilePath, nil, 0666) + err := os.WriteFile(traceFilePath, nil, 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.DebugCustomCF(helpers.CFEnv{ diff --git a/integration/v7/push/manifest_with_app_name_and_no_route_flag_test.go b/integration/v7/push/manifest_with_app_name_and_no_route_flag_test.go index 2494eddc7c1..7390c4cc64b 100644 --- a/integration/v7/push/manifest_with_app_name_and_no_route_flag_test.go +++ b/integration/v7/push/manifest_with_app_name_and_no_route_flag_test.go @@ -2,7 +2,6 @@ package push import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -27,7 +26,7 @@ var _ = Describe("push with a manifest and an app name", func() { randomHostName = helpers.RandomName() var err error - tempDir, err = ioutil.TempDir("", "no-route-flag-with-manifest-test") + tempDir, err = os.MkdirTemp("", "no-route-flag-with-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToSetupManifest := filepath.Join(tempDir, "setup-manifest.yml") helpers.WriteManifest(pathToSetupManifest, map[string]interface{}{ diff --git a/integration/v7/push/manifest_with_app_name_test.go b/integration/v7/push/manifest_with_app_name_test.go index c2ddc987ed4..c26a7d71be6 100644 --- a/integration/v7/push/manifest_with_app_name_test.go +++ b/integration/v7/push/manifest_with_app_name_test.go @@ -2,7 +2,6 @@ package push import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -26,7 +25,7 @@ var _ = Describe("push with a manifest and an app name", func() { appName = helpers.NewAppName() secondName = helpers.NewAppName() var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ @@ -92,7 +91,7 @@ var _ = Describe("push with a manifest and an app name", func() { When("an appName is not given with a nameless manifest", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ diff --git a/integration/v7/push/path_test.go b/integration/v7/push/path_test.go index 11c29ab6c63..06eebc8b5fe 100644 --- a/integration/v7/push/path_test.go +++ b/integration/v7/push/path_test.go @@ -2,7 +2,6 @@ package push import ( "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -27,7 +26,7 @@ var _ = Describe("handle path in manifest and flag override", func() { appName = helpers.NewAppName() secondName = helpers.NewAppName() var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) }) @@ -224,7 +223,7 @@ var _ = Describe("handle path in manifest and flag override", func() { manifestDir := helpers.TempDirAbsolutePath("", "manifest-dir") defer os.RemoveAll(manifestDir) - err := ioutil.WriteFile( + err := os.WriteFile( filepath.Join(manifestDir, "manifest.yml"), []byte(fmt.Sprintf(`--- applications: @@ -248,7 +247,7 @@ applications: var emptyDir string BeforeEach(func() { - sympath, err := ioutil.TempDir("", "integration-push-path-empty") + sympath, err := os.MkdirTemp("", "integration-push-path-empty") Expect(err).ToNot(HaveOccurred()) emptyDir, err = filepath.EvalSymlinks(sympath) Expect(err).ToNot(HaveOccurred()) @@ -272,7 +271,7 @@ applications: BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { - tmpfile, err := ioutil.TempFile("", "push-archive-integration") + tmpfile, err := os.CreateTemp("", "push-archive-integration") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()) diff --git a/integration/v7/push/push_suite_test.go b/integration/v7/push/push_suite_test.go index cbf86bd7887..ebd30ce219f 100644 --- a/integration/v7/push/push_suite_test.go +++ b/integration/v7/push/push_suite_test.go @@ -2,7 +2,6 @@ package push import ( "fmt" - "io/ioutil" "os" "testing" "time" @@ -67,7 +66,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { helpers.DestroyHomeDir(homeDir) var err error - realDir, err = ioutil.TempDir("", "push-real-dir") + realDir, err = os.MkdirTemp("", "push-real-dir") Expect(err).ToNot(HaveOccurred()) GinkgoWriter.Write([]byte(fmt.Sprintf("==============================End of Global Node %d Synchronized Before Each==============================", GinkgoParallelProcess()))) }) diff --git a/integration/v7/push/resource_matching_test.go b/integration/v7/push/resource_matching_test.go index 078f1787260..9364f9c3424 100644 --- a/integration/v7/push/resource_matching_test.go +++ b/integration/v7/push/resource_matching_test.go @@ -2,7 +2,7 @@ package push import ( "fmt" - "io/ioutil" + "os" "path/filepath" "strings" "time" @@ -27,7 +27,7 @@ var _ = Describe("resource matching", func() { It("uploads the unmatched resources", func() { helpers.WithHelloWorldApp(func(dir string) { tempfile := filepath.Join(dir, "ignore.html") - err := ioutil.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %s %s", time.Now(), strings.Repeat("a", 65*1024))), 0666) + err := os.WriteFile(tempfile, []byte(fmt.Sprintf("hello world %s %s", time.Now(), strings.Repeat("a", 65*1024))), 0666) Expect(err).ToNot(HaveOccurred()) session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") diff --git a/integration/v7/push/simple_manifest_only_test.go b/integration/v7/push/simple_manifest_only_test.go index 212871eeec5..3b94b4496cd 100644 --- a/integration/v7/push/simple_manifest_only_test.go +++ b/integration/v7/push/simple_manifest_only_test.go @@ -1,13 +1,12 @@ package push import ( - "io/ioutil" "os" "path/filepath" "code.cloudfoundry.org/cli/integration/helpers" - . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gbytes" . "github.com/onsi/gomega/gexec" @@ -110,7 +109,7 @@ var _ = Describe("push with a simple manifest", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ @@ -168,7 +167,7 @@ var _ = Describe("push with a simple manifest", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ @@ -216,7 +215,7 @@ var _ = Describe("push with a simple manifest", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ @@ -267,7 +266,7 @@ var _ = Describe("push with a simple manifest", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ @@ -311,7 +310,7 @@ var _ = Describe("push with a simple manifest", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ @@ -352,7 +351,7 @@ var _ = Describe("push with a simple manifest", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "simple-manifest-test") + tempDir, err = os.MkdirTemp("", "simple-manifest-test") Expect(err).ToNot(HaveOccurred()) pathToManifest = filepath.Join(tempDir, "manifest.yml") helpers.WriteManifest(pathToManifest, map[string]interface{}{ diff --git a/integration/v7/push/symlink_resources_test.go b/integration/v7/push/symlink_resources_test.go index e2413af8a59..f79ef305b2b 100644 --- a/integration/v7/push/symlink_resources_test.go +++ b/integration/v7/push/symlink_resources_test.go @@ -1,7 +1,6 @@ package push import ( - "io/ioutil" "os" "path/filepath" @@ -27,7 +26,7 @@ var _ = Describe("push with symlinked resources", func() { It("should push the symlink", func() { helpers.WithHelloWorldApp(func(dir string) { targetFile := filepath.Join(dir, "targetFile") - Expect(ioutil.WriteFile(targetFile, []byte("foo bar baz"), 0777)).ToNot(HaveOccurred()) + Expect(os.WriteFile(targetFile, []byte("foo bar baz"), 0777)).ToNot(HaveOccurred()) relativePath, err := filepath.Rel(dir, targetFile) Expect(err).ToNot(HaveOccurred()) @@ -46,7 +45,7 @@ var _ = Describe("push with symlinked resources", func() { When("the file doesn't exists", func() { It("should push the symlink", func() { helpers.WithHelloWorldApp(func(dir string) { - tempFile, err := ioutil.TempFile(dir, "tempFile") + tempFile, err := os.CreateTemp(dir, "tempFile") Expect(err).ToNot(HaveOccurred()) tempFile.Close() relativePath, err := filepath.Rel(dir, tempFile.Name()) @@ -69,7 +68,7 @@ var _ = Describe("push with symlinked resources", func() { When("the directory contains a symlink to subdirectory in the directory", func() { It("should push the symlink", func() { helpers.WithHelloWorldApp(func(dir string) { - targetDir, err := ioutil.TempDir(dir, "target-dir") + targetDir, err := os.MkdirTemp(dir, "target-dir") Expect(err).ToNot(HaveOccurred()) relativePath, err := filepath.Rel(dir, targetDir) Expect(err).ToNot(HaveOccurred()) @@ -99,13 +98,13 @@ var _ = Describe("push with symlinked resources", func() { BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { helpers.WithHelloWorldApp(func(appDir string) { - tmpfile, err := ioutil.TempFile("", "push-archive-integration") + tmpfile, err := os.CreateTemp("", "push-archive-integration") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()).ToNot(HaveOccurred()) targetFile := filepath.Join(appDir, "targetFile") - Expect(ioutil.WriteFile(targetFile, []byte("some random data"), 0777)).ToNot(HaveOccurred()) + Expect(os.WriteFile(targetFile, []byte("some random data"), 0777)).ToNot(HaveOccurred()) relativePath, err := filepath.Rel(appDir, targetFile) Expect(err).ToNot(HaveOccurred()) diff --git a/integration/v7/push/symlink_test.go b/integration/v7/push/symlink_test.go index 1e838520420..37339d753fd 100644 --- a/integration/v7/push/symlink_test.go +++ b/integration/v7/push/symlink_test.go @@ -1,7 +1,6 @@ package push import ( - "io/ioutil" "os" "path/filepath" @@ -22,7 +21,7 @@ var _ = Describe("push with symlink path", func() { appName = helpers.NewAppName() var err error - runningDir, err = ioutil.TempDir("", "push-with-symlink") + runningDir, err = os.MkdirTemp("", "push-with-symlink") Expect(err).ToNot(HaveOccurred()) symlinkedPath = filepath.Join(runningDir, "symlink-dir") }) @@ -63,7 +62,7 @@ var _ = Describe("push with symlink path", func() { BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { - tmpfile, err := ioutil.TempFile("", "push-archive-integration") + tmpfile, err := os.CreateTemp("", "push-archive-integration") Expect(err).ToNot(HaveOccurred()) archive = tmpfile.Name() Expect(tmpfile.Close()).ToNot(HaveOccurred()) diff --git a/integration/v7/selfcontained/selfcontained_suite_test.go b/integration/v7/selfcontained/selfcontained_suite_test.go index 336ec8bcc8b..f5f1a647105 100644 --- a/integration/v7/selfcontained/selfcontained_suite_test.go +++ b/integration/v7/selfcontained/selfcontained_suite_test.go @@ -6,7 +6,6 @@ import ( "crypto/rsa" "encoding/base64" "encoding/json" - "io/ioutil" "os" "path/filepath" "testing" @@ -58,7 +57,7 @@ var _ = AfterEach(func() { }) func loadConfig() configv3.JSONConfig { - rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + rawConfig, err := os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).NotTo(HaveOccurred()) var configFile configv3.JSONConfig diff --git a/plugin/plugin.go b/plugin/plugin.go index 47853eb4d4d..b2f1f8113ac 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -2,9 +2,13 @@ package plugin import plugin_models "code.cloudfoundry.org/cli/plugin/models" -/** +/* +* + Command interface needs to be implemented for a runnable plugin of `cf` -**/ + +* +*/ type Plugin interface { Run(cliConnection CliConnection, args []string) GetMetadata() PluginMetadata diff --git a/plugin/plugin_examples/test_rpc_server_example/test_rpc_server_example_suite_test.go b/plugin/plugin_examples/test_rpc_server_example/test_rpc_server_example_suite_test.go index a31acf07fac..182bf14c795 100644 --- a/plugin/plugin_examples/test_rpc_server_example/test_rpc_server_example_suite_test.go +++ b/plugin/plugin_examples/test_rpc_server_example/test_rpc_server_example_suite_test.go @@ -1,13 +1,12 @@ package main_test import ( + "testing" "time" "code.cloudfoundry.org/cli/cf/util/testhelpers/pluginbuilder" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) func TestTestRpcServerExample(t *testing.T) { diff --git a/plugin/plugin_suite_test.go b/plugin/plugin_suite_test.go index 4b02e049580..8076cb8955e 100644 --- a/plugin/plugin_suite_test.go +++ b/plugin/plugin_suite_test.go @@ -2,12 +2,11 @@ package plugin_test import ( "path/filepath" + "testing" "code.cloudfoundry.org/cli/cf/util/testhelpers/pluginbuilder" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) func TestPlugin(t *testing.T) { diff --git a/plugin/rpc/cli_rpc_server.go b/plugin/rpc/cli_rpc_server.go index 168f6a3b065..34241693b2c 100644 --- a/plugin/rpc/cli_rpc_server.go +++ b/plugin/rpc/cli_rpc_server.go @@ -1,8 +1,15 @@ package rpc import ( + "bytes" + "fmt" + "io" + "net" + "net/rpc" "os" + "strconv" "strings" + "sync" "code.cloudfoundry.org/cli/cf/api" "code.cloudfoundry.org/cli/cf/commandregistry" @@ -13,16 +20,6 @@ import ( "code.cloudfoundry.org/cli/version" "github.com/blang/semver/v4" - "fmt" - "net" - "net/rpc" - "strconv" - - "bytes" - "io" - - "sync" - "code.cloudfoundry.org/cli/cf/trace" ) diff --git a/resources/application_resource.go b/resources/application_resource.go index 361cb14c6a7..b7b5c782557 100644 --- a/resources/application_resource.go +++ b/resources/application_resource.go @@ -1,9 +1,10 @@ package resources import ( + "encoding/json" + "code.cloudfoundry.org/cli/api/cloudcontroller" "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" - "encoding/json" ) // Application represents a Cloud Controller V3 Application. diff --git a/resources/service_instance_usage_summary_resource.go b/resources/service_instance_usage_summary_resource.go index 45be72edf13..20a5e147a76 100644 --- a/resources/service_instance_usage_summary_resource.go +++ b/resources/service_instance_usage_summary_resource.go @@ -13,7 +13,7 @@ func (s *ServiceInstanceUsageSummaryList) UnmarshalJSON(data []byte) error { } type ServiceInstanceUsageSummary struct { - SpaceGUID string `jsonry:"space.guid""` + SpaceGUID string `jsonry:"space.guid"` BoundAppCount int `jsonry:"bound_app_count"` } diff --git a/resources/shared_to_spaces_resource_test.go b/resources/shared_to_spaces_resource_test.go index 532586237ff..ce3a43e37e0 100644 --- a/resources/shared_to_spaces_resource_test.go +++ b/resources/shared_to_spaces_resource_test.go @@ -1,9 +1,9 @@ package resources_test import ( - "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" "encoding/json" + "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" . "code.cloudfoundry.org/cli/resources" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/util/batcher/batcher_test.go b/util/batcher/batcher_test.go index ccaca8687f6..dd02696fbad 100644 --- a/util/batcher/batcher_test.go +++ b/util/batcher/batcher_test.go @@ -52,7 +52,8 @@ var _ = Describe("Batcher", func() { }) It("calls the callback", func() { - batcher.RequestByGUID([]string{"one", "two", "three"}, fakeCallback) + _, err := batcher.RequestByGUID([]string{"one", "two", "three"}, fakeCallback) + Expect(err).NotTo(HaveOccurred()) Expect(calls).To(HaveLen(1)) Expect(calls[0]).To(Equal([]string{"one", "two", "three"})) @@ -60,7 +61,8 @@ var _ = Describe("Batcher", func() { When("the guids list exceeds the batch size", func() { It("calls the callback multiple times", func() { - batcher.RequestByGUID(spreadGuids(0, 520), fakeCallback) + _, err := batcher.RequestByGUID(spreadGuids(0, 520), fakeCallback) + Expect(err).NotTo(HaveOccurred()) Expect(calls).To(HaveLen(3)) Expect(calls[0]).To(Equal(spreadGuids(0, 200))) diff --git a/util/checksum_test.go b/util/checksum_test.go index d7dfe1cd299..4dcade05947 100644 --- a/util/checksum_test.go +++ b/util/checksum_test.go @@ -2,7 +2,6 @@ package util_test import ( "fmt" - "io/ioutil" "os" . "code.cloudfoundry.org/cli/util" @@ -35,7 +34,7 @@ var _ = Describe("Sha1Checksum", func() { ) BeforeEach(func() { - f, err = ioutil.TempFile("", "sha1_test_") + f, err = os.CreateTemp("", "sha1_test_") Expect(err).NotTo(HaveOccurred()) defer f.Close() _, err = f.Write([]byte("abc")) @@ -79,7 +78,7 @@ var _ = Describe("Sha1Checksum", func() { ) BeforeEach(func() { - f, err = ioutil.TempFile("", "sha1_test_") + f, err = os.CreateTemp("", "sha1_test_") Expect(err).NotTo(HaveOccurred()) defer f.Close() _, err = f.Write([]byte("abc")) diff --git a/util/clissh/ssh.go b/util/clissh/ssh.go index 069022872cc..a6f32ce7115 100644 --- a/util/clissh/ssh.go +++ b/util/clissh/ssh.go @@ -264,6 +264,7 @@ func (c *SecureShell) localForwardAcceptLoop(listener net.Listener, addr string) for { conn, err := listener.Accept() if err != nil { + //nolint:staticcheck if netErr, ok := err.(net.Error); ok && netErr.Temporary() { time.Sleep(100 * time.Millisecond) continue diff --git a/util/clissh/ssh_suite_test.go b/util/clissh/ssh_suite_test.go index 9d157c12c19..1276d6b36af 100644 --- a/util/clissh/ssh_suite_test.go +++ b/util/clissh/ssh_suite_test.go @@ -1,16 +1,15 @@ package clissh_test import ( - "io/ioutil" + "os" "path/filepath" + "testing" "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" log "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" - - "testing" ) var ( @@ -26,12 +25,12 @@ func TestCmd(t *testing.T) { var _ = BeforeSuite(func() { SetDefaultEventuallyTimeout(3 * time.Second) - hostKeyBytes, err := ioutil.ReadFile(filepath.Join("..", "..", "fixtures", "host-key")) + hostKeyBytes, err := os.ReadFile(filepath.Join("..", "..", "fixtures", "host-key")) Expect(err).NotTo(HaveOccurred()) hostKey, err := ssh.ParsePrivateKey(hostKeyBytes) Expect(err).NotTo(HaveOccurred()) - privateKeyBytes, err := ioutil.ReadFile(filepath.Join("..", "..", "fixtures", "private-key")) + privateKeyBytes, err := os.ReadFile(filepath.Join("..", "..", "fixtures", "private-key")) Expect(err).NotTo(HaveOccurred()) privateKey, err := ssh.ParsePrivateKey(privateKeyBytes) Expect(err).NotTo(HaveOccurred()) diff --git a/util/command_parser/command_parser_test.go b/util/command_parser/command_parser_test.go index 6beb0d6846f..e12c3735297 100644 --- a/util/command_parser/command_parser_test.go +++ b/util/command_parser/command_parser_test.go @@ -1,13 +1,14 @@ package command_parser_test import ( + "io" + "code.cloudfoundry.org/cli/command/common" "code.cloudfoundry.org/cli/util/command_parser" "code.cloudfoundry.org/cli/util/configv3" "code.cloudfoundry.org/cli/util/ui" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "io/ioutil" ) var _ = Describe("Command 'Parser'", func() { @@ -18,7 +19,7 @@ var _ = Describe("Command 'Parser'", func() { BeforeEach(func() { var err error v3Config = new(configv3.Config) - pluginUI, err = ui.NewPluginUI(v3Config, ioutil.Discard, ioutil.Discard) + pluginUI, err = ui.NewPluginUI(v3Config, io.Discard, io.Discard) Expect(err).ToNot(HaveOccurred()) }) diff --git a/util/configv3/color.go b/util/configv3/color.go index 50301cc8a81..51cfa5655a8 100644 --- a/util/configv3/color.go +++ b/util/configv3/color.go @@ -22,9 +22,9 @@ const ( type ColorSetting int // ColorEnabled returns the color setting based off: -// 1. The $CF_COLOR environment variable if set (0/1/t/f/true/false) -// 2. The 'ColorEnabled' value in the .cf/config.json if set -// 3. Defaults to ColorAuto if nothing is set +// 1. The $CF_COLOR environment variable if set (0/1/t/f/true/false) +// 2. The 'ColorEnabled' value in the .cf/config.json if set +// 3. Defaults to ColorAuto if nothing is set func (config *Config) ColorEnabled() ColorSetting { if config.ENV.CFColor != "" { val, err := strconv.ParseBool(config.ENV.CFColor) diff --git a/util/configv3/config_suite_test.go b/util/configv3/config_suite_test.go index 95c6c00c320..cb2416295a2 100644 --- a/util/configv3/config_suite_test.go +++ b/util/configv3/config_suite_test.go @@ -1,15 +1,13 @@ package configv3_test import ( - "io/ioutil" "os" "path/filepath" + "testing" "code.cloudfoundry.org/cli/integration/helpers" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) const ( @@ -23,7 +21,7 @@ func TestConfig(t *testing.T) { } func setup() string { - homeDir, err := ioutil.TempDir("", "cli-config-tests") + homeDir, err := os.MkdirTemp("", "cli-config-tests") Expect(err).NotTo(HaveOccurred()) err = os.Setenv("CF_HOME", homeDir) Expect(err).NotTo(HaveOccurred()) diff --git a/util/configv3/config_unix_test.go b/util/configv3/config_unix_test.go index 21b972f9069..1d06e71acc2 100644 --- a/util/configv3/config_unix_test.go +++ b/util/configv3/config_unix_test.go @@ -5,7 +5,6 @@ package configv3_test import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -100,13 +99,13 @@ var _ = Describe("Verbose", func() { BeforeEach(func() { var err error - tempDir, err = ioutil.TempDir("", "config-trace") + tempDir, err = os.MkdirTemp("", "config-trace") Expect(err).ToNot(HaveOccurred()) tempDirAbs, err := filepath.EvalSymlinks(tempDir) Expect(err).ToNot(HaveOccurred()) ogLogPath = filepath.Join(tempDirAbs, "og.log") - err = ioutil.WriteFile(ogLogPath, nil, 0666) + err = os.WriteFile(ogLogPath, nil, 0666) Expect(err).ToNot(HaveOccurred()) symlinkLogPath = filepath.Join(tempDirAbs, "sym.log") diff --git a/util/configv3/env.go b/util/configv3/env.go index 031be343c7d..efd935e37d0 100644 --- a/util/configv3/env.go +++ b/util/configv3/env.go @@ -43,8 +43,8 @@ func (config *Config) CFUsername() string { } // DialTimeout returns the timeout to use when dialing. This is based off of: -// 1. The $CF_DIAL_TIMEOUT environment variable if set -// 2. Falling back to the default +// 1. The $CF_DIAL_TIMEOUT environment variable if set +// 2. Falling back to the default func (config *Config) DialTimeout() time.Duration { if config.ENV.CFDialTimeout != "" { envVal, err := strconv.ParseInt(config.ENV.CFDialTimeout, 10, 64) @@ -63,8 +63,8 @@ func (config *Config) DockerPassword() string { // Experimental returns whether or not to run experimental CLI commands. This // is based on the following: -// 1. The $CF_CLI_EXPERIMENTAL environment variable if set -// 2. Defaults to false +// 1. The $CF_CLI_EXPERIMENTAL environment variable if set +// 2. Defaults to false func (config *Config) Experimental() bool { if config.ENV.Experimental != "" { envVal, err := strconv.ParseBool(config.ENV.Experimental) @@ -78,8 +78,8 @@ func (config *Config) Experimental() bool { // HTTPSProxy returns the proxy url that the CLI should use. The url is based // off of: -// 1. The $https_proxy environment variable if set -// 2. Defaults to the empty string +// 1. The $https_proxy environment variable if set +// 2. Defaults to the empty string func (config *Config) HTTPSProxy() string { return config.ENV.HTTPSProxy } @@ -114,8 +114,8 @@ func (config *Config) LogLevel() int { // StagingTimeout returns the max time an application staging should take. The // time is based off of: -// 1. The $CF_STAGING_TIMEOUT environment variable if set -// 2. Defaults to the DefaultStagingTimeout +// 1. The $CF_STAGING_TIMEOUT environment variable if set +// 2. Defaults to the DefaultStagingTimeout func (config *Config) StagingTimeout() time.Duration { if config.ENV.CFStagingTimeout != "" { timeoutInMin, err := strconv.ParseFloat(config.ENV.CFStagingTimeout, 64) @@ -130,8 +130,8 @@ func (config *Config) StagingTimeout() time.Duration { // StartupTimeout returns the max time an application should take to start. The // time is based off of: -// 1. The $CF_STARTUP_TIMEOUT environment variable if set -// 2. Defaults to the DefaultStartupTimeout +// 1. The $CF_STARTUP_TIMEOUT environment variable if set +// 2. Defaults to the DefaultStartupTimeout func (config *Config) StartupTimeout() time.Duration { if config.ENV.CFStartupTimeout != "" { timeoutInMin, err := strconv.ParseFloat(config.ENV.CFStartupTimeout, 64) diff --git a/util/configv3/json_config.go b/util/configv3/json_config.go index c672de98ad9..0089bb4365d 100644 --- a/util/configv3/json_config.go +++ b/util/configv3/json_config.go @@ -92,8 +92,8 @@ func (config *Config) MinCLIVersion() string { // OverallPollingTimeout returns the overall polling timeout for async // operations. The time is based off of: -// 1. The config file's AsyncTimeout value (integer) is > 0 -// 2. Defaults to the DefaultOverallPollingTimeout +// 1. The config file's AsyncTimeout value (integer) is > 0 +// 2. Defaults to the DefaultOverallPollingTimeout func (config *Config) OverallPollingTimeout() time.Duration { if config.ConfigFile.AsyncTimeout == 0 { return DefaultOverallPollingTimeout diff --git a/util/configv3/load_config.go b/util/configv3/load_config.go index 90470e2464d..a16e7227b7a 100644 --- a/util/configv3/load_config.go +++ b/util/configv3/load_config.go @@ -2,13 +2,12 @@ package configv3 import ( "encoding/json" - "io/ioutil" "math" "os" "path/filepath" "code.cloudfoundry.org/cli/command/translatableerror" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) func (c *Config) loadPluginConfig() error { @@ -19,7 +18,7 @@ func (c *Config) loadPluginConfig() error { } } else { var file []byte - file, err = ioutil.ReadFile(pluginFilePath) + file, err = os.ReadFile(pluginFilePath) if err != nil { return err } @@ -54,14 +53,14 @@ func GetCFConfig() (*Config, error) { // // The '.cf' directory will be read in one of the following locations on UNIX // Systems: -// 1. $CF_HOME/.cf if $CF_HOME is set -// 2. $HOME/.cf as the default +// 1. $CF_HOME/.cf if $CF_HOME is set +// 2. $HOME/.cf as the default // // The '.cf' directory will be read in one of the following locations on // Windows Systems: -// 1. CF_HOME\.cf if CF_HOME is set -// 2. HOMEDRIVE\HOMEPATH\.cf if HOMEDRIVE or HOMEPATH is set -// 3. USERPROFILE\.cf as the default +// 1. CF_HOME\.cf if CF_HOME is set +// 2. HOMEDRIVE\HOMEPATH\.cf if HOMEDRIVE or HOMEPATH is set +// 3. USERPROFILE\.cf as the default func LoadConfig(flags ...FlagOverride) (*Config, error) { err := removeOldTempConfigFiles() if err != nil { @@ -86,7 +85,7 @@ func LoadConfig(flags ...FlagOverride) (*Config, error) { if _, err = os.Stat(configFilePath); err == nil || !os.IsNotExist(err) { var file []byte - file, err = ioutil.ReadFile(configFilePath) + file, err = os.ReadFile(configFilePath) if err != nil { return nil, err } @@ -149,12 +148,12 @@ func LoadConfig(flags ...FlagOverride) (*Config, error) { } // Developer Note: The following is untested! Change at your own risk. - isTTY := terminal.IsTerminal(int(os.Stdout.Fd())) + isTTY := term.IsTerminal(int(os.Stdout.Fd())) terminalWidth := math.MaxInt32 if isTTY { var err error - terminalWidth, _, err = terminal.GetSize(int(os.Stdout.Fd())) + terminalWidth, _, err = term.GetSize(int(os.Stdout.Fd())) if err != nil { return nil, err } diff --git a/util/configv3/load_config_test.go b/util/configv3/load_config_test.go index 9fdb6a9286b..3f051427936 100644 --- a/util/configv3/load_config_test.go +++ b/util/configv3/load_config_test.go @@ -2,7 +2,6 @@ package configv3_test import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -64,7 +63,7 @@ var _ = Describe("Config", func() { configDir := filepath.Join(homeDir, ".cf") Expect(os.MkdirAll(configDir, 0777)).To(Succeed()) for i := 0; i < 3; i++ { - tmpFile, fileErr := ioutil.TempFile(configDir, "temp-config") + tmpFile, fileErr := os.CreateTemp(configDir, "temp-config") Expect(fileErr).ToNot(HaveOccurred()) tmpFile.Close() } diff --git a/util/configv3/locale.go b/util/configv3/locale.go index 99da3e0688f..dd5c4c47475 100644 --- a/util/configv3/locale.go +++ b/util/configv3/locale.go @@ -9,10 +9,10 @@ const ( // Locale returns the locale/language the UI should be displayed in. This value // is based off of: -// 1. The 'Locale' setting in the .cf/config.json -// 2. The $LC_ALL environment variable if set -// 3. The $LANG environment variable if set -// 4. Defaults to DefaultLocale +// 1. The 'Locale' setting in the .cf/config.json +// 2. The $LC_ALL environment variable if set +// 3. The $LANG environment variable if set +// 4. Defaults to DefaultLocale func (config *Config) Locale() string { if config.ConfigFile.Locale != "" { return config.ConfigFile.Locale diff --git a/util/configv3/plugins_config.go b/util/configv3/plugins_config.go index d5776e9ba8a..a084b71f563 100644 --- a/util/configv3/plugins_config.go +++ b/util/configv3/plugins_config.go @@ -3,7 +3,6 @@ package configv3 import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "sort" @@ -114,8 +113,8 @@ func (config *Config) GetPluginCaseInsensitive(pluginName string) (Plugin, bool) } // PluginHome returns the plugin configuration directory to: -// 1. The $CF_PLUGIN_HOME/.cf/plugins environment variable if set -// 2. Defaults to the home directory (outlined in LoadConfig)/.cf/plugins +// 1. The $CF_PLUGIN_HOME/.cf/plugins environment variable if set +// 2. Defaults to the home directory (outlined in LoadConfig)/.cf/plugins func (config *Config) PluginHome() string { if config.ENV.CFPluginHome != "" { return filepath.Join(config.ENV.CFPluginHome, ".cf", "plugins") @@ -157,5 +156,5 @@ func (config *Config) WritePluginConfig() error { } // Write to file - return ioutil.WriteFile(filepath.Join(pluginFileDir, "config.json"), rawConfig, 0600) + return os.WriteFile(filepath.Join(pluginFileDir, "config.json"), rawConfig, 0600) } diff --git a/util/configv3/plugins_config_test.go b/util/configv3/plugins_config_test.go index 3639f80e733..7a5ce1a0d2b 100644 --- a/util/configv3/plugins_config_test.go +++ b/util/configv3/plugins_config_test.go @@ -1,7 +1,6 @@ package configv3_test import ( - "io/ioutil" "os" "path/filepath" "syscall" @@ -397,7 +396,7 @@ var _ = Describe("PluginsConfig", func() { config = new(Config) var err error - pluginHome, err = ioutil.TempDir("", "my-plugin-home") + pluginHome, err = os.MkdirTemp("", "my-plugin-home") Expect(err).ToNot(HaveOccurred()) Expect(os.RemoveAll(pluginHome)).ToNot(HaveOccurred()) }) @@ -427,7 +426,7 @@ var _ = Describe("PluginsConfig", func() { var tempFile string BeforeEach(func() { - f, err := ioutil.TempFile("", "fail-plugin-home") + f, err := os.CreateTemp("", "fail-plugin-home") Expect(err).ToNot(HaveOccurred()) Expect(f.Close()).ToNot(HaveOccurred()) tempFile = f.Name() @@ -455,11 +454,11 @@ var _ = Describe("PluginsConfig", func() { BeforeEach(func() { var err error - file, err = ioutil.TempFile("", "") + file, err = os.CreateTemp("", "") Expect(err).NotTo(HaveOccurred()) defer file.Close() - err = ioutil.WriteFile(file.Name(), []byte("foo"), 0600) + err = os.WriteFile(file.Name(), []byte("foo"), 0600) Expect(err).NotTo(HaveOccurred()) plugin.Location = file.Name() @@ -480,7 +479,7 @@ var _ = Describe("PluginsConfig", func() { BeforeEach(func() { var err error - dirPath, err = ioutil.TempDir("", "") + dirPath, err = os.MkdirTemp("", "") Expect(err).NotTo(HaveOccurred()) plugin.Location = dirPath diff --git a/util/configv3/write_config.go b/util/configv3/write_config.go index 15f02637820..950ae9accd1 100644 --- a/util/configv3/write_config.go +++ b/util/configv3/write_config.go @@ -2,7 +2,6 @@ package configv3 import ( "encoding/json" - "io/ioutil" "os" "os/signal" "syscall" @@ -31,7 +30,7 @@ func (c *Config) WriteConfig() error { signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, os.Interrupt) defer signal.Stop(sig) - tempConfigFile, err := ioutil.TempFile(dir, "temp-config") + tempConfigFile, err := os.CreateTemp(dir, "temp-config") if err != nil { return err } @@ -40,7 +39,7 @@ func (c *Config) WriteConfig() error { go catchSignal(sig, tempConfigFileName) - err = ioutil.WriteFile(tempConfigFileName, rawConfig, 0600) + err = os.WriteFile(tempConfigFileName, rawConfig, 0600) if err != nil { return err } diff --git a/util/configv3/write_config_test.go b/util/configv3/write_config_test.go index aeb9778c411..3b8760de7e9 100644 --- a/util/configv3/write_config_test.go +++ b/util/configv3/write_config_test.go @@ -2,7 +2,7 @@ package configv3_test import ( "encoding/json" - "io/ioutil" + "os" "path/filepath" "sort" "strings" @@ -45,7 +45,7 @@ var _ = Describe("Config", func() { err := config.WriteConfig() Expect(err).ToNot(HaveOccurred()) - file, err = ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) + file, err = os.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) Expect(err).ToNot(HaveOccurred()) }) diff --git a/util/download/downloader.go b/util/download/downloader.go index 36560464b4b..e779e84c6d7 100644 --- a/util/download/downloader.go +++ b/util/download/downloader.go @@ -2,7 +2,6 @@ package download import ( "io" - "io/ioutil" "net" "net/http" "os" @@ -43,7 +42,7 @@ func (downloader Downloader) Download(url string, tmpDirPath string) (string, er defer resp.Body.Close() if resp.StatusCode >= 400 { - rawBytes, readErr := ioutil.ReadAll(resp.Body) + rawBytes, readErr := io.ReadAll(resp.Body) if readErr != nil { return bpFileName, readErr } diff --git a/util/download/downloader_test.go b/util/download/downloader_test.go index ea285c9358f..44dbfc550c2 100644 --- a/util/download/downloader_test.go +++ b/util/download/downloader_test.go @@ -2,7 +2,7 @@ package download_test import ( "errors" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -39,7 +39,7 @@ var _ = Describe("Downloader", func() { url = "https://some.url" var err error - tmpDirPath, err = ioutil.TempDir("", "bpdir-") + tmpDirPath, err = os.MkdirTemp("", "bpdir-") Expect(err).ToNot(HaveOccurred()) }) @@ -57,7 +57,7 @@ var _ = Describe("Downloader", func() { BeforeEach(func() { responseBody = "some response body" response := &http.Response{ - Body: ioutil.NopCloser(strings.NewReader(responseBody)), + Body: io.NopCloser(strings.NewReader(responseBody)), ContentLength: int64(len(responseBody)), StatusCode: http.StatusOK, } @@ -67,7 +67,7 @@ var _ = Describe("Downloader", func() { It("returns correct path to the downloaded file", func() { Expect(executeErr).ToNot(HaveOccurred()) - raw, err := ioutil.ReadFile(file) + raw, err := os.ReadFile(file) Expect(err).ToNot(HaveOccurred()) Expect(string(raw)).To(Equal(responseBody)) }) @@ -96,7 +96,7 @@ var _ = Describe("Downloader", func() { BeforeEach(func() { responseBody = "not found" response := &http.Response{ - Body: ioutil.NopCloser(strings.NewReader(responseBody)), + Body: io.NopCloser(strings.NewReader(responseBody)), StatusCode: http.StatusNotFound, Status: "404 Not Found", } diff --git a/util/manifest/manifest.go b/util/manifest/manifest.go index e993b116a1c..3d244ac8275 100644 --- a/util/manifest/manifest.go +++ b/util/manifest/manifest.go @@ -1,7 +1,7 @@ package manifest import ( - "io/ioutil" + "os" "path/filepath" "github.com/cloudfoundry/bosh-cli/director/template" @@ -59,7 +59,7 @@ func ReadAndInterpolateManifest(pathToManifest string, pathsToVarsFiles []string // interpolates variables if a vars file is provided, and returns the // Unmarshalled result. func ReadAndInterpolateRawManifest(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV) ([]byte, error) { - rawManifest, err := ioutil.ReadFile(pathToManifest) + rawManifest, err := os.ReadFile(pathToManifest) if err != nil { return nil, err } @@ -68,7 +68,7 @@ func ReadAndInterpolateRawManifest(pathToManifest string, pathsToVarsFiles []str fileVars := template.StaticVariables{} for _, path := range pathsToVarsFiles { - rawVarsFile, ioerr := ioutil.ReadFile(path) + rawVarsFile, ioerr := os.ReadFile(path) if ioerr != nil { return nil, ioerr } @@ -105,7 +105,7 @@ func WriteApplicationManifest(application Application, filePath string) error { return ManifestCreationError{Err: err} } - err = ioutil.WriteFile(filePath, manifestBytes, 0644) + err = os.WriteFile(filePath, manifestBytes, 0644) if err != nil { return ManifestCreationError{Err: err} } diff --git a/util/manifest/manifest_test.go b/util/manifest/manifest_test.go index 3d3e3262594..fbbe5f419bc 100644 --- a/util/manifest/manifest_test.go +++ b/util/manifest/manifest_test.go @@ -3,7 +3,6 @@ package manifest_test import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -30,7 +29,7 @@ var _ = Describe("Manifest", func() { ) BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "manifest-test-") + tempFile, err := os.CreateTemp("", "manifest-test-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).ToNot(HaveOccurred()) pathToManifest = tempFile.Name() @@ -108,7 +107,7 @@ applications: random-route: true ` - err := ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err := os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -214,7 +213,7 @@ applications: When("global fields are provided", func() { DescribeTable("raises a GlobalFieldsError", func(manifestProperty string, numberOfValues int) { - tempManifest, err := ioutil.TempFile("", "manifest-test-") + tempManifest, err := os.CreateTemp("", "manifest-test-") Expect(err).ToNot(HaveOccurred()) Expect(tempManifest.Close()).ToNot(HaveOccurred()) manifestPath := tempManifest.Name() @@ -226,7 +225,7 @@ applications: values := []string{"A", "B"} manifest = fmt.Sprintf("---\n%s: [%s]", manifestProperty, strings.Join(values, ",")) } - err = ioutil.WriteFile(manifestPath, []byte(manifest), 0666) + err = os.WriteFile(manifestPath, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) _, err = ReadAndInterpolateManifest(manifestPath, pathsToVarsFiles, vars) @@ -267,7 +266,7 @@ applications: - name: "app-1" ` - err := ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err := os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -285,7 +284,7 @@ applications: memory: 200M instances: 10 ` - err := ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err := os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -319,7 +318,7 @@ applications: - "some-other-buildpack-2" memory: 2048M instances: 0` - err := ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err := os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -357,7 +356,7 @@ applications: memory: 200M instances: 10 ` - err := ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err := os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -382,7 +381,7 @@ applications: - name: app-1 buildpacks: ` - err := ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err := os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -399,7 +398,7 @@ applications: - name: ((var1)) instances: ((var2)) ` - err := ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err := os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -410,15 +409,15 @@ applications: BeforeEach(func() { var err error - varsDir, err = ioutil.TempDir("", "vars-test") + varsDir, err = os.MkdirTemp("", "vars-test") Expect(err).ToNot(HaveOccurred()) varsFilePath1 := filepath.Join(varsDir, "vars-1") - err = ioutil.WriteFile(varsFilePath1, []byte("var1: app-1"), 0666) + err = os.WriteFile(varsFilePath1, []byte("var1: app-1"), 0666) Expect(err).ToNot(HaveOccurred()) varsFilePath2 := filepath.Join(varsDir, "vars-2") - err = ioutil.WriteFile(varsFilePath2, []byte("var2: 4"), 0666) + err = os.WriteFile(varsFilePath2, []byte("var2: 4"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = append(pathsToVarsFiles, varsFilePath1, varsFilePath2) @@ -431,11 +430,11 @@ applications: When("multiple values for the same variable(s) are provided", func() { BeforeEach(func() { varsFilePath1 := filepath.Join(varsDir, "vars-1") - err := ioutil.WriteFile(varsFilePath1, []byte("var1: garbageapp\nvar1: app-1\nvar2: 0"), 0666) + err := os.WriteFile(varsFilePath1, []byte("var1: garbageapp\nvar1: app-1\nvar2: 0"), 0666) Expect(err).ToNot(HaveOccurred()) varsFilePath2 := filepath.Join(varsDir, "vars-2") - err = ioutil.WriteFile(varsFilePath2, []byte("var2: 4"), 0666) + err = os.WriteFile(varsFilePath2, []byte("var2: 4"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = append(pathsToVarsFiles, varsFilePath1, varsFilePath2) @@ -459,7 +458,7 @@ applications: When("a variable in the manifest is not provided in the vars file", func() { BeforeEach(func() { varsFilePath := filepath.Join(varsDir, "vars-1") - err := ioutil.WriteFile(varsFilePath, []byte("notvar: foo"), 0666) + err := os.WriteFile(varsFilePath, []byte("notvar: foo"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = []string{varsFilePath} @@ -484,7 +483,7 @@ applications: When("the provided file is not a valid yaml file", func() { BeforeEach(func() { varsFilePath := filepath.Join(varsDir, "vars-1") - err := ioutil.WriteFile(varsFilePath, []byte(": bad"), 0666) + err := os.WriteFile(varsFilePath, []byte(": bad"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = []string{varsFilePath} @@ -522,12 +521,12 @@ applications: When("vars and vars files are provided", func() { var varsFilePath string BeforeEach(func() { - tmp, err := ioutil.TempFile("", "util-manifest-varsilfe") + tmp, err := os.CreateTemp("", "util-manifest-varsilfe") Expect(err).NotTo(HaveOccurred()) Expect(tmp.Close()).NotTo(HaveOccurred()) varsFilePath = tmp.Name() - err = ioutil.WriteFile(varsFilePath, []byte("var1: app-1\nvar2: 12345"), 0666) + err = os.WriteFile(varsFilePath, []byte("var1: app-1\nvar2: 12345"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = []string{varsFilePath} @@ -560,7 +559,7 @@ applications: BeforeEach(func() { var err error - tmpDir, err = ioutil.TempDir("", "manifest-test-") + tmpDir, err = os.MkdirTemp("", "manifest-test-") Expect(err).NotTo(HaveOccurred()) filePath = filepath.Join(tmpDir, "manifest.yml") }) @@ -619,7 +618,7 @@ applications: It("creates and writes the manifest to the specified filepath", func() { Expect(executeErr).NotTo(HaveOccurred()) - manifestBytes, err := ioutil.ReadFile(filePath) + manifestBytes, err := os.ReadFile(filePath) Expect(err).NotTo(HaveOccurred()) Expect(string(manifestBytes)).To(Equal(`applications: - name: app-1 @@ -664,7 +663,7 @@ applications: It("does not save them in manifest", func() { Expect(executeErr).NotTo(HaveOccurred()) - manifestBytes, err := ioutil.ReadFile(filePath) + manifestBytes, err := os.ReadFile(filePath) Expect(err).NotTo(HaveOccurred()) Expect(string(manifestBytes)).To(Equal(`applications: - name: app-1 @@ -694,7 +693,7 @@ applications: It("writes the file in an expanded path", func() { Expect(executeErr).ToNot(HaveOccurred()) - manifestBytes, err := ioutil.ReadFile(filepath.Join(tmpDir, "manifest.yml")) + manifestBytes, err := os.ReadFile(filepath.Join(tmpDir, "manifest.yml")) Expect(err).ToNot(HaveOccurred()) Expect(string(manifestBytes)).To(Equal(`applications: - name: app-1 @@ -704,7 +703,7 @@ applications: When("the file already exists", func() { BeforeEach(func() { - err := ioutil.WriteFile(filePath, []byte(`{}`), 0644) + err := os.WriteFile(filePath, []byte(`{}`), 0644) Expect(err).ToNot(HaveOccurred()) application = Application{ Name: "app-1", @@ -714,7 +713,7 @@ applications: Context("writes the file", func() { It("truncates and writes the manifest to specified filepath", func() { Expect(executeErr).ToNot(HaveOccurred()) - manifestBytes, err := ioutil.ReadFile(filePath) + manifestBytes, err := os.ReadFile(filePath) Expect(err).ToNot(HaveOccurred()) Expect(string(manifestBytes)).To(Equal(`applications: - name: app-1 diff --git a/util/manifest/manifest_unix_test.go b/util/manifest/manifest_unix_test.go index dfb40924316..e4a5db67e55 100644 --- a/util/manifest/manifest_unix_test.go +++ b/util/manifest/manifest_unix_test.go @@ -4,7 +4,6 @@ package manifest_test import ( - "io/ioutil" "os" "path/filepath" @@ -21,12 +20,12 @@ var _ = Describe("Manifest with paths", func() { ) JustBeforeEach(func() { - tempFile, err := ioutil.TempFile("", "manifest-test-") + tempFile, err := os.CreateTemp("", "manifest-test-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).ToNot(HaveOccurred()) pathToManifest = tempFile.Name() - err = ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err = os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) diff --git a/util/manifest/manifest_windows_test.go b/util/manifest/manifest_windows_test.go index 14b2107762f..d425c419208 100644 --- a/util/manifest/manifest_windows_test.go +++ b/util/manifest/manifest_windows_test.go @@ -4,7 +4,6 @@ package manifest_test import ( - "io/ioutil" "os" "path/filepath" @@ -21,12 +20,12 @@ var _ = Describe("Manifest with paths", func() { ) JustBeforeEach(func() { - tempFile, err := ioutil.TempFile("", "manifest-test-") + tempFile, err := os.CreateTemp("", "manifest-test-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).ToNot(HaveOccurred()) pathToManifest = tempFile.Name() - err = ioutil.WriteFile(pathToManifest, []byte(manifest), 0666) + err = os.WriteFile(pathToManifest, []byte(manifest), 0666) Expect(err).ToNot(HaveOccurred()) }) diff --git a/util/manifestparser/locator_test.go b/util/manifestparser/locator_test.go index c64c1984013..120a28fa3c2 100644 --- a/util/manifestparser/locator_test.go +++ b/util/manifestparser/locator_test.go @@ -1,7 +1,6 @@ package manifestparser_test import ( - "io/ioutil" "os" "path/filepath" "strings" @@ -33,7 +32,7 @@ var _ = Describe("Locator", func() { BeforeEach(func() { var err error - workingDir, err = ioutil.TempDir("", "manifest-locator-working-dir") + workingDir, err = os.MkdirTemp("", "manifest-locator-working-dir") Expect(err).ToNot(HaveOccurred()) workingDir, err = filepath.EvalSymlinks(workingDir) Expect(err).ToNot(HaveOccurred()) @@ -50,7 +49,7 @@ var _ = Describe("Locator", func() { When("given a file path", func() { BeforeEach(func() { filepathOrDirectory = filepath.Join(workingDir, "some-manifest.yml") - Expect(ioutil.WriteFile(filepathOrDirectory, nil, 0600)).To(Succeed()) + Expect(os.WriteFile(filepathOrDirectory, nil, 0600)).To(Succeed()) }) It("returns the path and true", func() { @@ -67,7 +66,7 @@ var _ = Describe("Locator", func() { When("a manifest.yml exists in the directory", func() { BeforeEach(func() { - Expect(ioutil.WriteFile(filepath.Join(workingDir, "manifest.yml"), nil, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(workingDir, "manifest.yml"), nil, 0600)).To(Succeed()) }) It("returns the path and true", func() { @@ -79,7 +78,7 @@ var _ = Describe("Locator", func() { When("a manifest.yaml exists in the directory", func() { BeforeEach(func() { - Expect(ioutil.WriteFile(filepath.Join(workingDir, "manifest.yaml"), nil, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(workingDir, "manifest.yaml"), nil, 0600)).To(Succeed()) }) It("returns the path and true", func() { @@ -135,7 +134,7 @@ var _ = Describe("Locator", func() { When("the path to the manifest is a symbolic link", func() { BeforeEach(func() { originalFilepathOrDirectory = filepath.Join(workingDir, "some-manifest.yml") - Expect(ioutil.WriteFile(originalFilepathOrDirectory, nil, 0600)).To(Succeed()) + Expect(os.WriteFile(originalFilepathOrDirectory, nil, 0600)).To(Succeed()) filepathOrDirectory = filepath.Join(workingDir, "link-to-some-manifest.yml") err := os.Symlink(originalFilepathOrDirectory, filepathOrDirectory) Expect(err).To(BeNil()) diff --git a/util/manifestparser/parser.go b/util/manifestparser/parser.go index 2c8839bd3a7..4f1f2a83d80 100644 --- a/util/manifestparser/parser.go +++ b/util/manifestparser/parser.go @@ -2,7 +2,7 @@ package manifestparser import ( "errors" - "io/ioutil" + "os" "github.com/cloudfoundry/bosh-cli/director/template" "gopkg.in/yaml.v2" @@ -19,7 +19,7 @@ type ManifestParser struct{} // applications and leave only a single application in the resulting parsed // manifest structure. func (m ManifestParser) InterpolateManifest(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV) ([]byte, error) { - rawManifest, err := ioutil.ReadFile(pathToManifest) + rawManifest, err := os.ReadFile(pathToManifest) if err != nil { return nil, err } @@ -28,7 +28,7 @@ func (m ManifestParser) InterpolateManifest(pathToManifest string, pathsToVarsFi fileVars := template.StaticVariables{} for _, path := range pathsToVarsFiles { - rawVarsFile, ioerr := ioutil.ReadFile(path) + rawVarsFile, ioerr := os.ReadFile(path) if ioerr != nil { return nil, ioerr } diff --git a/util/manifestparser/parser_test.go b/util/manifestparser/parser_test.go index 98e29f7df20..6085ec3d862 100644 --- a/util/manifestparser/parser_test.go +++ b/util/manifestparser/parser_test.go @@ -2,7 +2,6 @@ package manifestparser_test import ( "errors" - "io/ioutil" "os" "path/filepath" @@ -28,7 +27,7 @@ var _ = Describe("ManifestParser", func() { ) BeforeEach(func() { - tempFile, err := ioutil.TempFile("", "manifest-test-") + tempFile, err := os.CreateTemp("", "manifest-test-") Expect(err).ToNot(HaveOccurred()) Expect(tempFile.Close()).ToNot(HaveOccurred()) pathToManifest = tempFile.Name() @@ -55,7 +54,7 @@ applications: - name: spark - name: flame `) - err := ioutil.WriteFile(pathToManifest, givenManifest, 0666) + err := os.WriteFile(pathToManifest, givenManifest, 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -76,7 +75,7 @@ applications: - name: ((var1)) - name: ((var2)) `) - err := ioutil.WriteFile(pathToManifest, givenManifest, 0666) + err := os.WriteFile(pathToManifest, givenManifest, 0666) Expect(err).ToNot(HaveOccurred()) }) @@ -87,15 +86,15 @@ applications: BeforeEach(func() { var err error - varsDir, err = ioutil.TempDir("", "vars-test") + varsDir, err = os.MkdirTemp("", "vars-test") Expect(err).ToNot(HaveOccurred()) varsFilePath1 := filepath.Join(varsDir, "vars-1") - err = ioutil.WriteFile(varsFilePath1, []byte("var1: spark"), 0666) + err = os.WriteFile(varsFilePath1, []byte("var1: spark"), 0666) Expect(err).ToNot(HaveOccurred()) varsFilePath2 := filepath.Join(varsDir, "vars-2") - err = ioutil.WriteFile(varsFilePath2, []byte("var2: flame"), 0666) + err = os.WriteFile(varsFilePath2, []byte("var2: flame"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = append(pathsToVarsFiles, varsFilePath1, varsFilePath2) @@ -108,11 +107,11 @@ applications: When("multiple values for the same variable(s) are provided", func() { BeforeEach(func() { varsFilePath1 := filepath.Join(varsDir, "vars-1") - err := ioutil.WriteFile(varsFilePath1, []byte("var1: garbageapp\nvar1: spark\nvar2: doesn't matter"), 0666) + err := os.WriteFile(varsFilePath1, []byte("var1: garbageapp\nvar1: spark\nvar2: doesn't matter"), 0666) Expect(err).ToNot(HaveOccurred()) varsFilePath2 := filepath.Join(varsDir, "vars-2") - err = ioutil.WriteFile(varsFilePath2, []byte("var2: flame"), 0666) + err = os.WriteFile(varsFilePath2, []byte("var2: flame"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = append(pathsToVarsFiles, varsFilePath1, varsFilePath2) @@ -140,7 +139,7 @@ applications: When("a variable in the manifest is not provided in the vars file", func() { BeforeEach(func() { varsFilePath := filepath.Join(varsDir, "vars-1") - err := ioutil.WriteFile(varsFilePath, []byte("notvar: foo"), 0666) + err := os.WriteFile(varsFilePath, []byte("notvar: foo"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = []string{varsFilePath} @@ -165,7 +164,7 @@ applications: When("the provided file is not a valid yaml file", func() { BeforeEach(func() { varsFilePath := filepath.Join(varsDir, "vars-1") - err := ioutil.WriteFile(varsFilePath, []byte(": bad"), 0666) + err := os.WriteFile(varsFilePath, []byte(": bad"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = []string{varsFilePath} @@ -200,12 +199,12 @@ applications: When("vars and vars files are provided", func() { var varsFilePath string BeforeEach(func() { - tmp, err := ioutil.TempFile("", "util-manifest-varsilfe") + tmp, err := os.CreateTemp("", "util-manifest-varsilfe") Expect(err).NotTo(HaveOccurred()) Expect(tmp.Close()).NotTo(HaveOccurred()) varsFilePath = tmp.Name() - err = ioutil.WriteFile(varsFilePath, []byte("var1: spark\nvar2: 12345"), 0666) + err = os.WriteFile(varsFilePath, []byte("var1: spark\nvar2: 12345"), 0666) Expect(err).ToNot(HaveOccurred()) pathsToVarsFiles = []string{varsFilePath} diff --git a/util/plugin/plugin.go b/util/plugin/plugin.go index 67ce1896bf7..b184d598df6 100644 --- a/util/plugin/plugin.go +++ b/util/plugin/plugin.go @@ -1,10 +1,9 @@ package plugin import ( - "os" - "errors" "fmt" + "os" plugin_transition "code.cloudfoundry.org/cli/plugin/transition" "code.cloudfoundry.org/cli/util/configv3" diff --git a/util/railway/railway_test.go b/util/railway/railway_test.go index a3caff336f7..bd191c33811 100644 --- a/util/railway/railway_test.go +++ b/util/railway/railway_test.go @@ -17,10 +17,11 @@ var _ = Describe("Sequentially()", func() { j = 0 ) - railway.Sequentially( + _, err := railway.Sequentially( func() (ccv3.Warnings, error) { i = 1; return ccv3.Warnings{}, nil }, func() (ccv3.Warnings, error) { j = 2; return ccv3.Warnings{}, nil }, ) + Expect(err).NotTo(HaveOccurred()) Expect(i).To(Equal(1)) Expect(j).To(Equal(2)) @@ -29,10 +30,11 @@ var _ = Describe("Sequentially()", func() { It("calls the tracks in order", func() { i := 0 - railway.Sequentially( + _, err := railway.Sequentially( func() (ccv3.Warnings, error) { i = 1; return ccv3.Warnings{}, nil }, func() (ccv3.Warnings, error) { i = 2; return ccv3.Warnings{}, nil }, ) + Expect(err).NotTo(HaveOccurred()) Expect(i).To(Equal(2)) }) diff --git a/util/randomword/generator.go b/util/randomword/generator.go index 7360b3e0fa8..404b777cb83 100644 --- a/util/randomword/generator.go +++ b/util/randomword/generator.go @@ -193,35 +193,36 @@ wolverine wombat zebra` -type Generator struct{} +type Generator struct { + r *rand.Rand +} func NewGenerator() Generator { - rand.Seed(time.Now().UnixNano()) - return Generator{} + return Generator{r: rand.New(rand.NewSource(time.Now().UnixNano()))} } func (gen Generator) Babble() string { return fmt.Sprintf("%s-%s-%s", gen.RandomAdjective(), gen.RandomNoun(), gen.RandomTwoLetters()) } -func (Generator) RandomAdjective() string { - return randomElement(adjectives) +func (gen Generator) RandomAdjective() string { + return randomElement(gen.r, adjectives) } -func (Generator) RandomNoun() string { - return randomElement(nouns) +func (gen Generator) RandomNoun() string { + return randomElement(gen.r, nouns) } -func (Generator) RandomTwoLetters() string { +func (gen Generator) RandomTwoLetters() string { var asciiLetterA = 97 - letterOne := string(rune(rand.Intn(26) + asciiLetterA)) - letterTwo := string(rune(rand.Intn(26) + asciiLetterA)) + letterOne := string(rune(gen.r.Intn(26) + asciiLetterA)) + letterTwo := string(rune(gen.r.Intn(26) + asciiLetterA)) return letterOne + letterTwo } -func randomElement(fullList string) string { +func randomElement(r *rand.Rand, fullList string) string { wordList := strings.Split(fullList, "\n") - randomWordIndex := rand.Int() % len(wordList) + randomWordIndex := r.Int() % len(wordList) return wordList[randomWordIndex] } diff --git a/util/tls_test.go b/util/tls_test.go index b176522447c..6ca055dda20 100644 --- a/util/tls_test.go +++ b/util/tls_test.go @@ -66,6 +66,7 @@ RVNEplh5ZEYbbWclddUBf46JPRU/eEu4JMqOJOykTdwbByFa3909Bzs= }) It("adds them to the trusted CAs", func() { + //nolint:staticcheck Expect(tlsConfig.RootCAs.Subjects()).To(ContainElement(ContainSubstring("Cloud Foundry"))) }) }) diff --git a/util/ui/request_logger_file_writer_test.go b/util/ui/request_logger_file_writer_test.go index 43d11b5530a..780497bec0d 100644 --- a/util/ui/request_logger_file_writer_test.go +++ b/util/ui/request_logger_file_writer_test.go @@ -3,7 +3,6 @@ package ui_test import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -32,7 +31,7 @@ var _ = Describe("Request Logger File Writer", func() { Describe("Valid file paths", func() { BeforeEach(func() { var err error - tmpdir, err = ioutil.TempDir("", "request_logger") + tmpdir, err = os.MkdirTemp("", "request_logger") Expect(err).ToNot(HaveOccurred()) logFile1 = filepath.Join(tmpdir, "tmp_sub_dir", "tmpfile1") @@ -53,11 +52,11 @@ var _ = Describe("Request Logger File Writer", func() { err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(RedactedValue + "\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(RedactedValue + "\n")) }) @@ -71,11 +70,11 @@ var _ = Describe("Request Logger File Writer", func() { err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("this is a dump of stuff\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("this is a dump of stuff\n")) }) @@ -96,7 +95,7 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - raw, err := ioutil.ReadFile(logFile1) + raw, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) contents := string(raw) @@ -105,7 +104,7 @@ Origin: wss://doppler.bosh-lite.com:443` Expect(contents).To(MatchRegexp(`Authorization: \[PRIVATE DATA HIDDEN\]`)) Expect(contents).To(MatchRegexp("Origin: wss://doppler.bosh-lite.com:443")) - raw, err = ioutil.ReadFile(logFile2) + raw, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) contents = string(raw) @@ -123,11 +122,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("Header: Value\n\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("Header: Value\n\n")) }) @@ -141,11 +140,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("Host: banana\n\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("Host: banana\n\n")) }) @@ -168,11 +167,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(formatted)) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(formatted)) }) @@ -186,11 +185,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("\n")) }) @@ -205,11 +204,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(raw + "\n\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(raw + "\n\n")) }) @@ -225,11 +224,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(ContainSubstring(msg)) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(ContainSubstring(msg)) }) @@ -243,11 +242,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("GET /v2/spaces/guid/summary HTTP/1.1\n\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("GET /v2/spaces/guid/summary HTTP/1.1\n\n")) }) @@ -261,11 +260,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("HTTP/1.1 200 OK\n\n")) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal("HTTP/1.1 200 OK\n\n")) }) @@ -280,11 +279,11 @@ Origin: wss://doppler.bosh-lite.com:443` err = display.Stop() Expect(err).ToNot(HaveOccurred()) - contents, err := ioutil.ReadFile(logFile1) + contents, err := os.ReadFile(logFile1) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(fmt.Sprintf("banana: [%s]\n\n", passedTime.Format(time.RFC3339)))) - contents, err = ioutil.ReadFile(logFile2) + contents, err = os.ReadFile(logFile2) Expect(err).ToNot(HaveOccurred()) Expect(string(contents)).To(Equal(fmt.Sprintf("banana: [%s]\n\n", passedTime.Format(time.RFC3339)))) }) @@ -325,7 +324,7 @@ Origin: wss://doppler.bosh-lite.com:443` BeforeEach(func() { var err error - tmpdir, err = ioutil.TempDir("", "request_logger") + tmpdir, err = os.MkdirTemp("", "request_logger") Expect(err).ToNot(HaveOccurred()) pathName = filepath.Join(tmpdir, "foo") diff --git a/util/ui/ui_test.go b/util/ui/ui_test.go index deab14aefd7..442d49c9d11 100644 --- a/util/ui/ui_test.go +++ b/util/ui/ui_test.go @@ -197,7 +197,7 @@ var _ = Describe("UI", func() { "arr": []string{"a", "b"}, } - ui.DisplayJSON("named_json", obj) + Expect(ui.DisplayJSON("named_json", obj)).To(Succeed()) Expect(out).To(SatisfyAll( Say("named_json: {\n"),