Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move from io/ioutil to io and os packages #1253

Merged
merged 1 commit into from
Dec 4, 2021
Merged
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
4 changes: 2 additions & 2 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cmd

import (
"io/ioutil"
"io"
"log"
"os"
"testing"
)

func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}
8 changes: 4 additions & 4 deletions integrationtest/bundled/bundled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"os/exec"
Expand All @@ -19,7 +19,7 @@ import (
)

func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}

Expand Down Expand Up @@ -116,9 +116,9 @@ func TestBundledPlugin(t *testing.T) {
var b []byte
var err error
if runtime.GOOS == "windows" && IsWindowsResultExist() {
b, err = ioutil.ReadFile(filepath.Join(testDir, "result_windows.json"))
b, err = os.ReadFile(filepath.Join(testDir, "result_windows.json"))
} else {
b, err = ioutil.ReadFile(filepath.Join(testDir, "result.json"))
b, err = os.ReadFile(filepath.Join(testDir, "result.json"))
}
if err != nil {
t.Fatal(err)
Expand Down
8 changes: 4 additions & 4 deletions integrationtest/inspection/inspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand All @@ -18,7 +18,7 @@ import (
)

func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}

Expand Down Expand Up @@ -127,9 +127,9 @@ func TestIntegration(t *testing.T) {
var b []byte
var err error
if runtime.GOOS == "windows" && IsWindowsResultExist() {
b, err = ioutil.ReadFile(filepath.Join(testDir, "result_windows.json"))
b, err = os.ReadFile(filepath.Join(testDir, "result_windows.json"))
} else {
b, err = ioutil.ReadFile(filepath.Join(testDir, "result.json"))
b, err = os.ReadFile(filepath.Join(testDir, "result.json"))
}
if err != nil {
t.Fatal(err)
Expand Down
3 changes: 1 addition & 2 deletions integrationtest/langserver/langserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -118,7 +117,7 @@ func withinTempDir(t *testing.T, test func(dir string)) {
}
}()

dir, err := ioutil.TempDir("", "withinTempDir")
dir, err := os.MkdirTemp("", "withinTempDir")
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions integrationtest/langserver/text_document_did_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -13,7 +13,7 @@ import (

func Test_textDocumentDidChange(t *testing.T) {
withinFixtureDir(t, "workdir", func(dir string) {
src, err := ioutil.ReadFile(dir + "/main.tf")
src, err := os.ReadFile(dir + "/main.tf")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -66,7 +66,7 @@ resource "aws_instance" "foo" {
}

// Assert no changes for actual files
changedSrc, err := ioutil.ReadFile(dir + "/main.tf")
changedSrc, err := os.ReadFile(dir + "/main.tf")
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions integrationtest/langserver/text_document_did_open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -13,7 +13,7 @@ import (

func Test_textDocumentDidOpen(t *testing.T) {
withinFixtureDir(t, "workdir", func(dir string) {
src, err := ioutil.ReadFile(dir + "/main.tf")
src, err := os.ReadFile(dir + "/main.tf")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func didOpenResponse(uri lsp.DocumentURI, t *testing.T) string {

func Test_textDocumentDidOpen_pathFunctions(t *testing.T) {
withinFixtureDir(t, "path_functions", func(dir string) {
src, err := ioutil.ReadFile(dir + "/main.tf")
src, err := os.ReadFile(dir + "/main.tf")
if err != nil {
t.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -41,10 +40,10 @@ rule "aws_instance_example_type" {
enabled = false
}`

if err := ioutil.WriteFile(dir+"/main.tf", []byte(content), os.ModePerm); err != nil {
if err := os.WriteFile(dir+"/main.tf", []byte(content), os.ModePerm); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(dir+"/.tflint.hcl", []byte(config), os.ModePerm); err != nil {
if err := os.WriteFile(dir+"/.tflint.hcl", []byte(config), os.ModePerm); err != nil {
t.Fatal(err)
}
uri := pathToURI(dir + "/main.tf")
Expand Down Expand Up @@ -73,7 +72,7 @@ rule "aws_instance_example_type" {
fmt.Fprint(stdin, initializeRequest())
fmt.Fprint(stdin, didOpenRequest(uri, content, t))
// Change config file from outside of LSP
_ = ioutil.WriteFile(dir+"/.tflint.hcl", []byte(changedConfig), os.ModePerm)
_ = os.WriteFile(dir+"/.tflint.hcl", []byte(changedConfig), os.ModePerm)
fmt.Fprint(stdin, toJSONRPC2(string(req)))
fmt.Fprint(stdin, shutdownRequest())
fmt.Fprint(stdin, exitRequest())
Expand All @@ -100,15 +99,15 @@ resource "aws_instance" "foo" {
variable "instance_type" {}
`

if err := ioutil.WriteFile(dir+"/main.tf", []byte(content), os.ModePerm); err != nil {
if err := os.WriteFile(dir+"/main.tf", []byte(content), os.ModePerm); err != nil {
t.Fatal(err)
}
uri := pathToURI(dir + "/main.tf")

valueFile := `
instance_type = "t1.2xlarge"
`
if err := ioutil.WriteFile(dir+"/terraform.tfvars", []byte(valueFile), os.ModePerm); err != nil {
if err := os.WriteFile(dir+"/terraform.tfvars", []byte(valueFile), os.ModePerm); err != nil {
t.Fatal(err)
}

Expand All @@ -120,7 +119,7 @@ plugin "testing" {
plugin "aws" {
enabled = false
}`
if err := ioutil.WriteFile(dir+"/.tflint.hcl", []byte(config), os.ModePerm); err != nil {
if err := os.WriteFile(dir+"/.tflint.hcl", []byte(config), os.ModePerm); err != nil {
t.Fatal(err)
}

Expand Down
3 changes: 1 addition & 2 deletions plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -182,7 +181,7 @@ func (c *InstallConfig) downloadToTempFile(asset *github.ReleaseAsset) (*os.File
return nil, err
}

file, err := ioutil.TempFile("", "tflint-download-temp-file-*")
file, err := os.CreateTemp("", "tflint-download-temp-file-*")
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions rules/terraformrules/terraform_module_pinned_source_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package terraformrules

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -538,7 +537,7 @@ func loadConfigfromTempFile(t *testing.T, content string) *tflint.Config {
return tflint.EmptyConfig()
}

tmpfile, err := ioutil.TempFile("", "terraform_module_pinned_source")
tmpfile, err := os.CreateTemp("", "terraform_module_pinned_source")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions rules/terraformrules/terraform_module_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package terraformrules

import (
"fmt"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -241,7 +240,7 @@ func loadConfigfromModuleVersionTempFile(t *testing.T, content string) *tflint.C
return tflint.EmptyConfig()
}

tmpfile, err := ioutil.TempFile("", "terraform_module_version")
tmpfile, err := os.CreateTemp("", "terraform_module_version")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions rules/terraformrules/terraform_naming_convention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package terraformrules

import (
"fmt"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -2899,7 +2898,7 @@ func loadConfigFromNamingConventionTempFile(t *testing.T, content string) *tflin
return tflint.EmptyConfig()
}

tmpfile, err := ioutil.TempFile("", "terraform_naming_convention")
tmpfile, err := os.CreateTemp("", "terraform_naming_convention")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions rules/terraformrules/terraformrules_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package terraformrules

import (
"io/ioutil"
"io"
"log"
"os"
"testing"
)

func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}
4 changes: 2 additions & 2 deletions terraform/lang/funcs/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package funcs
import (
"encoding/base64"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"unicode/utf8"
Expand Down Expand Up @@ -378,7 +378,7 @@ func readFileBytes(baseDir, path string) ([]byte, error) {
return nil, err
}

src, err := ioutil.ReadAll(f)
src, err := io.ReadAll(f)
if err != nil {
return nil, fmt.Errorf("failed to read %s", path)
}
Expand Down
3 changes: 1 addition & 2 deletions tflint/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tflint

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -24,7 +23,7 @@ func Test_NewAnnotations(t *testing.T) {
}
}()

src, err := ioutil.ReadFile(filepath.Join(currentDir, "test-fixtures", "annotations", "resource.tf"))
src, err := os.ReadFile(filepath.Join(currentDir, "test-fixtures", "annotations", "resource.tf"))
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions tflint/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tflint
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -136,7 +135,7 @@ func getTFWorkspace() string {
return envVar
}

envData, _ := ioutil.ReadFile(filepath.Join(getTFDataDir(), "environment"))
envData, _ := os.ReadFile(filepath.Join(getTFDataDir(), "environment"))
current := string(bytes.TrimSpace(envData))
if current != "" {
log.Printf("[INFO] environment file found: %s", current)
Expand Down
4 changes: 2 additions & 2 deletions tflint/tflint_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tflint

import (
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand All @@ -13,7 +13,7 @@ import (
)

func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}

Expand Down