Update to go1.16
This commit is contained in:
parent
2e7833df49
commit
bdba7d3adf
62 changed files with 217 additions and 318 deletions
|
@ -2,7 +2,7 @@ package acme
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
|
@ -60,7 +60,7 @@ func (s *LocalStore) get(resolverName string) (*StoredData, error) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
file, err := ioutil.ReadAll(f)
|
||||
file, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func (s *LocalStore) listenSaveAction() {
|
|||
logger.Error(err)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(s.filename, data, 0o600)
|
||||
err = os.WriteFile(s.filename, data, 0o600)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package acme
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -23,7 +23,7 @@ func TestLocalStore_GetAccount(t *testing.T) {
|
|||
}
|
||||
}`, email)
|
||||
|
||||
err := ioutil.WriteFile(acmeFile, []byte(filePayload), 0o600)
|
||||
err := os.WriteFile(acmeFile, []byte(filePayload), 0o600)
|
||||
require.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
|
@ -68,7 +68,7 @@ func TestLocalStore_SaveAccount(t *testing.T) {
|
|||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
file, err := ioutil.ReadFile(acmeFile)
|
||||
file, err := os.ReadFile(acmeFile)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := `{
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -197,7 +196,7 @@ func flattenCertificates(ctx context.Context, tlsConfig *dynamic.TLSConfiguratio
|
|||
}
|
||||
|
||||
func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory string, configuration *dynamic.Configuration) (*dynamic.Configuration, error) {
|
||||
fileList, err := ioutil.ReadDir(directory)
|
||||
fileList, err := os.ReadDir(directory)
|
||||
if err != nil {
|
||||
return configuration, fmt.Errorf("unable to read directory %s: %w", directory, err)
|
||||
}
|
||||
|
@ -436,7 +435,7 @@ func (p *Provider) decodeConfiguration(filePath, content string) (*dynamic.Confi
|
|||
|
||||
func readFile(filename string) (string, error) {
|
||||
if len(filename) > 0 {
|
||||
buf, err := ioutil.ReadFile(filename)
|
||||
buf, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package file
|
|||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -27,13 +26,12 @@ type ProvideTestCase struct {
|
|||
}
|
||||
|
||||
func TestTLSContent(t *testing.T) {
|
||||
tempDir := createTempDir(t, "testdir")
|
||||
defer os.RemoveAll(tempDir)
|
||||
tempDir := t.TempDir()
|
||||
|
||||
fileTLS, err := createTempFile("./fixtures/toml/tls_file.cert", tempDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileConfig, err := ioutil.TempFile(tempDir, "temp*.toml")
|
||||
fileConfig, err := os.CreateTemp(tempDir, "temp*.toml")
|
||||
require.NoError(t, err)
|
||||
|
||||
content := `
|
||||
|
@ -245,7 +243,7 @@ func getTestCases() []ProvideTestCase {
|
|||
func createProvider(t *testing.T, test ProvideTestCase, watch bool) *Provider {
|
||||
t.Helper()
|
||||
|
||||
tempDir := createTempDir(t, "testdir")
|
||||
tempDir := t.TempDir()
|
||||
|
||||
provider := &Provider{}
|
||||
provider.Watch = true
|
||||
|
@ -265,7 +263,7 @@ func createProvider(t *testing.T, test ProvideTestCase, watch bool) *Provider {
|
|||
var file *os.File
|
||||
if watch {
|
||||
var err error
|
||||
file, err = ioutil.TempFile(tempDir, "temp*"+filepath.Ext(test.filePath))
|
||||
file, err = os.CreateTemp(tempDir, "temp*"+filepath.Ext(test.filePath))
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
var err error
|
||||
|
@ -283,17 +281,6 @@ func createProvider(t *testing.T, test ProvideTestCase, watch bool) *Provider {
|
|||
return provider
|
||||
}
|
||||
|
||||
// createTempDir Helper.
|
||||
func createTempDir(t *testing.T, dir string) string {
|
||||
t.Helper()
|
||||
|
||||
d, err := ioutil.TempDir("", dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func copyFile(srcPath, dstPath string) error {
|
||||
dst, err := os.OpenFile(dstPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666)
|
||||
if err != nil {
|
||||
|
@ -312,7 +299,7 @@ func copyFile(srcPath, dstPath string) error {
|
|||
}
|
||||
|
||||
func createTempFile(srcPath, tempDir string) (*os.File, error) {
|
||||
file, err := ioutil.TempFile(tempDir, "temp*"+filepath.Ext(srcPath))
|
||||
file, err := os.CreateTemp(tempDir, "temp*"+filepath.Ext(srcPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
@ -139,7 +139,7 @@ func (p *Provider) fetchConfigurationData() ([]byte, error) {
|
|||
return nil, fmt.Errorf("received non-ok response code: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
return ioutil.ReadAll(res.Body)
|
||||
return io.ReadAll(res.Body)
|
||||
}
|
||||
|
||||
// decodeConfiguration decodes and returns the dynamic configuration from the given data.
|
||||
|
|
|
@ -3,7 +3,6 @@ package crd
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -147,7 +146,7 @@ func newExternalClusterClient(endpoint, token, caFilePath string) (*clientWrappe
|
|||
}
|
||||
|
||||
if caFilePath != "" {
|
||||
caData, err := ioutil.ReadFile(caFilePath)
|
||||
caData, err := os.ReadFile(caFilePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read CA file %s: %w", caFilePath, err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package crd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
|
||||
|
@ -46,7 +46,7 @@ func newClientMock(paths ...string) clientMock {
|
|||
var c clientMock
|
||||
|
||||
for _, path := range paths {
|
||||
yamlContent, err := ioutil.ReadFile(filepath.FromSlash("./fixtures/" + path))
|
||||
yamlContent, err := os.ReadFile(filepath.FromSlash("./fixtures/" + path))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package crd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -4394,7 +4394,7 @@ func TestCrossNamespace(t *testing.T) {
|
|||
var k8sObjects []runtime.Object
|
||||
var crdObjects []runtime.Object
|
||||
for _, path := range test.paths {
|
||||
yamlContent, err := ioutil.ReadFile(filepath.FromSlash("./fixtures/" + path))
|
||||
yamlContent, err := os.ReadFile(filepath.FromSlash("./fixtures/" + path))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
|
@ -138,7 +138,7 @@ func newExternalClusterClient(endpoint, token, caFilePath string) (*clientWrappe
|
|||
}
|
||||
|
||||
if caFilePath != "" {
|
||||
caData, err := ioutil.ReadFile(caFilePath)
|
||||
caData, err := os.ReadFile(caFilePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read CA file %s: %w", caFilePath, err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package gateway
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/k8s"
|
||||
|
@ -43,7 +43,7 @@ func newClientMock(paths ...string) clientMock {
|
|||
var c clientMock
|
||||
|
||||
for _, path := range paths {
|
||||
yamlContent, err := ioutil.ReadFile(filepath.FromSlash("./fixtures/" + path))
|
||||
yamlContent, err := os.ReadFile(filepath.FromSlash("./fixtures/" + path))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -112,7 +111,7 @@ func newExternalClusterClient(endpoint, token, caFilePath string) (*clientWrappe
|
|||
}
|
||||
|
||||
if caFilePath != "" {
|
||||
caData, err := ioutil.ReadFile(caFilePath)
|
||||
caData, err := os.ReadFile(caFilePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read CA file %s: %w", caFilePath, err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package ingress
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/k8s"
|
||||
|
@ -36,7 +36,7 @@ func newClientMock(serverVersion string, paths ...string) clientMock {
|
|||
c.serverVersion = version.Must(version.NewVersion(serverVersion))
|
||||
|
||||
for _, path := range paths {
|
||||
yamlContent, err := ioutil.ReadFile(path)
|
||||
yamlContent, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -271,11 +271,11 @@ func Test_createConfiguration(t *testing.T) {
|
|||
newJSON, err := json.MarshalIndent(cfg, "", " ")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(filename, newJSON, 0o644)
|
||||
err = os.WriteFile(filename, newJSON, 0o644)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
expectedJSON, err := ioutil.ReadFile(filename)
|
||||
expectedJSON, err := os.ReadFile(filename)
|
||||
require.NoError(t, err)
|
||||
|
||||
actualJSON, err := json.MarshalIndent(cfg, "", " ")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue