mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
internal/initwd: deprecate io/ioutil (#343)
Signed-off-by: Lars Lehtonen <lars.lehtonen@gmail.com>
This commit is contained in:
parent
40d6b4bd86
commit
07471df9d3
@ -6,7 +6,6 @@ package initwd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -59,7 +58,7 @@ func DirFromModule(ctx context.Context, loader *configload.Loader, rootDir, modu
|
|||||||
|
|
||||||
// The target directory must exist but be empty.
|
// The target directory must exist but be empty.
|
||||||
{
|
{
|
||||||
entries, err := ioutil.ReadDir(rootDir)
|
entries, err := os.ReadDir(rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
diags = diags.Append(tfdiags.Sourceless(
|
diags = diags.Append(tfdiags.Sourceless(
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -151,12 +150,12 @@ func TestModuleInstaller_packageEscapeError(t *testing.T) {
|
|||||||
// %%BASE%% with the temporary directory path.
|
// %%BASE%% with the temporary directory path.
|
||||||
{
|
{
|
||||||
rootFilename := filepath.Join(dir, "package-escape.tf")
|
rootFilename := filepath.Join(dir, "package-escape.tf")
|
||||||
template, err := ioutil.ReadFile(rootFilename)
|
template, err := os.ReadFile(rootFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
final := bytes.ReplaceAll(template, []byte("%%BASE%%"), []byte(filepath.ToSlash(dir)))
|
final := bytes.ReplaceAll(template, []byte("%%BASE%%"), []byte(filepath.ToSlash(dir)))
|
||||||
err = ioutil.WriteFile(rootFilename, final, 0644)
|
err = os.WriteFile(rootFilename, final, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -189,12 +188,12 @@ func TestModuleInstaller_explicitPackageBoundary(t *testing.T) {
|
|||||||
// %%BASE%% with the temporary directory path.
|
// %%BASE%% with the temporary directory path.
|
||||||
{
|
{
|
||||||
rootFilename := filepath.Join(dir, "package-prefix.tf")
|
rootFilename := filepath.Join(dir, "package-prefix.tf")
|
||||||
template, err := ioutil.ReadFile(rootFilename)
|
template, err := os.ReadFile(rootFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
final := bytes.ReplaceAll(template, []byte("%%BASE%%"), []byte(filepath.ToSlash(dir)))
|
final := bytes.ReplaceAll(template, []byte("%%BASE%%"), []byte(filepath.ToSlash(dir)))
|
||||||
err = ioutil.WriteFile(rootFilename, final, 0644)
|
err = os.WriteFile(rootFilename, final, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -897,7 +896,7 @@ func (h *testInstallHooks) Install(moduleAddr string, version *version.Version,
|
|||||||
func tempChdir(t *testing.T, sourceDir string) (string, func()) {
|
func tempChdir(t *testing.T, sourceDir string) (string, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "terraform-configload")
|
tmpDir, err := os.MkdirTemp("", "terraform-configload")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create temporary directory: %s", err)
|
t.Fatalf("failed to create temporary directory: %s", err)
|
||||||
return "", nil
|
return "", nil
|
||||||
|
Loading…
Reference in New Issue
Block a user