mirror of
https://github.com/gomods/athens
synced 2026-02-03 12:10:32 +00:00
feat: replace ioutil with io and os (#1816)
This commit is contained in:
@@ -2,7 +2,7 @@ package actions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -42,7 +42,7 @@ func TestProxyRoutes(t *testing.T) {
|
|||||||
testCases := []routeTest{
|
testCases := []routeTest{
|
||||||
{"GET", "/", "", func(t *testing.T, resp *http.Response) {
|
{"GET", "/", "", func(t *testing.T, resp *http.Response) {
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, `"Welcome to The Athens Proxy"`, string(body))
|
assert.Equal(t, `"Welcome to The Athens Proxy"`, string(body))
|
||||||
}},
|
}},
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package actions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -19,7 +19,7 @@ func initializeAuthFile(path string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fileBts, err := ioutil.ReadFile(path)
|
fileBts, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("could not read %s: %v", path, err)
|
log.Fatalf("could not read %s: %v", path, err)
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ func initializeAuthFile(path string) {
|
|||||||
|
|
||||||
fileName := transformAuthFileName(filepath.Base(path))
|
fileName := transformAuthFileName(filepath.Base(path))
|
||||||
rcp := filepath.Join(hdir, fileName)
|
rcp := filepath.Join(hdir, fileName)
|
||||||
if err := ioutil.WriteFile(rcp, fileBts, 0600); err != nil {
|
if err := os.WriteFile(rcp, fileBts, 0600); err != nil {
|
||||||
log.Fatalf("could not write to file: %v", err)
|
log.Fatalf("could not write to file: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ func netrcFromToken(tok string) {
|
|||||||
log.Fatalf("netrcFromToken: could not get homedir: %v", err)
|
log.Fatalf("netrcFromToken: could not get homedir: %v", err)
|
||||||
}
|
}
|
||||||
rcp := filepath.Join(hdir, getNETRCFilename())
|
rcp := filepath.Join(hdir, getNETRCFilename())
|
||||||
if err := ioutil.WriteFile(rcp, []byte(fileContent), 0600); err != nil {
|
if err := os.WriteFile(rcp, []byte(fileContent), 0600); err != nil {
|
||||||
log.Fatalf("netrcFromToken: could not write to file: %v", err)
|
log.Fatalf("netrcFromToken: could not write to file: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build e2etests
|
||||||
// +build e2etests
|
// +build e2etests
|
||||||
|
|
||||||
package e2etests
|
package e2etests
|
||||||
@@ -6,7 +7,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -35,12 +35,12 @@ type catalogRes struct {
|
|||||||
|
|
||||||
func (m *E2eSuite) SetupSuite() {
|
func (m *E2eSuite) SetupSuite() {
|
||||||
var err error
|
var err error
|
||||||
m.goPath, err = ioutil.TempDir("/tmp", "gopath")
|
m.goPath, err = os.MkdirTemp("/tmp", "gopath")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Fail("Failed to make temp dir", err)
|
m.Fail("Failed to make temp dir", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.sampleRepoPath, err = ioutil.TempDir("/tmp", "repopath")
|
m.sampleRepoPath, err = os.MkdirTemp("/tmp", "repopath")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Fail("Failed to make temp dir for sample repo", err)
|
m.Fail("Failed to make temp dir for sample repo", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -433,7 +432,7 @@ func restoreEnv(envVars map[string]string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tempFile(perm os.FileMode) (name string, err error) {
|
func tempFile(perm os.FileMode) (name string, err error) {
|
||||||
f, err := ioutil.TempFile(os.TempDir(), "prefix-")
|
f, err := os.CreateTemp(os.TempDir(), "prefix-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
athenserr "github.com/gomods/athens/pkg/errors"
|
athenserr "github.com/gomods/athens/pkg/errors"
|
||||||
@@ -125,7 +125,7 @@ func TestListMerge(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for _, v := range tc.strVersions {
|
for _, v := range tc.strVersions {
|
||||||
s.Save(ctx, testModName, v, bts, ioutil.NopCloser(bytes.NewReader(bts)), bts)
|
s.Save(ctx, testModName, v, bts, io.NopCloser(bytes.NewReader(bts)), bts)
|
||||||
}
|
}
|
||||||
defer clearStorage(s, testModName, tc.strVersions)
|
defer clearStorage(s, testModName, tc.strVersions)
|
||||||
dp := New(&Opts{s, nil, &listerMock{versions: tc.goVersions, err: tc.goErr}, nil, Strict})
|
dp := New(&Opts{s, nil, &listerMock{versions: tc.goVersions, err: tc.goErr}, nil, Strict})
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package mode
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gomods/athens/pkg/errors"
|
"github.com/gomods/athens/pkg/errors"
|
||||||
@@ -59,7 +59,7 @@ func NewFile(m Mode, downloadURL string) (*DownloadFile, error) {
|
|||||||
|
|
||||||
if strings.HasPrefix(string(m), "file:") {
|
if strings.HasPrefix(string(m), "file:") {
|
||||||
filePath := string(m[5:])
|
filePath := string(m[5:])
|
||||||
bts, err := ioutil.ReadFile(filePath)
|
bts, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/stretchr/testify/assert"
|
"io"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/gomods/athens/pkg/storage"
|
"github.com/gomods/athens/pkg/storage"
|
||||||
"github.com/gomods/athens/pkg/storage/mem"
|
"github.com/gomods/athens/pkg/storage/mem"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
@@ -358,7 +359,7 @@ func TestGoMod(t *testing.T) {
|
|||||||
func getGoldenFile(t *testing.T, name string) []byte {
|
func getGoldenFile(t *testing.T, name string) []byte {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
file := filepath.Join("test_data", strings.Replace(name, " ", "_", -1)+".golden")
|
file := filepath.Join("test_data", strings.Replace(name, " ", "_", -1)+".golden")
|
||||||
bts, err := ioutil.ReadFile(file)
|
bts, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -418,7 +419,7 @@ func (m *mockFetcher) Fetch(ctx context.Context, mod, ver string) (*storage.Vers
|
|||||||
return &storage.Version{
|
return &storage.Version{
|
||||||
Mod: bts,
|
Mod: bts,
|
||||||
Info: bts,
|
Info: bts,
|
||||||
Zip: ioutil.NopCloser(bytes.NewReader(bts)),
|
Zip: io.NopCloser(bytes.NewReader(bts)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,7 +430,7 @@ func TestDownloadProtocolWhenFetchFails(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fakeMod := testMod{"github.com/athens-artifacts/samplelib", "v1.0.0"}
|
fakeMod := testMod{"github.com/athens-artifacts/samplelib", "v1.0.0"}
|
||||||
bts := []byte(fakeMod.mod + "@" + fakeMod.ver)
|
bts := []byte(fakeMod.mod + "@" + fakeMod.ver)
|
||||||
err = s.Save(context.Background(), fakeMod.mod, fakeMod.ver, bts, ioutil.NopCloser(bytes.NewReader(bts)), bts)
|
err = s.Save(context.Background(), fakeMod.mod, fakeMod.ver, bts, io.NopCloser(bytes.NewReader(bts)), bts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -58,7 +57,7 @@ func newTestFilter(filterFile string) (*module.Filter, error) {
|
|||||||
func Test_FilterMiddleware(t *testing.T) {
|
func Test_FilterMiddleware(t *testing.T) {
|
||||||
r := require.New(t)
|
r := require.New(t)
|
||||||
|
|
||||||
filter, err := ioutil.TempFile(os.TempDir(), "filter-")
|
filter, err := os.CreateTemp(os.TempDir(), "filter-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gomods/athens/pkg/errors"
|
"github.com/gomods/athens/pkg/errors"
|
||||||
@@ -99,6 +99,6 @@ func validate(ctx context.Context, client *http.Client, hook, mod, ver string) (
|
|||||||
func validationResponseFromRequest(resp *http.Response) validationResponse {
|
func validationResponseFromRequest(resp *http.Response) validationResponse {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
return validationResponse{Valid: resp.StatusCode == http.StatusOK, Message: body}
|
return validationResponse{Valid: resp.StatusCode == http.StatusOK, Message: body}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package module
|
package module
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -208,27 +207,27 @@ func (t *FilterTests) Test_initFromConfig() {
|
|||||||
defer os.Remove(filterFile)
|
defer os.Remove(filterFile)
|
||||||
|
|
||||||
goodInput := []byte("+ github.com/a/b\n\n# some comment\n- github.com/c/d\n\nD github.com/x")
|
goodInput := []byte("+ github.com/a/b\n\n# some comment\n- github.com/c/d\n\nD github.com/x")
|
||||||
ioutil.WriteFile(filterFile, goodInput, 0644)
|
os.WriteFile(filterFile, goodInput, 0644)
|
||||||
|
|
||||||
f, err := initFromConfig(filterFile)
|
f, err := initFromConfig(filterFile)
|
||||||
r.NotNil(f)
|
r.NotNil(f)
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
|
|
||||||
badInput := []byte("+ github.com/a/b\n\n# some comment\n\n- github.com/c/d\n\nD github.com/x\nsome_random_line")
|
badInput := []byte("+ github.com/a/b\n\n# some comment\n\n- github.com/c/d\n\nD github.com/x\nsome_random_line")
|
||||||
ioutil.WriteFile(filterFile, badInput, 0644)
|
os.WriteFile(filterFile, badInput, 0644)
|
||||||
f, err = initFromConfig(filterFile)
|
f, err = initFromConfig(filterFile)
|
||||||
r.Nil(f)
|
r.Nil(f)
|
||||||
r.Error(err)
|
r.Error(err)
|
||||||
|
|
||||||
versionInput := []byte("+ github.com/a/b\n\n# some comment\n\n- github.com/c/d v1,v2.3.4,v3.2.*\n\nD github.com/x\n")
|
versionInput := []byte("+ github.com/a/b\n\n# some comment\n\n- github.com/c/d v1,v2.3.4,v3.2.*\n\nD github.com/x\n")
|
||||||
ioutil.WriteFile(filterFile, versionInput, 0644)
|
os.WriteFile(filterFile, versionInput, 0644)
|
||||||
f, err = initFromConfig(filterFile)
|
f, err = initFromConfig(filterFile)
|
||||||
r.NotNil(f)
|
r.NotNil(f)
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tempFilterFile(t *testing.T) (path string) {
|
func tempFilterFile(t *testing.T) (path string) {
|
||||||
filter, err := ioutil.TempFile(os.TempDir(), "filter-")
|
filter, err := os.CreateTemp(os.TempDir(), "filter-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
@@ -48,7 +48,7 @@ func (s *ModuleSuite) TestGoGetFetcherFetch() {
|
|||||||
|
|
||||||
r.True(len(ver.Mod) > 0)
|
r.True(len(ver.Mod) > 0)
|
||||||
|
|
||||||
zipBytes, err := ioutil.ReadAll(ver.Zip)
|
zipBytes, err := io.ReadAll(ver.Zip)
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
r.True(len(zipBytes) > 0)
|
r.True(len(zipBytes) > 0)
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ func (s *ModuleSuite) TestGoGetFetcherSumDB() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
r := s.Require()
|
r := s.Require()
|
||||||
zipBytes, err := ioutil.ReadFile("test_data/mockmod.xyz@v1.2.3.zip")
|
zipBytes, err := os.ReadFile("test_data/mockmod.xyz@v1.2.3.zip")
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
mp := &mockProxy{paths: map[string][]byte{
|
mp := &mockProxy{paths: map[string][]byte{
|
||||||
"/mockmod.xyz/@v/v1.2.3.info": []byte(`{"Version":"v1.2.3"}`),
|
"/mockmod.xyz/@v/v1.2.3.info": []byte(`{"Version":"v1.2.3"}`),
|
||||||
@@ -101,7 +101,7 @@ func (s *ModuleSuite) TestGoGetFetcherSumDB() {
|
|||||||
func (s *ModuleSuite) TestGoGetDir() {
|
func (s *ModuleSuite) TestGoGetDir() {
|
||||||
r := s.Require()
|
r := s.Require()
|
||||||
t := s.T()
|
t := s.T()
|
||||||
dir, err := ioutil.TempDir("", "nested")
|
dir, err := os.MkdirTemp("", "nested")
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
os.RemoveAll(dir)
|
os.RemoveAll(dir)
|
||||||
@@ -113,7 +113,7 @@ func (s *ModuleSuite) TestGoGetDir() {
|
|||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
defer ver.Zip.Close()
|
defer ver.Zip.Close()
|
||||||
|
|
||||||
dirInfo, err := ioutil.ReadDir(dir)
|
dirInfo, err := os.ReadDir(dir)
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
|
|
||||||
if len(dirInfo) <= 0 {
|
if len(dirInfo) <= 0 {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package stash
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -104,7 +103,7 @@ func (mf *mockFetcher) Fetch(ctx context.Context, mod, ver string) (*storage.Ver
|
|||||||
return &storage.Version{
|
return &storage.Version{
|
||||||
Info: []byte("info"),
|
Info: []byte("info"),
|
||||||
Mod: []byte("gomod"),
|
Mod: []byte("gomod"),
|
||||||
Zip: ioutil.NopCloser(strings.NewReader("zipfile")),
|
Zip: io.NopCloser(strings.NewReader("zipfile")),
|
||||||
Semver: mf.ver,
|
Semver: mf.ver,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package stash
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -67,7 +67,7 @@ func TestWithGCS(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer zip.Close()
|
defer zip.Close()
|
||||||
zipContent, err := ioutil.ReadAll(zip)
|
zipContent, err := io.ReadAll(zip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package azureblob
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"github.com/gomods/athens/pkg/config"
|
"github.com/gomods/athens/pkg/config"
|
||||||
"github.com/gomods/athens/pkg/errors"
|
"github.com/gomods/athens/pkg/errors"
|
||||||
@@ -30,7 +30,7 @@ func (s *Storage) Info(ctx context.Context, module string, version string) ([]by
|
|||||||
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
|
|
||||||
infoBytes, err := ioutil.ReadAll(infoReader)
|
infoBytes, err := io.ReadAll(infoReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ func (s *Storage) GoMod(ctx context.Context, module string, version string) ([]b
|
|||||||
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
|
|
||||||
modBytes, err := ioutil.ReadAll(modReader)
|
modBytes, err := io.ReadAll(modReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, fmt.Errorf("could not get new reader for mod file: %s", err), errors.M(module), errors.V(version))
|
return nil, errors.E(op, fmt.Errorf("could not get new reader for mod file: %s", err), errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gomods/athens/pkg/storage"
|
"github.com/gomods/athens/pkg/storage"
|
||||||
@@ -49,7 +49,7 @@ func benchSave(b *testing.B, s storage.Backend, clear func() error) {
|
|||||||
|
|
||||||
module, version := "benchSaveModule", "1.0.1"
|
module, version := "benchSaveModule", "1.0.1"
|
||||||
mock := getMockModule()
|
mock := getMockModule()
|
||||||
zipBts, err := ioutil.ReadAll(mock.Zip)
|
zipBts, err := io.ReadAll(mock.Zip)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
||||||
mi := 0
|
mi := 0
|
||||||
@@ -76,7 +76,7 @@ func benchDelete(b *testing.B, s storage.Backend, clear func() error) {
|
|||||||
|
|
||||||
module, version := "benchDeleteModule", "1.0.1"
|
module, version := "benchDeleteModule", "1.0.1"
|
||||||
mock := getMockModule()
|
mock := getMockModule()
|
||||||
zipBts, err := ioutil.ReadAll(mock.Zip)
|
zipBts, err := io.ReadAll(mock.Zip)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -136,7 +136,7 @@ func testGet(t *testing.T, b storage.Backend) {
|
|||||||
modname := "github.com/gomods/athens"
|
modname := "github.com/gomods/athens"
|
||||||
ver := "v1.2.3"
|
ver := "v1.2.3"
|
||||||
mock := getMockModule()
|
mock := getMockModule()
|
||||||
zipBts, _ := ioutil.ReadAll(mock.Zip)
|
zipBts, _ := io.ReadAll(mock.Zip)
|
||||||
b.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
b.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
||||||
defer b.Delete(ctx, modname, ver)
|
defer b.Delete(ctx, modname, ver)
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ func testGet(t *testing.T, b storage.Backend) {
|
|||||||
|
|
||||||
zip, err := b.Zip(ctx, modname, ver)
|
zip, err := b.Zip(ctx, modname, ver)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
givenZipBts, err := ioutil.ReadAll(zip)
|
givenZipBts, err := io.ReadAll(zip)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, zipBts, givenZipBts)
|
require.Equal(t, zipBts, givenZipBts)
|
||||||
require.Equal(t, int64(len(zipBts)), zip.Size())
|
require.Equal(t, int64(len(zipBts)), zip.Size())
|
||||||
@@ -161,7 +161,7 @@ func testExists(t *testing.T, b storage.Backend) {
|
|||||||
modname := "github.com/gomods/athens"
|
modname := "github.com/gomods/athens"
|
||||||
ver := "v1.2.3"
|
ver := "v1.2.3"
|
||||||
mock := getMockModule()
|
mock := getMockModule()
|
||||||
zipBts, _ := ioutil.ReadAll(mock.Zip)
|
zipBts, _ := io.ReadAll(mock.Zip)
|
||||||
b.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
b.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
||||||
defer b.Delete(ctx, modname, ver)
|
defer b.Delete(ctx, modname, ver)
|
||||||
checker := storage.WithChecker(b)
|
checker := storage.WithChecker(b)
|
||||||
@@ -175,7 +175,7 @@ func testShouldNotExist(t *testing.T, b storage.Backend) {
|
|||||||
mod := "github.com/gomods/shouldNotExist"
|
mod := "github.com/gomods/shouldNotExist"
|
||||||
ver := "v1.2.3-pre.1"
|
ver := "v1.2.3-pre.1"
|
||||||
mock := getMockModule()
|
mock := getMockModule()
|
||||||
zipBts, _ := ioutil.ReadAll(mock.Zip)
|
zipBts, _ := io.ReadAll(mock.Zip)
|
||||||
err := b.Save(ctx, mod, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
err := b.Save(ctx, mod, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
||||||
require.NoError(t, err, "should successfully safe a mock module")
|
require.NoError(t, err, "should successfully safe a mock module")
|
||||||
defer b.Delete(ctx, mod, ver)
|
defer b.Delete(ctx, mod, ver)
|
||||||
@@ -217,7 +217,7 @@ func testCatalog(t *testing.T, b storage.Backend) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
mock := getMockModule()
|
mock := getMockModule()
|
||||||
zipBts, _ := ioutil.ReadAll(mock.Zip)
|
zipBts, _ := io.ReadAll(mock.Zip)
|
||||||
modname := "github.com/gomods/testCatalogModule"
|
modname := "github.com/gomods/testCatalogModule"
|
||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
ver := fmt.Sprintf("v1.2.%04d", i)
|
ver := fmt.Sprintf("v1.2.%04d", i)
|
||||||
@@ -256,6 +256,6 @@ func getMockModule() *storage.Version {
|
|||||||
return &storage.Version{
|
return &storage.Version{
|
||||||
Info: []byte("123"),
|
Info: []byte("123"),
|
||||||
Mod: []byte("456"),
|
Mod: []byte("456"),
|
||||||
Zip: ioutil.NopCloser(bytes.NewReader([]byte("789"))),
|
Zip: io.NopCloser(bytes.NewReader([]byte("789"))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
-5
@@ -5,7 +5,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -53,7 +52,7 @@ func (s *service) Info(ctx context.Context, mod, ver string) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err)
|
return nil, errors.E(op, err)
|
||||||
}
|
}
|
||||||
info, err := ioutil.ReadAll(body)
|
info, err := io.ReadAll(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err)
|
return nil, errors.E(op, err)
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ func (s *service) GoMod(ctx context.Context, mod, ver string) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err)
|
return nil, errors.E(op, err)
|
||||||
}
|
}
|
||||||
modFile, err := ioutil.ReadAll(body)
|
modFile, err := io.ReadAll(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err)
|
return nil, errors.E(op, err)
|
||||||
}
|
}
|
||||||
@@ -107,7 +106,7 @@ func (s *service) Save(ctx context.Context, mod, ver string, modFile []byte, zip
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
bts, _ := ioutil.ReadAll(resp.Body)
|
bts, _ := io.ReadAll(resp.Body)
|
||||||
return errors.E(op, fmt.Errorf("unexpected status code: %v - body: %s", resp.StatusCode, bts), resp.StatusCode)
|
return errors.E(op, fmt.Errorf("unexpected status code: %v - body: %s", resp.StatusCode, bts), resp.StatusCode)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -176,7 +175,7 @@ func (s *service) doRequest(ctx context.Context, method, mod, ver, ext string) (
|
|||||||
return nil, 0, errors.E(op, err)
|
return nil, 0, errors.E(op, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
return nil, 0, errors.E(op, fmt.Errorf("none 200 status code: %v - body: %s", resp.StatusCode, body), resp.StatusCode)
|
return nil, 0, errors.E(op, fmt.Errorf("none 200 status code: %v - body: %s", resp.StatusCode, body), resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-3
@@ -3,7 +3,6 @@ package external
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -88,7 +87,7 @@ func NewServer(strg storage.Backend) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer infoFile.Close()
|
defer infoFile.Close()
|
||||||
info, err := ioutil.ReadAll(infoFile)
|
info, err := io.ReadAll(infoFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 400)
|
http.Error(w, err.Error(), 400)
|
||||||
return
|
return
|
||||||
@@ -99,7 +98,7 @@ func NewServer(strg storage.Backend) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer modReader.Close()
|
defer modReader.Close()
|
||||||
modFile, err := ioutil.ReadAll(modReader)
|
modFile, err := io.ReadAll(modReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 400)
|
http.Error(w, err.Error(), 400)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package gcp
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"cloud.google.com/go/storage"
|
"cloud.google.com/go/storage"
|
||||||
"github.com/gomods/athens/pkg/config"
|
"github.com/gomods/athens/pkg/config"
|
||||||
@@ -21,7 +21,7 @@ func (s *Storage) Info(ctx context.Context, module, version string) ([]byte, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err, getErrorKind(err), errors.M(module), errors.V(version))
|
return nil, errors.E(op, err, getErrorKind(err), errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
infoBytes, err := ioutil.ReadAll(infoReader)
|
infoBytes, err := io.ReadAll(infoReader)
|
||||||
infoReader.Close()
|
infoReader.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
||||||
@@ -38,7 +38,7 @@ func (s *Storage) GoMod(ctx context.Context, module, version string) ([]byte, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err, getErrorKind(err), errors.M(module), errors.V(version))
|
return nil, errors.E(op, err, getErrorKind(err), errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
modBytes, err := ioutil.ReadAll(modReader)
|
modBytes, err := io.ReadAll(modReader)
|
||||||
modReader.Close()
|
modReader.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, fmt.Errorf("could not get new reader for mod file: %s", err), errors.M(module), errors.V(version))
|
return nil, errors.E(op, fmt.Errorf("could not get new reader for mod file: %s", err), errors.M(module), errors.V(version))
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package minio
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gomods/athens/pkg/errors"
|
"github.com/gomods/athens/pkg/errors"
|
||||||
@@ -22,7 +22,7 @@ func (v *storageImpl) Info(ctx context.Context, module, vsn string) ([]byte, err
|
|||||||
return nil, errors.E(op, err)
|
return nil, errors.E(op, err)
|
||||||
}
|
}
|
||||||
defer infoReader.Close()
|
defer infoReader.Close()
|
||||||
info, err := ioutil.ReadAll(infoReader)
|
info, err := io.ReadAll(infoReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, transformNotFoundErr(op, module, vsn, err)
|
return nil, transformNotFoundErr(op, module, vsn, err)
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ func (v *storageImpl) GoMod(ctx context.Context, module, vsn string) ([]byte, er
|
|||||||
return nil, errors.E(op, err)
|
return nil, errors.E(op, err)
|
||||||
}
|
}
|
||||||
defer modReader.Close()
|
defer modReader.Close()
|
||||||
mod, err := ioutil.ReadAll(modReader)
|
mod, err := io.ReadAll(modReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, transformNotFoundErr(op, module, vsn, err)
|
return nil, transformNotFoundErr(op, module, vsn, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ func (m *ModuleStore) newClient() (*mongo.Client, error) {
|
|||||||
roots = x509.NewCertPool()
|
roots = x509.NewCertPool()
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := ioutil.ReadFile(m.certPath)
|
cert, err := os.ReadFile(m.certPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err)
|
return nil, errors.E(op, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package mongo
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -48,13 +48,13 @@ func TestQueryModuleVersionExists(t *testing.T) {
|
|||||||
mock := &storage.Version{
|
mock := &storage.Version{
|
||||||
Info: []byte("123"),
|
Info: []byte("123"),
|
||||||
Mod: []byte("456"),
|
Mod: []byte("456"),
|
||||||
Zip: ioutil.NopCloser(bytes.NewReader([]byte("789"))),
|
Zip: io.NopCloser(bytes.NewReader([]byte("789"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
backend := getStorage(t)
|
backend := getStorage(t)
|
||||||
|
|
||||||
zipBts, _ := ioutil.ReadAll(mock.Zip)
|
zipBts, _ := io.ReadAll(mock.Zip)
|
||||||
backend.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
backend.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
||||||
defer backend.Delete(ctx, modname, ver)
|
defer backend.Delete(ctx, modname, ver)
|
||||||
|
|
||||||
@@ -69,13 +69,13 @@ func TestQueryKindNotFoundErrorCases(t *testing.T) {
|
|||||||
mock := &storage.Version{
|
mock := &storage.Version{
|
||||||
Info: []byte("123"),
|
Info: []byte("123"),
|
||||||
Mod: []byte("456"),
|
Mod: []byte("456"),
|
||||||
Zip: ioutil.NopCloser(bytes.NewReader([]byte("789"))),
|
Zip: io.NopCloser(bytes.NewReader([]byte("789"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
backend := getStorage(t)
|
backend := getStorage(t)
|
||||||
|
|
||||||
zipBts, _ := ioutil.ReadAll(mock.Zip)
|
zipBts, _ := io.ReadAll(mock.Zip)
|
||||||
backend.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
backend.Save(ctx, modname, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
|
||||||
defer backend.Delete(ctx, modname, ver)
|
defer backend.Delete(ctx, modname, ver)
|
||||||
|
|
||||||
@@ -111,12 +111,12 @@ func TestNewStorageWithDefaultOverrides(t *testing.T) {
|
|||||||
collName string
|
collName string
|
||||||
expCollName string
|
expCollName string
|
||||||
}{
|
}{
|
||||||
{"Test Default 'Athens' DB Name", "athens", "athens", "modules", "modules"}, //Tests the default database name
|
{"Test Default 'Athens' DB Name", "athens", "athens", "modules", "modules"}, // Tests the default database name
|
||||||
{"Test Custom DB Name", "testAthens", "testAthens", "modules", "modules"}, //Tests a non-default database name
|
{"Test Custom DB Name", "testAthens", "testAthens", "modules", "modules"}, // Tests a non-default database name
|
||||||
{"Test Blank DB Name", "", "athens", "modules", "modules"}, //Tests the blank database name edge-case
|
{"Test Blank DB Name", "", "athens", "modules", "modules"}, // Tests the blank database name edge-case
|
||||||
{"Test Default 'Modules' Collection Name", "athens", "athens", "modules", "modules"}, //Tests the default collection name
|
{"Test Default 'Modules' Collection Name", "athens", "athens", "modules", "modules"}, // Tests the default collection name
|
||||||
{"Test Custom Collection Name", "athens", "athens", "testModules", "testModules"}, //Tests the non-default collection name
|
{"Test Custom Collection Name", "athens", "athens", "testModules", "testModules"}, // Tests the non-default collection name
|
||||||
{"Test Blank Collection Name", "athens", "athens", "", "modules"}, //Tests the blank collection name edge-case
|
{"Test Blank Collection Name", "athens", "athens", "", "modules"}, // Tests the blank collection name edge-case
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package s3
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
@@ -32,7 +32,7 @@ func (s *Storage) Info(ctx context.Context, module, version string) ([]byte, err
|
|||||||
}
|
}
|
||||||
defer infoReader.Close()
|
defer infoReader.Close()
|
||||||
|
|
||||||
infoBytes, err := ioutil.ReadAll(infoReader)
|
infoBytes, err := io.ReadAll(infoReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
return nil, errors.E(op, err, errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ func (s *Storage) GoMod(ctx context.Context, module, version string) ([]byte, er
|
|||||||
}
|
}
|
||||||
defer modReader.Close()
|
defer modReader.Close()
|
||||||
|
|
||||||
modBytes, err := ioutil.ReadAll(modReader)
|
modBytes, err := io.ReadAll(modReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.E(op, fmt.Errorf("could not get new reader for mod file: %s", err), errors.M(module), errors.V(version))
|
return nil, errors.E(op, fmt.Errorf("could not get new reader for mod file: %s", err), errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user