Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

mockgen: replace io/ioutil with io and os package #676

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
7 changes: 3 additions & 4 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"fmt"
"go/token"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -149,7 +148,7 @@ func main() {
g.mockNames = parseMockNames(*mockNames)
}
if *copyrightFile != "" {
header, err := ioutil.ReadFile(*copyrightFile)
header, err := os.ReadFile(*copyrightFile)
if err != nil {
log.Fatalf("Failed reading copyright file: %v", err)
}
Expand All @@ -165,7 +164,7 @@ func main() {
if err := os.MkdirAll(filepath.Dir(*destination), os.ModePerm); err != nil {
log.Fatalf("Unable to create directory: %v", err)
}
existing, err := ioutil.ReadFile(*destination)
existing, err := os.ReadFile(*destination)
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatalf("Failed reading pre-exiting destination file: %v", err)
}
Expand Down Expand Up @@ -704,7 +703,7 @@ func parsePackageImport(srcDir string) (string, error) {
if moduleMode != "off" {
currentDir := srcDir
for {
dat, err := ioutil.ReadFile(filepath.Join(currentDir, "go.mod"))
dat, err := os.ReadFile(filepath.Join(currentDir, "go.mod"))
if os.IsNotExist(err) {
if currentDir == filepath.Dir(currentDir) {
// at the root
Expand Down
7 changes: 3 additions & 4 deletions mockgen/mockgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -369,7 +368,7 @@ func Test_createPackageMap(t *testing.T) {
}

func TestParsePackageImport_FallbackGoPath(t *testing.T) {
goPath, err := ioutil.TempDir("", "gopath")
goPath, err := os.MkdirTemp("", "gopath")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -404,7 +403,7 @@ func TestParsePackageImport_FallbackMultiGoPath(t *testing.T) {
var goPathList []string

// first gopath
goPath, err := ioutil.TempDir("", "gopath1")
goPath, err := os.MkdirTemp("", "gopath1")
if err != nil {
t.Error(err)
}
Expand All @@ -421,7 +420,7 @@ func TestParsePackageImport_FallbackMultiGoPath(t *testing.T) {
}

// second gopath
goPath, err = ioutil.TempDir("", "gopath2")
goPath, err = os.MkdirTemp("", "gopath2")
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions mockgen/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"go/parser"
"go/token"
"go/types"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -701,7 +701,7 @@ func isVariadic(f *ast.FuncType) bool {

// packageNameOfDir get package import path via dir
func packageNameOfDir(srcDir string) (string, error) {
files, err := ioutil.ReadDir(srcDir)
files, err := os.ReadDir(srcDir)
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions mockgen/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -92,7 +91,7 @@ func writeProgram(importPath string, symbols []string) ([]byte, error) {

// run the given program and parse the output as a model.Package.
func run(program string) (*model.Package, error) {
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -133,7 +132,7 @@ func run(program string) (*model.Package, error) {
// parses the output as a model.Package.
func runInDir(program []byte, dir string) (*model.Package, error) {
// We use TempDir instead of TempFile so we can control the filename.
tmpDir, err := ioutil.TempDir(dir, "gomock_reflect_")
tmpDir, err := os.MkdirTemp(dir, "gomock_reflect_")
if err != nil {
return nil, err
}
Expand All @@ -149,7 +148,7 @@ func runInDir(program []byte, dir string) (*model.Package, error) {
progBinary += ".exe"
}

if err := ioutil.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil {
if err := os.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil {
return nil, err
}

Expand Down