Skip to content

Commit

Permalink
Replace use of io/ioutil with their alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
chitoku-k authored and benjaminguttmann-avtq committed Aug 11, 2022
1 parent ae07455 commit 18621cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions collectors/bosh_collector_test.go
Expand Up @@ -2,7 +2,6 @@ package collectors_test

import (
"errors"
"io/ioutil"
"os"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -56,7 +55,7 @@ var _ = Describe("BoshCollector", func() {
environment = "test_environment"
boshName = "test_bosh_name"
boshUUID = "test_bosh_uuid"
tmpfile, err = ioutil.TempFile("", "service_discovery_collector_test_")
tmpfile, err = os.CreateTemp("", "service_discovery_collector_test_")
Expect(err).ToNot(HaveOccurred())
serviceDiscoveryFilename = tmpfile.Name()

Expand Down
3 changes: 1 addition & 2 deletions collectors/service_discovery_collector.go
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"sync"
Expand Down Expand Up @@ -182,7 +181,7 @@ func (c *ServiceDiscoveryCollector) writeTargetGroupsToFile(targetGroups TargetG
}

dir, name := path.Split(c.serviceDiscoveryFilename)
f, err := ioutil.TempFile(dir, name)
f, err := os.CreateTemp(dir, name)
if err != nil {
return errors.New(fmt.Sprintf("Error creating temp file: %v", err))
}
Expand Down
15 changes: 7 additions & 8 deletions collectors/service_discovery_collector_test.go
@@ -1,7 +1,6 @@
package collectors_test

import (
"io/ioutil"
"os"

. "github.com/benjamintf1/unmarshalledmatchers"
Expand Down Expand Up @@ -44,7 +43,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() {
environment = "test_environment"
boshName = "test_bosh_name"
boshUUID = "test_bosh_uuid"
tmpfile, err = ioutil.TempFile("", "service_discovery_collector_test_")
tmpfile, err = os.CreateTemp("", "service_discovery_collector_test_")
Expect(err).ToNot(HaveOccurred())
serviceDiscoveryFilename = tmpfile.Name()
azsFilter = filters.NewAZsFilter([]string{})
Expand Down Expand Up @@ -209,7 +208,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() {

It("writes a target groups file", func() {
Eventually(metrics).Should(Receive())
targetGroups, err := ioutil.ReadFile(serviceDiscoveryFilename)
targetGroups, err := os.ReadFile(serviceDiscoveryFilename)
Expect(err).ToNot(HaveOccurred())
Expect(string(targetGroups)).To(MatchUnorderedJSON(targetGroupsContent))
})
Expand All @@ -228,7 +227,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() {

It("writes an empty target groups file", func() {
Eventually(metrics).Should(Receive())
targetGroups, err := ioutil.ReadFile(serviceDiscoveryFilename)
targetGroups, err := os.ReadFile(serviceDiscoveryFilename)
Expect(err).ToNot(HaveOccurred())
Expect(string(targetGroups)).To(Equal("[]"))
})
Expand All @@ -249,7 +248,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() {

It("writes an empty target groups file", func() {
Eventually(metrics).Should(Receive())
targetGroups, err := ioutil.ReadFile(serviceDiscoveryFilename)
targetGroups, err := os.ReadFile(serviceDiscoveryFilename)
Expect(err).ToNot(HaveOccurred())
Expect(string(targetGroups)).To(Equal("[]"))
})
Expand All @@ -270,7 +269,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() {

It("writes an empty target groups file", func() {
Eventually(metrics).Should(Receive())
targetGroups, err := ioutil.ReadFile(serviceDiscoveryFilename)
targetGroups, err := os.ReadFile(serviceDiscoveryFilename)
Expect(err).ToNot(HaveOccurred())
Expect(string(targetGroups)).To(Equal("[]"))
})
Expand All @@ -290,7 +289,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() {

It("writes an empty target groups file", func() {
Eventually(metrics).Should(Receive())
targetGroups, err := ioutil.ReadFile(serviceDiscoveryFilename)
targetGroups, err := os.ReadFile(serviceDiscoveryFilename)
Expect(err).ToNot(HaveOccurred())
Expect(string(targetGroups)).To(Equal("[]"))
})
Expand All @@ -311,7 +310,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() {

It("writes an empty target groups file", func() {
Eventually(metrics).Should(Receive())
targetGroups, err := ioutil.ReadFile(serviceDiscoveryFilename)
targetGroups, err := os.ReadFile(serviceDiscoveryFilename)
Expect(err).ToNot(HaveOccurred())
Expect(string(targetGroups)).To(Equal("[]"))
})
Expand Down

0 comments on commit 18621cd

Please sign in to comment.