Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-08-27 08:39:31 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-09-09 06:07:22 +0300
commit9bc6df51b36a1e0f763b6ebc7974bb3d98aabf3a (patch)
tree28b88e9c3b6f2a16650164c15a28bfc62360763f /internal
parent9dd40765e162aba80482abdf3ca8f788bec7a8db (diff)
refactor: move away from ioutil (deprecated)
Diffstat (limited to 'internal')
-rw-r--r--internal/auth/auth_test.go8
-rw-r--r--internal/config/config.go6
-rw-r--r--internal/domain/domain_test.go4
-rw-r--r--internal/httpfs/http_fs_test.go6
-rw-r--r--internal/httprange/resource.go3
-rw-r--r--internal/httptransport/metered_round_tripper_test.go4
-rw-r--r--internal/serving/disk/local/serving_test.go4
-rw-r--r--internal/serving/disk/symlink/path_test.go3
-rw-r--r--internal/serving/disk/zip/serving_test.go4
-rw-r--r--internal/source/gitlab/client/client.go5
-rw-r--r--internal/testhelpers/tmpdir.go3
-rw-r--r--internal/vfs/local/root_test.go4
-rw-r--r--internal/vfs/local/vfs_test.go5
-rw-r--r--internal/vfs/zip/archive_test.go9
-rw-r--r--internal/vfs/zip/vfs_test.go4
15 files changed, 33 insertions, 39 deletions
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go
index b49e5423..77ea0b7a 100644
--- a/internal/auth/auth_test.go
+++ b/internal/auth/auth_test.go
@@ -3,7 +3,7 @@ package auth
import (
"bytes"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/http/httptest"
"net/url"
@@ -301,7 +301,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) {
require.Equal(t, http.StatusNotFound, res.StatusCode)
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.Equal(t, string(body), "Generic 404")
}
@@ -471,7 +471,7 @@ func TestCheckResponseForInvalidTokenWhenInvalidToken(t *testing.T) {
require.NoError(t, err)
r := &http.Request{URL: reqURL, Host: "pages.gitlab-example.com", RequestURI: "/test"}
- resp := &http.Response{StatusCode: http.StatusUnauthorized, Body: ioutil.NopCloser(bytes.NewReader([]byte("{\"error\":\"invalid_token\"}")))}
+ resp := &http.Response{StatusCode: http.StatusUnauthorized, Body: io.NopCloser(bytes.NewReader([]byte("{\"error\":\"invalid_token\"}")))}
defer resp.Body.Close()
require.Equal(t, true, auth.CheckResponseForInvalidToken(result, r, resp))
@@ -489,7 +489,7 @@ func TestCheckResponseForInvalidTokenWhenNotInvalidToken(t *testing.T) {
require.NoError(t, err)
r := &http.Request{URL: reqURL}
- resp := &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader([]byte("ok")))}
+ resp := &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader([]byte("ok")))}
require.Equal(t, false, auth.CheckResponseForInvalidToken(result, r, resp))
}
diff --git a/internal/config/config.go b/internal/config/config.go
index 71ff0eed..61767a57 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -3,7 +3,7 @@ package config
import (
"encoding/base64"
"fmt"
- "io/ioutil"
+ "os"
"strings"
"time"
@@ -157,7 +157,7 @@ func setGitLabAPISecretKey(secretFile string, config *Config) error {
return nil
}
- encoded, err := ioutil.ReadFile(secretFile)
+ encoded, err := os.ReadFile(secretFile)
if err != nil {
return fmt.Errorf("reading secret file: %w", err)
}
@@ -259,7 +259,7 @@ func loadConfig() (*Config, error) {
{&config.General.RootKey, *pagesRootKey},
} {
if file.path != "" {
- if *file.contents, err = ioutil.ReadFile(file.path); err != nil {
+ if *file.contents, err = os.ReadFile(file.path); err != nil {
return nil, err
}
}
diff --git a/internal/domain/domain_test.go b/internal/domain/domain_test.go
index f053001a..5a95b4ec 100644
--- a/internal/domain/domain_test.go
+++ b/internal/domain/domain_test.go
@@ -2,7 +2,7 @@ package domain
import (
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/http/httptest"
"testing"
@@ -210,7 +210,7 @@ func TestServeNamespaceNotFound(t *testing.T) {
defer resp.Body.Close()
require.Equal(t, http.StatusNotFound, resp.StatusCode)
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Contains(t, string(body), tt.expectedResponse)
diff --git a/internal/httpfs/http_fs_test.go b/internal/httpfs/http_fs_test.go
index f47e17ff..cbdbc0e1 100644
--- a/internal/httpfs/http_fs_test.go
+++ b/internal/httpfs/http_fs_test.go
@@ -1,7 +1,7 @@
package httpfs
import (
- "io/ioutil"
+ "io"
"net/http"
"net/url"
"os"
@@ -87,7 +87,7 @@ func TestFSOpen(t *testing.T) {
require.NoError(t, err)
- content, err := ioutil.ReadAll(got)
+ content, err := io.ReadAll(got)
require.NoError(t, err)
require.Equal(t, test.expectedContent, string(content))
@@ -192,7 +192,7 @@ func TestFileSystemPathCanServeHTTP(t *testing.T) {
defer res.Body.Close()
require.Equal(t, test.expectedStatusCode, res.StatusCode)
- content, err := ioutil.ReadAll(res.Body)
+ content, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.Equal(t, test.expectedContent, string(content))
diff --git a/internal/httprange/resource.go b/internal/httprange/resource.go
index 5e61d3fb..1da1af95 100644
--- a/internal/httprange/resource.go
+++ b/internal/httprange/resource.go
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
- "io/ioutil"
"net/http"
"strconv"
"strings"
@@ -87,7 +86,7 @@ func NewResource(ctx context.Context, url string, httpClient *http.Client) (*Res
}
defer func() {
- io.CopyN(ioutil.Discard, res.Body, 1) // since we want to read a single byte
+ io.CopyN(io.Discard, res.Body, 1) // since we want to read a single byte
res.Body.Close()
}()
diff --git a/internal/httptransport/metered_round_tripper_test.go b/internal/httptransport/metered_round_tripper_test.go
index 218ed4a7..147cfdba 100644
--- a/internal/httptransport/metered_round_tripper_test.go
+++ b/internal/httptransport/metered_round_tripper_test.go
@@ -1,7 +1,7 @@
package httptransport
import (
- "io/ioutil"
+ "io"
"net/http"
"net/http/httptest"
"strconv"
@@ -27,7 +27,7 @@ func TestReconfigureMeteredRoundTripper(t *testing.T) {
defer res.Body.Close()
require.Equal(t, http.StatusOK, res.StatusCode)
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.Equal(t, "httptransport/testdata/file.html\n", string(body))
diff --git a/internal/serving/disk/local/serving_test.go b/internal/serving/disk/local/serving_test.go
index 2602451f..8352bfc9 100644
--- a/internal/serving/disk/local/serving_test.go
+++ b/internal/serving/disk/local/serving_test.go
@@ -1,7 +1,7 @@
package local
import (
- "io/ioutil"
+ "io"
"net/http"
"net/http/httptest"
"testing"
@@ -82,7 +82,7 @@ func TestDisk_ServeFileHTTP(t *testing.T) {
defer resp.Body.Close()
require.Equal(t, test.expectedStatus, resp.StatusCode)
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Contains(t, string(body), test.expectedBody)
diff --git a/internal/serving/disk/symlink/path_test.go b/internal/serving/disk/symlink/path_test.go
index c9da51c3..400432c2 100644
--- a/internal/serving/disk/symlink/path_test.go
+++ b/internal/serving/disk/symlink/path_test.go
@@ -6,7 +6,6 @@ package symlink_test
import (
"context"
- "io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -156,7 +155,7 @@ func TestIssue13582(t *testing.T) {
t.Fatal(err)
}
file := filepath.Join(linkToDir, "file")
- err = ioutil.WriteFile(file, nil, 0644)
+ err = os.WriteFile(file, nil, 0644)
if err != nil {
t.Fatal(err)
}
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go
index 2cbee18d..167c47c3 100644
--- a/internal/serving/disk/zip/serving_test.go
+++ b/internal/serving/disk/zip/serving_test.go
@@ -1,7 +1,7 @@
package zip
import (
- "io/ioutil"
+ "io"
"net/http"
"net/http/httptest"
"os"
@@ -127,7 +127,7 @@ func TestZip_ServeFileHTTP(t *testing.T) {
defer resp.Body.Close()
require.Equal(t, test.expectedStatus, resp.StatusCode)
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Contains(t, string(body), test.expectedBody)
diff --git a/internal/source/gitlab/client/client.go b/internal/source/gitlab/client/client.go
index 30185143..92ae0390 100644
--- a/internal/source/gitlab/client/client.go
+++ b/internal/source/gitlab/client/client.go
@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
- "io/ioutil"
"net/http"
"net/url"
"path"
@@ -118,7 +117,7 @@ func (gc *Client) GetLookup(ctx context.Context, host string) api.Lookup {
// larger than 512 bytes, the response body will not be closed properly, thus
// we need to close it manually in every case.
defer func() {
- io.Copy(ioutil.Discard, resp.Body)
+ io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}()
@@ -154,7 +153,7 @@ func (gc *Client) get(ctx context.Context, path string, params url.Values) (*htt
// nolint: errcheck
// best effort to discard and close the response body
- io.Copy(ioutil.Discard, resp.Body)
+ io.Copy(io.Discard, resp.Body)
resp.Body.Close()
// StatusNoContent means that a domain does not exist, it is not an error
diff --git a/internal/testhelpers/tmpdir.go b/internal/testhelpers/tmpdir.go
index 5765d308..92987199 100644
--- a/internal/testhelpers/tmpdir.go
+++ b/internal/testhelpers/tmpdir.go
@@ -2,7 +2,6 @@ package testhelpers
import (
"context"
- "io/ioutil"
"os"
"path/filepath"
"testing"
@@ -18,7 +17,7 @@ var fs = vfs.Instrumented(&local.VFS{})
func TmpDir(tb testing.TB, pattern string) (vfs.Root, string) {
tb.Helper()
- tmpDir, err := ioutil.TempDir("", pattern)
+ tmpDir, err := os.MkdirTemp("", pattern)
require.NoError(tb, err)
// On some systems `/tmp` can be a symlink
diff --git a/internal/vfs/local/root_test.go b/internal/vfs/local/root_test.go
index f89e7736..1cf505bf 100644
--- a/internal/vfs/local/root_test.go
+++ b/internal/vfs/local/root_test.go
@@ -2,7 +2,7 @@ package local
import (
"context"
- "io/ioutil"
+ "io"
"os"
"path/filepath"
"testing"
@@ -288,7 +288,7 @@ func TestOpen(t *testing.T) {
require.NoError(t, err, "Open")
- data, err := ioutil.ReadAll(file)
+ data, err := io.ReadAll(file)
require.NoError(t, err, "ReadAll")
require.Equal(t, test.expectedContent, string(data), "ReadAll")
})
diff --git a/internal/vfs/local/vfs_test.go b/internal/vfs/local/vfs_test.go
index b678cfa7..2072d110 100644
--- a/internal/vfs/local/vfs_test.go
+++ b/internal/vfs/local/vfs_test.go
@@ -2,7 +2,6 @@ package local
import (
"context"
- "io/ioutil"
"os"
"path/filepath"
"testing"
@@ -16,7 +15,7 @@ import (
var localVFS = &VFS{}
func tmpDir(t *testing.T) (string, func()) {
- tmpDir, err := ioutil.TempDir("", "vfs")
+ tmpDir, err := os.MkdirTemp("", "vfs")
require.NoError(t, err)
// On some systems `/tmp` can be a symlink
@@ -44,7 +43,7 @@ func TestVFSRoot(t *testing.T) {
require.NoError(t, err)
filePath := filepath.Join(tmpDir, "file")
- err = ioutil.WriteFile(filePath, []byte{}, 0644)
+ err = os.WriteFile(filePath, []byte{}, 0644)
require.NoError(t, err)
symlinks := map[string]string{
diff --git a/internal/vfs/zip/archive_test.go b/internal/vfs/zip/archive_test.go
index 23fe0583..acd89d49 100644
--- a/internal/vfs/zip/archive_test.go
+++ b/internal/vfs/zip/archive_test.go
@@ -6,7 +6,6 @@ import (
"context"
"crypto/rand"
"io"
- "io/ioutil"
"net/http"
"net/http/httptest"
"os"
@@ -77,7 +76,7 @@ func testOpen(t *testing.T, zip *zipArchive) {
}
require.NoError(t, err)
- data, err := ioutil.ReadAll(f)
+ data, err := io.ReadAll(f)
require.NoError(t, err)
require.Equal(t, tt.expectedContent, string(data))
@@ -173,7 +172,7 @@ func TestOpenCached(t *testing.T) {
require.NoError(t, err)
defer f.Close()
- _, err = ioutil.ReadAll(f)
+ _, err = io.ReadAll(f)
if test.expectedReadErr != nil {
require.Equal(t, test.expectedReadErr, err)
status, _ := zip.(*zipArchive).openStatus()
@@ -354,7 +353,7 @@ func TestArchiveCanBeReadAfterOpenCtxCanceled(t *testing.T) {
file, err := zip.Open(context.Background(), "index.html")
require.NoError(t, err)
- data, err := ioutil.ReadAll(file)
+ data, err := io.ReadAll(file)
require.NoError(t, err)
require.Equal(t, "zip.gitlab.io/project/index.html\n", string(data))
@@ -478,7 +477,7 @@ func benchmarkArchiveRead(b *testing.B, size int64) {
f, err := z.Open(context.Background(), "file.txt")
require.NoError(b, err)
- _, err = io.Copy(ioutil.Discard, f)
+ _, err = io.Copy(io.Discard, f)
require.NoError(b, err)
require.NoError(b, f.Close())
diff --git a/internal/vfs/zip/vfs_test.go b/internal/vfs/zip/vfs_test.go
index 22cc5c6b..fb368a69 100644
--- a/internal/vfs/zip/vfs_test.go
+++ b/internal/vfs/zip/vfs_test.go
@@ -2,7 +2,7 @@ package zip
import (
"context"
- "io/ioutil"
+ "io"
"testing"
"time"
@@ -55,7 +55,7 @@ func TestVFSRoot(t *testing.T) {
f, err := root.Open(context.Background(), "index.html")
require.NoError(t, err)
- content, err := ioutil.ReadAll(f)
+ content, err := io.ReadAll(f)
require.NoError(t, err)
require.Equal(t, "zip.gitlab.io/project/index.html\n", string(content))