Replaced deprecated io/ioutil functions (#768)

Signed-off-by: slab713 <109306207+slab713@users.noreply.github.com>
This commit is contained in:
slab713
2022-09-02 14:56:02 +02:00
committed by GitHub
parent 6ae793eb51
commit 8ffb053cec
36 changed files with 249 additions and 280 deletions
+3 -3
View File
@@ -10,7 +10,7 @@ import (
"crypto/x509"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
@@ -131,7 +131,7 @@ func doHTTPRequest(req *http.Request, verifyTLS bool, resultsPtr interface{}) (h
return nil, zotErrors.ErrUnauthorizedAccess
}
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyBytes, _ := io.ReadAll(resp.Body)
return nil, errors.New(string(bodyBytes)) //nolint: goerr113
}
@@ -179,7 +179,7 @@ func getTLSConfig(certsPath string, caCertPool *x509.CertPool) (*tls.Config, err
return nil, err
}
caCert, err := ioutil.ReadFile(caCertFile)
caCert, err := os.ReadFile(caCertFile)
if err != nil {
return nil, err
}
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -67,7 +66,7 @@ func TestElevatedPrivilegesTLSNewControllerPrivilegedCert(t *testing.T) {
os.Chdir(wd)
caCert, err := ioutil.ReadFile(CACert)
caCert, err := os.ReadFile(CACert)
So(err, ShouldBeNil)
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
+3 -4
View File
@@ -9,7 +9,6 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -46,7 +45,7 @@ const (
func TestTLSWithAuth(t *testing.T) {
Convey("Make a new controller", t, func() {
caCert, err := ioutil.ReadFile(CACert)
caCert, err := os.ReadFile(CACert)
So(err, ShouldBeNil)
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
@@ -152,7 +151,7 @@ func TestTLSWithAuth(t *testing.T) {
func TestTLSWithoutAuth(t *testing.T) {
Convey("Home certs - Make a new controller", t, func() {
caCert, err := ioutil.ReadFile(CACert)
caCert, err := os.ReadFile(CACert)
So(err, ShouldBeNil)
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
@@ -222,7 +221,7 @@ func TestTLSWithoutAuth(t *testing.T) {
func TestTLSBadCerts(t *testing.T) {
Convey("Make a new controller", t, func() {
caCert, err := ioutil.ReadFile(CACert)
caCert, err := os.ReadFile(CACert)
So(err, ShouldBeNil)
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
+2 -3
View File
@@ -6,7 +6,6 @@ package cli
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
@@ -135,7 +134,7 @@ func getConfigMapFromFile(filePath string) ([]interface{}, error) {
file.Close()
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
@@ -169,7 +168,7 @@ func saveConfigMapToFile(filePath string, configMap []interface{}) error {
return err
}
if err := ioutil.WriteFile(filePath, marshalled, defaultFilePerms); err != nil {
if err := os.WriteFile(filePath, marshalled, defaultFilePerms); err != nil {
return err
}
+4 -5
View File
@@ -5,7 +5,6 @@ package cli //nolint:testpackage
import (
"bytes"
"io/ioutil"
"log"
"os"
"strings"
@@ -70,7 +69,7 @@ func TestConfigCmdMain(t *testing.T) {
cmd.SetArgs(args)
_ = cmd.Execute()
actual, err := ioutil.ReadFile(file)
actual, err := os.ReadFile(file)
if err != nil {
panic(err)
}
@@ -288,7 +287,7 @@ func TestConfigCmdMain(t *testing.T) {
err := cmd.Execute()
So(err, ShouldBeNil)
actual, err := ioutil.ReadFile(configPath)
actual, err := os.ReadFile(configPath)
if err != nil {
panic(err)
}
@@ -324,7 +323,7 @@ func TestConfigCmdMain(t *testing.T) {
err := cmd.Execute()
So(err, ShouldBeNil)
actual, err := ioutil.ReadFile(configPath)
actual, err := os.ReadFile(configPath)
if err != nil {
panic(err)
}
@@ -347,7 +346,7 @@ func TestConfigCmdMain(t *testing.T) {
err := cmd.Execute()
So(err, ShouldBeNil)
actual, err := ioutil.ReadFile(configPath)
actual, err := os.ReadFile(configPath)
if err != nil {
panic(err)
}
+6 -7
View File
@@ -3,7 +3,6 @@ package cli_test
import (
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"time"
@@ -23,7 +22,7 @@ func TestConfigReloader(t *testing.T) {
port := test.GetFreePort()
baseURL := test.GetBaseURL(port)
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
username := "alice"
@@ -78,7 +77,7 @@ func TestConfigReloader(t *testing.T) {
}
}`, port, htpasswdPath, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
@@ -161,7 +160,7 @@ func TestConfigReloader(t *testing.T) {
port := test.GetFreePort()
baseURL := test.GetBaseURL(port)
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
defer os.Remove(logFile.Name()) // clean up
@@ -202,7 +201,7 @@ func TestConfigReloader(t *testing.T) {
}
}`, port, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
@@ -291,7 +290,7 @@ func TestConfigReloader(t *testing.T) {
port := test.GetFreePort()
baseURL := test.GetBaseURL(port)
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
defer os.Remove(logFile.Name()) // clean up
@@ -332,7 +331,7 @@ func TestConfigReloader(t *testing.T) {
}
}`, port, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
+10 -11
View File
@@ -5,7 +5,6 @@ package cli_test
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
@@ -24,7 +23,7 @@ func TestServeExtensions(t *testing.T) {
Convey("config file with no extensions", t, func(c C) {
port := GetFreePort()
baseURL := GetBaseURL(port)
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
defer os.Remove(logFile.Name()) // clean up
@@ -42,7 +41,7 @@ func TestServeExtensions(t *testing.T) {
}
}`, port, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
_, err = cfgfile.Write([]byte(content))
@@ -65,7 +64,7 @@ func TestServeExtensions(t *testing.T) {
Convey("config file with empty extensions", t, func(c C) {
port := GetFreePort()
baseURL := GetBaseURL(port)
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
defer os.Remove(logFile.Name()) // clean up
@@ -85,7 +84,7 @@ func TestServeExtensions(t *testing.T) {
}
}`, port, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
_, err = cfgfile.Write([]byte(content))
@@ -109,13 +108,13 @@ func TestServeExtensions(t *testing.T) {
func testWithMetricsEnabled(cfgContentFormat string) {
port := GetFreePort()
baseURL := GetBaseURL(port)
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
defer os.Remove(logFile.Name()) // clean up
content := fmt.Sprintf(cfgContentFormat, port, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
@@ -221,7 +220,7 @@ func TestServeMetricsExtension(t *testing.T) {
Convey("with explicit disable", t, func(c C) {
port := GetFreePort()
baseURL := GetBaseURL(port)
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
defer os.Remove(logFile.Name()) // clean up
@@ -244,7 +243,7 @@ func TestServeMetricsExtension(t *testing.T) {
}
}`, port, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
_, err = cfgfile.Write([]byte(content))
@@ -676,14 +675,14 @@ func runCLIWithConfig(tempDir string, config string) (string, error) {
port := GetFreePort()
baseURL := GetBaseURL(port)
logFile, err := ioutil.TempFile(tempDir, "zot-log*.txt")
logFile, err := os.CreateTemp(tempDir, "zot-log*.txt")
if err != nil {
return "", err
}
defer os.Remove(logFile.Name()) // clean up
cfgfile, err := ioutil.TempFile(tempDir, "zot-test*.json")
cfgfile, err := os.CreateTemp(tempDir, "zot-test*.json")
if err != nil {
return "", err
}
+1 -2
View File
@@ -8,7 +8,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path"
@@ -1414,7 +1413,7 @@ func makeConfigFile(content string) string {
configPath := path.Join(home + "/.zot")
if err := ioutil.WriteFile(configPath, []byte(content), 0o600); err != nil {
if err := os.WriteFile(configPath, []byte(content), 0o600); err != nil {
panic(err)
}
+40 -41
View File
@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"testing"
@@ -78,7 +77,7 @@ func TestServe(t *testing.T) {
})
Convey("bad config", func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"log":{}}`)
@@ -98,7 +97,7 @@ func TestVerify(t *testing.T) {
defer func() { os.Args = oldArgs }()
Convey("Test verify bad config", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"log":{}}`)
@@ -111,7 +110,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify storage driver different than s3", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot", "storageDriver": {"name": "gcs"}},
@@ -126,7 +125,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify subpath storage driver different than s3", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot", "storageDriver": {"name": "s3"},
@@ -142,7 +141,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify subpath storage config", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot",
@@ -218,7 +217,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify w/ authorization and w/o authentication", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -234,7 +233,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify w/ authorization and w/ authentication", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -251,7 +250,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify anonymous authorization", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -268,7 +267,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify default authorization fail", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -287,7 +286,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify default authorization fail", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -307,7 +306,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify w/ sync and w/o filesystem storage", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot", "storageDriver": {"name": "s3"}},
@@ -324,7 +323,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify w/ sync and w/ filesystem storage", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -341,7 +340,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify with bad sync prefixes", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -359,7 +358,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify with bad authorization repo patterns", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -375,7 +374,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify sync config default tls value", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -394,7 +393,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify sync without retry options", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot"},
@@ -411,7 +410,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify config with unknown keys", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"distSpecVersion": "1.0.0", "storage": {"rootDirectory": "/tmp/zot"},
@@ -426,7 +425,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify config with missing basedn key", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"distSpecVersion": "1.0.0", "storage": {"rootDirectory": "/tmp/zot"},
@@ -442,7 +441,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify config with missing address key", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"distSpecVersion": "1.0.0", "storage": {"rootDirectory": "/tmp/zot"},
@@ -458,7 +457,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify config with missing userattribute key", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"distSpecVersion": "1.0.0", "storage": {"rootDirectory": "/tmp/zot"},
@@ -474,7 +473,7 @@ func TestVerify(t *testing.T) {
})
Convey("Test verify good config", t, func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"distSpecVersion": "1.0.0", "storage": {"rootDirectory": "/tmp/zot"},
@@ -498,7 +497,7 @@ func TestLoadConfig(t *testing.T) {
})
Convey("Test subpath config combination", t, func(c C) {
config := config.New()
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name())
content := []byte(`{"storage":{"rootDirectory":"/tmp/zot",
@@ -557,7 +556,7 @@ func TestGC(t *testing.T) {
})
Convey("Test GC config corner cases", t, func(c C) {
contents, err := ioutil.ReadFile("../../examples/config-gc.json")
contents, err := os.ReadFile("../../examples/config-gc.json")
So(err, ShouldBeNil)
Convey("GC delay without GC", func() {
@@ -565,14 +564,14 @@ func TestGC(t *testing.T) {
err = json.Unmarshal(contents, config)
config.Storage.GC = false
file, err := ioutil.TempFile("", "gc-config-*.json")
file, err := os.CreateTemp("", "gc-config-*.json")
So(err, ShouldBeNil)
defer os.Remove(file.Name())
contents, err = json.MarshalIndent(config, "", " ")
So(err, ShouldBeNil)
err = ioutil.WriteFile(file.Name(), contents, 0o600)
err = os.WriteFile(file.Name(), contents, 0o600)
So(err, ShouldBeNil)
err = cli.LoadConfiguration(config, file.Name())
So(err, ShouldBeNil)
@@ -585,14 +584,14 @@ func TestGC(t *testing.T) {
config.Storage.GCDelay = 0
config.Storage.GCInterval = 24 * time.Hour
file, err := ioutil.TempFile("", "gc-config-*.json")
file, err := os.CreateTemp("", "gc-config-*.json")
So(err, ShouldBeNil)
defer os.Remove(file.Name())
contents, err = json.MarshalIndent(config, "", " ")
So(err, ShouldBeNil)
err = ioutil.WriteFile(file.Name(), contents, 0o600)
err = os.WriteFile(file.Name(), contents, 0o600)
So(err, ShouldBeNil)
err = cli.LoadConfiguration(config, file.Name())
So(err, ShouldBeNil)
@@ -603,14 +602,14 @@ func TestGC(t *testing.T) {
err = json.Unmarshal(contents, config)
config.Storage.GCDelay = -1 * time.Second
file, err := ioutil.TempFile("", "gc-config-*.json")
file, err := os.CreateTemp("", "gc-config-*.json")
So(err, ShouldBeNil)
defer os.Remove(file.Name())
contents, err = json.MarshalIndent(config, "", " ")
So(err, ShouldBeNil)
err = ioutil.WriteFile(file.Name(), contents, 0o600)
err = os.WriteFile(file.Name(), contents, 0o600)
So(err, ShouldBeNil)
err = cli.LoadConfiguration(config, file.Name())
So(err, ShouldNotBeNil)
@@ -619,7 +618,7 @@ func TestGC(t *testing.T) {
Convey("GC delay when GC = false", func() {
config := config.New()
file, err := ioutil.TempFile("", "gc-false-config-*.json")
file, err := os.CreateTemp("", "gc-false-config-*.json")
So(err, ShouldBeNil)
defer os.Remove(file.Name())
@@ -627,7 +626,7 @@ func TestGC(t *testing.T) {
"gc": false}, "http": {"address": "127.0.0.1", "port": "8080"},
"log": {"level": "debug"}}`)
err = ioutil.WriteFile(file.Name(), content, 0o600)
err = os.WriteFile(file.Name(), content, 0o600)
So(err, ShouldBeNil)
err = cli.LoadConfiguration(config, file.Name())
So(err, ShouldBeNil)
@@ -639,14 +638,14 @@ func TestGC(t *testing.T) {
err = json.Unmarshal(contents, config)
config.Storage.GCInterval = -1 * time.Second
file, err := ioutil.TempFile("", "gc-config-*.json")
file, err := os.CreateTemp("", "gc-config-*.json")
So(err, ShouldBeNil)
defer os.Remove(file.Name())
contents, err = json.MarshalIndent(config, "", " ")
So(err, ShouldBeNil)
err = ioutil.WriteFile(file.Name(), contents, 0o600)
err = os.WriteFile(file.Name(), contents, 0o600)
So(err, ShouldBeNil)
err = cli.LoadConfiguration(config, file.Name())
So(err, ShouldNotBeNil)
@@ -683,7 +682,7 @@ func TestScrub(t *testing.T) {
})
Convey("bad config", func(c C) {
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(`{"log":{}}`)
@@ -720,7 +719,7 @@ func TestScrub(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(fmt.Sprintf(`{
@@ -752,7 +751,7 @@ func TestScrub(t *testing.T) {
Convey("no image store provided", func(c C) {
port := GetFreePort()
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(fmt.Sprintf(`{
@@ -782,7 +781,7 @@ func TestScrub(t *testing.T) {
repoName := "badIndex"
repo, err := ioutil.TempDir(dir, repoName)
repo, err := os.MkdirTemp(dir, repoName)
if err != nil {
panic(err)
}
@@ -793,19 +792,19 @@ func TestScrub(t *testing.T) {
if _, err = os.Stat(fmt.Sprintf("%s/oci-layout", repo)); err != nil {
content := []byte(`{"imageLayoutVersion": "1.0.0"}`)
if err = ioutil.WriteFile(fmt.Sprintf("%s/oci-layout", repo), content, 0o600); err != nil {
if err = os.WriteFile(fmt.Sprintf("%s/oci-layout", repo), content, 0o600); err != nil {
panic(err)
}
}
if _, err = os.Stat(fmt.Sprintf("%s/index.json", repo)); err != nil {
content := []byte(`not a JSON content`)
if err = ioutil.WriteFile(fmt.Sprintf("%s/index.json", repo), content, 0o600); err != nil {
if err = os.WriteFile(fmt.Sprintf("%s/index.json", repo), content, 0o600); err != nil {
panic(err)
}
}
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
tmpfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(tmpfile.Name()) // clean up
content := []byte(fmt.Sprintf(`{
+3 -4
View File
@@ -6,7 +6,6 @@ package cli_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"sync"
@@ -46,7 +45,7 @@ func TestSressTooManyOpenFiles(t *testing.T) {
conf.Storage.Dedupe = false
conf.Storage.GC = true
logFile, err := ioutil.TempFile("", "zot-log*.txt")
logFile, err := os.CreateTemp("", "zot-log*.txt")
So(err, ShouldBeNil)
defer func() {
@@ -93,7 +92,7 @@ func TestSressTooManyOpenFiles(t *testing.T) {
}
}`, dir, conf.Storage.Dedupe, conf.Storage.GC, port, logFile.Name())
cfgfile, err := ioutil.TempFile("", "zot-test*.json")
cfgfile, err := os.CreateTemp("", "zot-test*.json")
So(err, ShouldBeNil)
defer os.Remove(cfgfile.Name()) // clean up
_, err = cfgfile.Write([]byte(content))
@@ -135,7 +134,7 @@ func TestSressTooManyOpenFiles(t *testing.T) {
stopServer(ctlr)
time.Sleep(2 * time.Second)
scrubFile, err := ioutil.TempFile("", "zot-scrub*.txt")
scrubFile, err := os.CreateTemp("", "zot-scrub*.txt")
So(err, ShouldBeNil)
defer func() {