Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions internal/pidfile/pidfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package pidfile

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -18,7 +17,7 @@ type PIDFile struct {
}

func checkPIDFileAlreadyExists(path string) error {
if pidByte, err := ioutil.ReadFile(path); err == nil {
if pidByte, err := os.ReadFile(path); err == nil {
pidString := strings.TrimSpace(string(pidByte))
if pid, err := strconv.Atoi(pidString); err == nil {
if processExists(pid) {
Expand All @@ -38,7 +37,7 @@ func New(path string) (*PIDFile, error) {
if err := MkdirAll(filepath.Dir(path), os.FileMode(0o755)); err != nil {
return nil, err
}
if err := ioutil.WriteFile(path, []byte(fmt.Sprintf("%d", os.Getpid())), 0o600); err != nil {
if err := os.WriteFile(path, []byte(fmt.Sprintf("%d", os.Getpid())), 0o600); err != nil {
return nil, err
}

Expand Down
3 changes: 1 addition & 2 deletions internal/pidfile/pidfile_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package pidfile

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

func TestNewAndRemove(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "test-pidfile")
dir, err := os.MkdirTemp(os.TempDir(), "test-pidfile")
if err != nil {
t.Fatal("Could not create test directory")
}
Expand Down
3 changes: 1 addition & 2 deletions testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ package main

import (
"context"
"io/ioutil"
"net"
"net/http"
"os"
"path"
)

func prepareTestSocket(_ string) (socketPath string, transport *http.Transport, cleanup func(), err error) {
tmp, err := ioutil.TempDir("", "webhook-socket-")
tmp, err := os.MkdirTemp("", "webhook-socket-")
if err != nil {
return "", nil, nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -172,7 +172,7 @@ func main() {
}

if !*verbose {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}

// Create pidfile
Expand Down Expand Up @@ -379,7 +379,7 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
isMultipart := strings.HasPrefix(req.ContentType, "multipart/form-data;")

if !isMultipart {
req.Body, err = ioutil.ReadAll(r.Body)
req.Body, err = io.ReadAll(r.Body)
if err != nil {
log.Printf("[%s] error reading the request body: %+v\n", req.ID, err)
}
Expand Down Expand Up @@ -608,7 +608,7 @@ func handleHook(h *hook.Hook, r *hook.Request) (string, error) {
}

for i := range files {
tmpfile, err := ioutil.TempFile(h.CommandWorkingDirectory, files[i].EnvName)
tmpfile, err := os.CreateTemp(h.CommandWorkingDirectory, files[i].EnvName)
if err != nil {
log.Printf("[%s] error creating temp file [%s]", r.ID, err)
continue
Expand Down
14 changes: 7 additions & 7 deletions webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -34,7 +34,7 @@ func TestStaticParams(t *testing.T) {

// case 2: binary with spaces in its name
d1 := []byte("#!/bin/sh\n/bin/echo\n")
err := ioutil.WriteFile("/tmp/with space", d1, 0755)
err := os.WriteFile("/tmp/with space", d1, 0755)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestWebhook(t *testing.T) {

url := fmt.Sprintf("http://%s/hooks/%s", authority, tt.id)

req, err := http.NewRequest(tt.method, url, ioutil.NopCloser(strings.NewReader(tt.body)))
req, err := http.NewRequest(tt.method, url, io.NopCloser(strings.NewReader(tt.body)))
if err != nil {
t.Errorf("New request failed: %s", err)
}
Expand All @@ -122,7 +122,7 @@ func TestWebhook(t *testing.T) {
t.Errorf("client.Do failed: %s", err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Errorf("POST %q: failed to ready body: %s", tt.desc, err)
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestWebhook(t *testing.T) {
}

func buildHookecho(t *testing.T) (binPath string, cleanupFn func()) {
tmp, err := ioutil.TempDir("", "hookecho-test-")
tmp, err := os.MkdirTemp("", "hookecho-test-")
if err != nil {
t.Fatal(err)
}
Expand All @@ -226,7 +226,7 @@ func buildHookecho(t *testing.T) (binPath string, cleanupFn func()) {
func genConfig(t *testing.T, bin, hookTemplate string) (configPath string, cleanupFn func()) {
tmpl := template.Must(template.ParseFiles(hookTemplate))

tmp, err := ioutil.TempDir("", "webhook-config-")
tmp, err := os.MkdirTemp("", "webhook-config-")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func genConfig(t *testing.T, bin, hookTemplate string) (configPath string, clean
}

func buildWebhook(t *testing.T) (binPath string, cleanupFn func()) {
tmp, err := ioutil.TempDir("", "webhook-test-")
tmp, err := os.MkdirTemp("", "webhook-test-")
if err != nil {
t.Fatal(err)
}
Expand Down