Skip to content

Commit

Permalink
Remove usage of deprecated io/ioutil and upgrade to Go 1.16 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo authored Dec 3, 2023
1 parent e308da9 commit 3570aa7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 30 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,19 @@ jobs:
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage
uses: codecov/codecov-action@v1
build_1_12:
name: Build with Go 1.12.17
build_1_16:
name: Build with Go 1.16
runs-on: ubuntu-latest
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'pull_request'
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.12.17'
go-version: '1.16'
- name: Git checkout
uses: actions/checkout@v3
with:
path: gopath/src/github.com/nicksnyder/go-i18n
- name: Build and test
working-directory: gopath/src/github.com/nicksnyder/go-i18n/v2
env:
GOPATH: ${{ github.workspace }}/gopath
GO111MODULE: on
working-directory: v2
run: |
go get ./...
go test -race ./...
2 changes: 1 addition & 1 deletion v2/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nicksnyder/go-i18n/v2

go 1.12
go 1.16

require (
github.com/BurntSushi/toml v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions v2/goi18n/common_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import "io/ioutil"
import "os"

func mustTempDir(prefix string) string {
outdir, err := ioutil.TempDir("", prefix)
outdir, err := os.MkdirTemp("", prefix)
if err != nil {
panic(err)
}
Expand Down
5 changes: 2 additions & 3 deletions v2/goi18n/extract_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (ec *extractCommand) execute() error {
return nil
}

buf, err := ioutil.ReadFile(path)
buf, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -113,7 +112,7 @@ func (ec *extractCommand) execute() error {
if err != nil {
return err
}
return ioutil.WriteFile(path, content, 0666)
return os.WriteFile(path, content, 0666)
}

// extractMessages extracts messages from the bytes of a Go source file.
Expand Down
12 changes: 5 additions & 7 deletions v2/goi18n/extract_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package main

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

func TestExtract(t *testing.T) {

tests := []struct {
name string
fileName string
Expand Down Expand Up @@ -258,15 +256,15 @@ zero = "Zero translation"
defer os.RemoveAll(outdir)

inpath := filepath.Join(indir, test.fileName)
if err := ioutil.WriteFile(inpath, []byte(test.file), 0666); err != nil {
if err := os.WriteFile(inpath, []byte(test.file), 0666); err != nil {
t.Fatal(err)
}

if code := testableMain([]string{"extract", "-outdir", outdir, indir}); code != 0 {
t.Fatalf("expected exit code 0; got %d\n", code)
}

files, err := ioutil.ReadDir(outdir)
files, err := os.ReadDir(outdir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -280,7 +278,7 @@ zero = "Zero translation"
}

outpath := filepath.Join(outdir, actualFile.Name())
actual, err := ioutil.ReadFile(outpath)
actual, err := os.ReadFile(outpath)
if err != nil {
t.Fatal(err)
}
Expand All @@ -292,15 +290,15 @@ zero = "Zero translation"
}

func TestExtractCommand(t *testing.T) {
outdir, err := ioutil.TempDir("", "TestExtractCommand")
outdir, err := os.MkdirTemp("", "TestExtractCommand")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(outdir)
if code := testableMain([]string{"extract", "-outdir", outdir, "../example/"}); code != 0 {
t.Fatalf("expected exit code 0; got %d", code)
}
actual, err := ioutil.ReadFile(filepath.Join(outdir, "active.en.toml"))
actual, err := os.ReadFile(filepath.Join(outdir, "active.en.toml"))
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions v2/goi18n/merge_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -83,7 +82,7 @@ func (mc *mergeCommand) execute() error {
}
inFiles := make(map[string][]byte)
for _, path := range mc.messageFiles {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -94,7 +93,7 @@ func (mc *mergeCommand) execute() error {
return err
}
for path, content := range ops.writeFiles {
if err := ioutil.WriteFile(path, content, 0666); err != nil {
if err := os.WriteFile(path, content, 0666); err != nil {
return err
}
}
Expand Down
9 changes: 4 additions & 5 deletions v2/goi18n/merge_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -539,14 +538,14 @@ zero = "{{.Count}} unread emails"
for name, content := range testCase.inFiles {
path := filepath.Join(indir, name)
infiles = append(infiles, path)
if err := ioutil.WriteFile(path, content, 0666); err != nil {
if err := os.WriteFile(path, content, 0666); err != nil {
t.Fatal(err)
}
}

for _, name := range testCase.deleteFiles {
path := filepath.Join(outdir, name)
if err := ioutil.WriteFile(path, []byte(`this file should get deleted`), 0666); err != nil {
if err := os.WriteFile(path, []byte(`this file should get deleted`), 0666); err != nil {
t.Fatal(err)
}
}
Expand All @@ -556,7 +555,7 @@ zero = "{{.Count}} unread emails"
t.Fatalf("expected exit code 0; got %d\n", code)
}

files, err := ioutil.ReadDir(outdir)
files, err := os.ReadDir(outdir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -570,7 +569,7 @@ zero = "{{.Count}} unread emails"
continue
}
path := filepath.Join(outdir, f.Name())
actual, err := ioutil.ReadFile(path)
actual, err := os.ReadFile(path)
if err != nil {
t.Error(err)
continue
Expand Down

0 comments on commit 3570aa7

Please sign in to comment.