Skip to content

Commit

Permalink
Remove deprecated ioutil calls
Browse files Browse the repository at this point in the history
Replaced with `os` package. Also uses t.TempDir in tests over MkDirTemp
  • Loading branch information
arbourd committed Apr 4, 2024
1 parent 37d3ea5 commit a628f16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 3 additions & 4 deletions out/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand All @@ -23,7 +22,7 @@ func buildMessage(alert Alert, m concourse.BuildMetadata, path string) *slack.Me
// Open and read message file if set
if alert.MessageFile != "" {
file := filepath.Join(path, alert.MessageFile)
f, err := ioutil.ReadFile(file)
f, err := os.ReadFile(file)

if err != nil {
fmt.Fprintf(os.Stderr, "error reading message_file: %v\nwill default to message instead\n", err)
Expand All @@ -35,7 +34,7 @@ func buildMessage(alert Alert, m concourse.BuildMetadata, path string) *slack.Me
// Open and read channel file if set
if alert.ChannelFile != "" {
file := filepath.Join(path, alert.ChannelFile)
f, err := ioutil.ReadFile(file)
f, err := os.ReadFile(file)

if err != nil {
fmt.Fprintf(os.Stderr, "error reading channel_file: %v\nwill default to channel instead\n", err)
Expand All @@ -47,7 +46,7 @@ func buildMessage(alert Alert, m concourse.BuildMetadata, path string) *slack.Me
// Open and read text file if set
if alert.TextFile != "" {
file := filepath.Join(path, alert.TextFile)
f, err := ioutil.ReadFile(file)
f, err := os.ReadFile(file)

if err != nil {
fmt.Fprintf(os.Stderr, "error reading text_file: %v\nwill default to text instead\n", err)
Expand Down
10 changes: 2 additions & 8 deletions out/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -354,14 +353,9 @@ func TestBuildMessage(t *testing.T) {
t.Run(name, func(t *testing.T) {
path := ""
if c.alert.MessageFile != "" || c.alert.ChannelFile != "" {
dir, err := ioutil.TempDir("", "example")
if err != nil {
t.Fatal(err)
}
path = dir
path = t.TempDir()

defer os.RemoveAll(dir)
if err := ioutil.WriteFile(filepath.Join(dir, "test_file"), []byte("filecontents"), 0666); err != nil {
if err := os.WriteFile(filepath.Join(path, "test_file"), []byte("filecontents"), 0666); err != nil {
t.Fatal(err)
}
}
Expand Down

0 comments on commit a628f16

Please sign in to comment.