mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
Refactor: move from io/ioutil to io and os package (#2234)
The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <zerjun@beatchain.co>
This commit is contained in:
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -72,7 +71,7 @@ var _ = Describe("test waitSecretVolume", func() {
|
||||
By("add non-empty file")
|
||||
_, err := os.Create(testdir + "/file")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = ioutil.WriteFile(testdir+"/file", []byte("test"), os.ModeAppend)
|
||||
err = os.WriteFile(testdir+"/file", []byte("test"), os.ModeAppend)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = waitWebhookSecretVolume(testdir, testTimeout, testInterval)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@@ -19,7 +19,7 @@ package e2e
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -90,7 +90,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.Get(util.URL("/envs/" + envHelloMeta.EnvName))
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -109,7 +109,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -125,7 +125,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.Get(util.URL("/envs/"))
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -143,7 +143,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -160,7 +160,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -178,7 +178,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.Get(util.URL(url))
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -197,7 +197,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.Post(util.URL(url), "application/json", strings.NewReader(string(data)))
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -215,7 +215,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
// TODO(zzxwill) revise the check process if we need to work on https://github.com/oam-dev/kubevela/discussions/933
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -229,7 +229,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.Get(util.URL("/components/"))
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
@@ -257,7 +257,7 @@ var _ = ginkgo.Describe("API", func() {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
|
||||
@@ -19,8 +19,9 @@ package e2e
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
@@ -60,7 +61,7 @@ var (
|
||||
JsonAppFileContext = func(context, jsonAppFile string) bool {
|
||||
return ginkgo.Context(context, func() {
|
||||
ginkgo.It("Start the application through the app file in JSON format.", func() {
|
||||
writeStatus := ioutil.WriteFile("vela.json", []byte(jsonAppFile), 0644)
|
||||
writeStatus := os.WriteFile("vela.json", []byte(jsonAppFile), 0644)
|
||||
gomega.Expect(writeStatus).NotTo(gomega.HaveOccurred())
|
||||
output, err := Exec("vela up -f vela.json")
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
@@ -183,7 +184,7 @@ var (
|
||||
resp, err := http.Post(util.URL("/envs/"), "application/json", strings.NewReader(string(data)))
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
result, err := io.ReadAll(resp.Body)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
var r apis.Response
|
||||
err = json.Unmarshal(result, &r)
|
||||
|
||||
@@ -18,7 +18,6 @@ package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -71,9 +70,9 @@ var _ = BeforeSuite(func(done Done) {
|
||||
|
||||
err = os.MkdirAll("definitions", os.ModePerm)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = ioutil.WriteFile("definitions/webservice.yaml", []byte(componentDef), 0644)
|
||||
err = os.WriteFile("definitions/webservice.yaml", []byte(componentDef), 0644)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = ioutil.WriteFile("definitions/ingress.yaml", []byte(traitDef), 0644)
|
||||
err = os.WriteFile("definitions/ingress.yaml", []byte(traitDef), 0644)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("apply test definitions")
|
||||
|
||||
@@ -18,7 +18,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
@@ -51,7 +51,7 @@ var _ = Describe("Test Kubectl Plugin", func() {
|
||||
}, 5*time.Second).Should(BeNil())
|
||||
|
||||
By("dry-run application")
|
||||
err := ioutil.WriteFile("dry-run-app.yaml", []byte(application), 0644)
|
||||
err := os.WriteFile("dry-run-app.yaml", []byte(application), 0644)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
output, err := e2e.Exec("kubectl-vela dry-run -f dry-run-app.yaml -n vela-system")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@@ -91,7 +91,7 @@ var _ = Describe("Test Kubectl Plugin", func() {
|
||||
}, 5*time.Second).Should(BeNil())
|
||||
|
||||
By("live-diff application")
|
||||
err := ioutil.WriteFile("live-diff-app.yaml", []byte(newApplication), 0644)
|
||||
err := os.WriteFile("live-diff-app.yaml", []byte(newApplication), 0644)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
output, err := e2e.Exec("kubectl-vela live-diff -f live-diff-app.yaml")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -50,7 +49,7 @@ func main() {
|
||||
writeOld := func(fileName string, data []byte) {
|
||||
pathOld := fmt.Sprintf("%s/%s", oldDir, fileName)
|
||||
/* #nosec */
|
||||
if err := ioutil.WriteFile(pathOld, data, 0644); err != nil {
|
||||
if err := os.WriteFile(pathOld, data, 0644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -58,7 +57,7 @@ func main() {
|
||||
writeNew := func(fileName string, data []byte) {
|
||||
pathNew := fmt.Sprintf("%s/%s", newDir, fileName)
|
||||
/* #nosec */
|
||||
if err := ioutil.WriteFile(pathNew, data, 0644); err != nil {
|
||||
if err := os.WriteFile(pathNew, data, 0644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -66,7 +65,7 @@ func main() {
|
||||
writeRuntime := func(subPath, fileName string, data []byte) {
|
||||
pathRuntime := fmt.Sprintf("%s/%s/charts/crds/%s", runtimeDir, subPath, fileName)
|
||||
/* #nosec */
|
||||
if err := ioutil.WriteFile(pathRuntime, data, 0644); err != nil {
|
||||
if err := os.WriteFile(pathRuntime, data, 0644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -77,7 +76,7 @@ func main() {
|
||||
}
|
||||
resourceName := extractMainInfo(info.Name())
|
||||
/* #nosec */
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to read file", err)
|
||||
return err
|
||||
|
||||
@@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@@ -39,7 +38,7 @@ func main() {
|
||||
|
||||
func fixNewSchemaValidationCheck(crds []string) error {
|
||||
for _, crd := range crds {
|
||||
data, err := ioutil.ReadFile(crd)
|
||||
data, err := os.ReadFile(crd)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "reading CRD file %s hit an issue: %s\n", crd, err)
|
||||
return err
|
||||
@@ -62,7 +61,7 @@ func fixNewSchemaValidationCheck(crds []string) error {
|
||||
newData = append(newData, line)
|
||||
previousLine = line
|
||||
}
|
||||
ioutil.WriteFile(crd, []byte(strings.Join(newData, "\n")), 0644)
|
||||
os.WriteFile(crd, []byte(strings.Join(newData, "\n")), 0644)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -63,7 +62,7 @@ func GetChartSource(path string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
defer os.Remove(packagedPath)
|
||||
packaged, err := ioutil.ReadFile(packagedPath)
|
||||
packaged, err := os.ReadFile(packagedPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package main // #nosec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -38,7 +37,7 @@ func main() {
|
||||
return nil
|
||||
}
|
||||
/* #nosec */
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to read file", err)
|
||||
return err
|
||||
@@ -47,7 +46,7 @@ func main() {
|
||||
newdata = strings.ReplaceAll(newdata, "x-kubernetes-preserve-unknown-fields: true", "")
|
||||
newdata = strings.ReplaceAll(newdata, "default: false", "")
|
||||
/* #nosec */
|
||||
if err = ioutil.WriteFile(path, []byte(newdata), 0644); err != nil {
|
||||
if err = os.WriteFile(path, []byte(newdata), 0644); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to write file:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
@@ -28,11 +28,11 @@ import (
|
||||
)
|
||||
|
||||
func TestGenerateSchemaFromValues(t *testing.T) {
|
||||
testValues, err := ioutil.ReadFile("./testdata/values.yaml")
|
||||
testValues, err := os.ReadFile("./testdata/values.yaml")
|
||||
if err != nil {
|
||||
t.Error(err, "cannot load test data")
|
||||
}
|
||||
wantSchema, err := ioutil.ReadFile("./testdata/values.schema.json")
|
||||
wantSchema, err := os.ReadFile("./testdata/values.schema.json")
|
||||
if err != nil {
|
||||
t.Error(err, "cannot load expected data")
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func TestGenerateSchemaFromValues(t *testing.T) {
|
||||
|
||||
func TestGetChartValuesJSONSchema(t *testing.T) {
|
||||
testHelm := testData("podinfo", "5.1.4", "http://oam.dev/catalog", "testSecret")
|
||||
wantSchema, err := ioutil.ReadFile("./testdata/podinfo.values.schema.json")
|
||||
wantSchema, err := os.ReadFile("./testdata/podinfo.values.schema.json")
|
||||
if err != nil {
|
||||
t.Error(err, "cannot load expected data")
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
@@ -90,7 +89,7 @@ func (c *HTTPCmd) Run(meta *registry.Meta) (res interface{}, err error) {
|
||||
}
|
||||
//nolint:errcheck
|
||||
defer resp.Body.Close()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
// parse response body and headers
|
||||
return map[string]interface{}{
|
||||
"body": string(b),
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
@@ -67,7 +67,7 @@ func makeHTTPRequest(ctx context.Context, webhookEndPoint, method string, payloa
|
||||
if requestErr != nil {
|
||||
return requestErr
|
||||
}
|
||||
body, requestErr = ioutil.ReadAll(r.Body)
|
||||
body, requestErr = io.ReadAll(r.Body)
|
||||
if requestErr != nil {
|
||||
return requestErr
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package assemble
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -43,7 +43,7 @@ var _ = Describe("Test Assemble Options", func() {
|
||||
)
|
||||
|
||||
appRev := &v1beta1.ApplicationRevision{}
|
||||
b, err := ioutil.ReadFile("./testdata/apprevision.yaml")
|
||||
b, err := os.ReadFile("./testdata/apprevision.yaml")
|
||||
/* appRevision test data is generated based on below application
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
@@ -156,7 +156,7 @@ var _ = Describe("Test Assemble Options", func() {
|
||||
compName = "frontend"
|
||||
)
|
||||
appRev := &v1beta1.ApplicationRevision{}
|
||||
b, err := ioutil.ReadFile("./testdata/filter_annotations.yaml")
|
||||
b, err := os.ReadFile("./testdata/filter_annotations.yaml")
|
||||
getKeys := func(m map[string]string) []string {
|
||||
var keys []string
|
||||
for k := range m {
|
||||
|
||||
@@ -19,7 +19,7 @@ package assemble
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -49,7 +49,7 @@ var _ = Describe("Test WorkloadOption", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
appRev = &v1beta1.ApplicationRevision{}
|
||||
b, err := ioutil.ReadFile("./testdata/apprevision.yaml")
|
||||
b, err := os.ReadFile("./testdata/apprevision.yaml")
|
||||
Expect(err).Should(BeNil())
|
||||
err = yaml.Unmarshal(b, appRev)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
@@ -61,7 +61,7 @@ func (c *ComponentHandler) customComponentRevisionHook(relatedApps []reconcile.R
|
||||
}
|
||||
//nolint:errcheck
|
||||
defer resp.Body.Close()
|
||||
respData, err := ioutil.ReadAll(resp.Body)
|
||||
respData, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package applicationconfiguration
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
|
||||
var RevisionHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var req RevisionHookRequest
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
data, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(400)
|
||||
return
|
||||
|
||||
@@ -19,7 +19,7 @@ package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -218,7 +218,7 @@ func TestFixOpenAPISchema(t *testing.T) {
|
||||
schema := swagger.Components.Schemas[model.ParameterFieldName].Value
|
||||
fixOpenAPISchema("", schema)
|
||||
fixedSchema, _ := schema.MarshalJSON()
|
||||
expectedSchema, _ := ioutil.ReadFile(filepath.Join(TestDir, tc.fixedFile))
|
||||
expectedSchema, _ := os.ReadFile(filepath.Join(TestDir, tc.fixedFile))
|
||||
assert.Equal(t, string(fixedSchema), string(expectedSchema))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package cue
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetParameter(t *testing.T) {
|
||||
data, _ := ioutil.ReadFile("testdata/workloads/metrics.cue")
|
||||
data, _ := os.ReadFile("testdata/workloads/metrics.cue")
|
||||
params, err := GetParameters(string(data))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, params, []types.Parameter{
|
||||
@@ -37,7 +37,7 @@ func TestGetParameter(t *testing.T) {
|
||||
{Name: "port", Required: false, Default: int64(8080), Type: cue.IntKind},
|
||||
{Name: "selector", Required: false, Usage: "the label selector for the pods, default is the workload labels", Type: cue.StructKind},
|
||||
})
|
||||
data, _ = ioutil.ReadFile("testdata/workloads/deployment.cue")
|
||||
data, _ = os.ReadFile("testdata/workloads/deployment.cue")
|
||||
params, err = GetParameters(string(data))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []types.Parameter{
|
||||
@@ -49,7 +49,7 @@ func TestGetParameter(t *testing.T) {
|
||||
{Name: "cpu", Short: "", Required: false, Usage: "", Default: "", Type: cue.StringKind}},
|
||||
params)
|
||||
|
||||
data, _ = ioutil.ReadFile("testdata/workloads/test-param.cue")
|
||||
data, _ = os.ReadFile("testdata/workloads/test-param.cue")
|
||||
params, err = GetParameters(string(data))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []types.Parameter{
|
||||
@@ -60,14 +60,14 @@ func TestGetParameter(t *testing.T) {
|
||||
{Name: "enable", Default: false, Type: cue.BoolKind},
|
||||
{Name: "fval", Default: 64.3, Type: cue.FloatKind},
|
||||
{Name: "nval", Default: float64(0), Required: true, Type: cue.NumberKind}}, params)
|
||||
data, _ = ioutil.ReadFile("testdata/workloads/empty.cue")
|
||||
data, _ = os.ReadFile("testdata/workloads/empty.cue")
|
||||
params, err = GetParameters(string(data))
|
||||
assert.NoError(t, err)
|
||||
var exp []types.Parameter
|
||||
assert.Equal(t, exp, params)
|
||||
|
||||
data, _ = ioutil.ReadFile("testdata/workloads/webservice.cue") // test cue parameter with "// +ignore" annotation
|
||||
params, err = GetParameters(string(data)) // Only test for func RetrieveComments
|
||||
data, _ = os.ReadFile("testdata/workloads/webservice.cue") // test cue parameter with "// +ignore" annotation
|
||||
params, err = GetParameters(string(data)) // Only test for func RetrieveComments
|
||||
assert.NoError(t, err)
|
||||
var flag bool
|
||||
for _, para := range params {
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -103,7 +102,7 @@ func HTTPGet(ctx context.Context, url string) ([]byte, error) {
|
||||
}
|
||||
//nolint:errcheck
|
||||
defer resp.Body.Close()
|
||||
return ioutil.ReadAll(resp.Body)
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// GetCUEParameterValue converts definitions to cue format
|
||||
@@ -240,7 +239,7 @@ func AskToChooseOneService(svcNames []string) (string, error) {
|
||||
|
||||
// ReadYamlToObject will read a yaml K8s object to runtime.Object
|
||||
func ReadYamlToObject(path string, object k8sruntime.Object) error {
|
||||
data, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
data, err := os.ReadFile(filepath.Clean(path))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -212,7 +211,7 @@ func TestGenOpenAPI(t *testing.T) {
|
||||
if tc.want.targetSchemaFile == "" {
|
||||
return
|
||||
}
|
||||
wantSchema, _ := ioutil.ReadFile(filepath.Join("testdata", tc.want.targetSchemaFile))
|
||||
wantSchema, _ := os.ReadFile(filepath.Join("testdata", tc.want.targetSchemaFile))
|
||||
if diff := cmp.Diff(wantSchema, got); diff != "" {
|
||||
t.Errorf("\n%s\nGenOpenAPIFromFile(...): -want, +got:\n%s", tc.reason, diff)
|
||||
}
|
||||
@@ -232,7 +231,7 @@ func TestRealtimePrintCommandOutput(t *testing.T) {
|
||||
err = RealtimePrintCommandOutput(cmd, logFile)
|
||||
assert.NoError(t, err)
|
||||
|
||||
data, _ := ioutil.ReadFile(logFile)
|
||||
data, _ := os.ReadFile(logFile)
|
||||
assert.Contains(t, string(data), hello)
|
||||
os.Remove(logFile)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package config
|
||||
import (
|
||||
b64 "encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -67,7 +66,7 @@ func ReadConfig(envName, configName string) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
cfgFile := filepath.Join(d, configName)
|
||||
b, err := ioutil.ReadFile(filepath.Clean(cfgFile))
|
||||
b, err := os.ReadFile(filepath.Clean(cfgFile))
|
||||
if os.IsNotExist(err) {
|
||||
return []byte{}, nil
|
||||
}
|
||||
@@ -81,5 +80,5 @@ func WriteConfig(envName, configName string, data []byte) error {
|
||||
return err
|
||||
}
|
||||
cfgFile := filepath.Join(d, configName)
|
||||
return ioutil.WriteFile(cfgFile, data, 0600)
|
||||
return os.WriteFile(cfgFile, data, 0600)
|
||||
}
|
||||
|
||||
17
pkg/utils/env/env.go
vendored
17
pkg/utils/env/env.go
vendored
@@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -43,7 +42,7 @@ func GetEnvDirByName(name string) string {
|
||||
|
||||
// GetEnvByName will get env info by name
|
||||
func GetEnvByName(name string) (*types.EnvMeta, error) {
|
||||
data, err := ioutil.ReadFile(filepath.Join(GetEnvDirByName(name), system.EnvConfigName))
|
||||
data, err := os.ReadFile(filepath.Join(GetEnvDirByName(name), system.EnvConfigName))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("env %s not exist", name)
|
||||
@@ -106,7 +105,7 @@ func CreateOrUpdateEnv(ctx context.Context, c client.Client, envName string, env
|
||||
return message, err
|
||||
}
|
||||
// nolint:gosec
|
||||
if err = ioutil.WriteFile(filepath.Join(subEnvDir, system.EnvConfigName), data, 0644); err != nil {
|
||||
if err = os.WriteFile(filepath.Join(subEnvDir, system.EnvConfigName), data, 0644); err != nil {
|
||||
return message, err
|
||||
}
|
||||
curEnvPath, err := system.GetCurrentEnvPath()
|
||||
@@ -114,7 +113,7 @@ func CreateOrUpdateEnv(ctx context.Context, c client.Client, envName string, env
|
||||
return message, err
|
||||
}
|
||||
// nolint:gosec
|
||||
if err = ioutil.WriteFile(curEnvPath, []byte(envName), 0644); err != nil {
|
||||
if err = os.WriteFile(curEnvPath, []byte(envName), 0644); err != nil {
|
||||
return message, err
|
||||
}
|
||||
|
||||
@@ -156,7 +155,7 @@ func UpdateEnv(ctx context.Context, c client.Client, envName string, namespace s
|
||||
}
|
||||
subEnvDir := filepath.Join(envdir, envName)
|
||||
// nolint:gosec
|
||||
if err = ioutil.WriteFile(filepath.Join(subEnvDir, system.EnvConfigName), data, 0644); err != nil {
|
||||
if err = os.WriteFile(filepath.Join(subEnvDir, system.EnvConfigName), data, 0644); err != nil {
|
||||
return message, err
|
||||
}
|
||||
message = "Update env succeed"
|
||||
@@ -181,7 +180,7 @@ func ListEnvs(envName string) ([]*types.EnvMeta, error) {
|
||||
if err != nil {
|
||||
return envList, err
|
||||
}
|
||||
files, err := ioutil.ReadDir(envDir)
|
||||
files, err := os.ReadDir(envDir)
|
||||
if err != nil {
|
||||
return envList, err
|
||||
}
|
||||
@@ -193,7 +192,7 @@ func ListEnvs(envName string) ([]*types.EnvMeta, error) {
|
||||
if !f.IsDir() {
|
||||
continue
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(filepath.Join(envDir, f.Name(), system.EnvConfigName)))
|
||||
data, err := os.ReadFile(filepath.Clean(filepath.Join(envDir, f.Name(), system.EnvConfigName)))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -215,7 +214,7 @@ func GetCurrentEnvName() (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(currentEnvPath))
|
||||
data, err := os.ReadFile(filepath.Clean(currentEnvPath))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -264,7 +263,7 @@ func SetEnv(envName string) (string, error) {
|
||||
return msg, err
|
||||
}
|
||||
//nolint:gosec
|
||||
if err = ioutil.WriteFile(currentEnvPath, []byte(envName), 0644); err != nil {
|
||||
if err = os.WriteFile(currentEnvPath, []byte(envName), 0644); err != nil {
|
||||
return msg, err
|
||||
}
|
||||
msg = fmt.Sprintf("Set environment succeed, current environment is " + envName + ", namespace is " + envMeta.Namespace)
|
||||
|
||||
@@ -18,7 +18,6 @@ package system
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -153,7 +152,7 @@ func InitDefaultEnv() error {
|
||||
}
|
||||
data, _ := json.Marshal(&types.EnvMeta{Namespace: types.DefaultAppNamespace, Name: types.DefaultEnvName})
|
||||
//nolint:gosec
|
||||
if err = ioutil.WriteFile(filepath.Join(defaultEnvDir, EnvConfigName), data, 0644); err != nil {
|
||||
if err = os.WriteFile(filepath.Join(defaultEnvDir, EnvConfigName), data, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
curEnvPath, err := GetCurrentEnvPath()
|
||||
@@ -161,7 +160,7 @@ func InitDefaultEnv() error {
|
||||
return err
|
||||
}
|
||||
//nolint:gosec
|
||||
if err = ioutil.WriteFile(curEnvPath, []byte(types.DefaultEnvName), 0644); err != nil {
|
||||
if err = os.WriteFile(curEnvPath, []byte(types.DefaultEnvName), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package http
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -113,7 +113,7 @@ func runMockServer(shutdown chan struct{}) {
|
||||
w.Write([]byte("hello"))
|
||||
})
|
||||
http.HandleFunc("/echo", func(w http.ResponseWriter, req *http.Request) {
|
||||
bt, _ := ioutil.ReadAll(req.Body)
|
||||
bt, _ := io.ReadAll(req.Body)
|
||||
w.Write(bt)
|
||||
})
|
||||
srv := &http.Server{Addr: ":1229"}
|
||||
|
||||
@@ -19,7 +19,6 @@ package appfile
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -95,7 +94,7 @@ func ApplyTerraform(app *v1beta1.Application, k8sClient client.Client, ioStream
|
||||
return nil, fmt.Errorf("failed to create directory for %s: %w", tfJSONDir, err)
|
||||
}
|
||||
}
|
||||
if err := ioutil.WriteFile(filepath.Join(tfJSONDir, "main.tf.json"), tf, 0600); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(tfJSONDir, "main.tf.json"), tf, 0600); err != nil {
|
||||
return nil, fmt.Errorf("failed to convert Terraform template: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package appfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -91,7 +90,7 @@ var _ = BeforeSuite(func(done Done) {
|
||||
|
||||
Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: addonNamespace}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
workloadData, err := ioutil.ReadFile("testdata/workloadDef.yaml")
|
||||
workloadData, err := os.ReadFile("testdata/workloadDef.yaml")
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
Expect(yaml.Unmarshal(workloadData, &wd)).Should(BeNil())
|
||||
@@ -100,7 +99,7 @@ var _ = BeforeSuite(func(done Done) {
|
||||
logf.Log.Info("Creating workload definition", "data", wd)
|
||||
Expect(k8sClient.Create(ctx, &wd)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
def, err := ioutil.ReadFile("testdata/terraform-aliyun-oss-workloadDefinition.yaml")
|
||||
def, err := os.ReadFile("testdata/terraform-aliyun-oss-workloadDefinition.yaml")
|
||||
Expect(err).Should(BeNil())
|
||||
var terraformDefinition corev1beta1.WorkloadDefinition
|
||||
Expect(yaml.Unmarshal(def, &terraformDefinition)).Should(BeNil())
|
||||
|
||||
@@ -19,7 +19,6 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -104,7 +103,7 @@ func JSONToYaml(data []byte, appFile *AppFile) (*AppFile, error) {
|
||||
|
||||
// LoadFromFile will read the file and load the AppFile struct
|
||||
func LoadFromFile(filename string) (*AppFile, error) {
|
||||
b, err := ioutil.ReadFile(filepath.Clean(filename))
|
||||
b, err := os.ReadFile(filepath.Clean(filename))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package driver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -63,7 +62,7 @@ func (l *Local) Save(app *api.Application, envName string) error {
|
||||
return err
|
||||
}
|
||||
//nolint:gosec
|
||||
return ioutil.WriteFile(filepath.Join(appDir, app.Name+".yaml"), out, 0644)
|
||||
return os.WriteFile(filepath.Join(appDir, app.Name+".yaml"), out, 0644)
|
||||
}
|
||||
|
||||
// Delete application from local storage
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package driver
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -47,7 +47,7 @@ func init() {
|
||||
}
|
||||
afile.Services = svcs
|
||||
out, _ := yaml.Marshal(afile)
|
||||
_ = ioutil.WriteFile(filepath.Join(dir, appName+".yaml"), out, 0644)
|
||||
_ = os.WriteFile(filepath.Join(dir, appName+".yaml"), out, 0644)
|
||||
}
|
||||
|
||||
func TestLocalDelete(t *testing.T) {
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package dryrun
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -118,6 +118,6 @@ var _ = AfterSuite(func() {
|
||||
})
|
||||
|
||||
func readDataFromFile(path string) string {
|
||||
b, _ := ioutil.ReadFile(path)
|
||||
b, _ := os.ReadFile(path)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"bytes"
|
||||
b64 "encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -105,7 +105,7 @@ func ListConfigs(ioStreams cmdutil.IOStreams, cmd *cobra.Command) error {
|
||||
}
|
||||
|
||||
func listConfigs(dir string) ([]string, error) {
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
@@ -127,7 +126,7 @@ func (o *Options) GetStaticPath() error {
|
||||
}
|
||||
tgzpath := filepath.Join(o.staticPath, "frontend.tgz")
|
||||
//nolint:gosec
|
||||
err = ioutil.WriteFile(tgzpath, data, 0644)
|
||||
err = os.WriteFile(tgzpath, data, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write frontend.tgz to static path err %w", err)
|
||||
}
|
||||
@@ -139,7 +138,7 @@ func (o *Options) GetStaticPath() error {
|
||||
if err = tgz.Unarchive(tgzpath, o.staticPath); err != nil {
|
||||
return fmt.Errorf("write static files to fontend dir err %w", err)
|
||||
}
|
||||
files, err := ioutil.ReadDir(o.staticPath)
|
||||
files, err := os.ReadDir(o.staticPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read static file %s err %w", o.staticPath, err)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@@ -119,7 +118,7 @@ func loadYAMLBytesFromFileOrHTTP(pathOrURL string) ([]byte, error) {
|
||||
if strings.HasPrefix(pathOrURL, "http://") || strings.HasPrefix(pathOrURL, "https://") {
|
||||
return common.HTTPGet(context.Background(), pathOrURL)
|
||||
}
|
||||
return ioutil.ReadFile(path.Clean(pathOrURL))
|
||||
return os.ReadFile(path.Clean(pathOrURL))
|
||||
}
|
||||
|
||||
func buildTemplateFromYAML(templateYAML string, def *common2.Definition) error {
|
||||
@@ -256,7 +255,7 @@ func NewDefinitionInitCommand(c common.Args) *cobra.Command {
|
||||
return errors.Wrapf(err, "failed to generate cue string")
|
||||
}
|
||||
if output != "" {
|
||||
if err = ioutil.WriteFile(path.Clean(output), []byte(cueString), 0600); err != nil {
|
||||
if err = os.WriteFile(path.Clean(output), []byte(cueString), 0600); err != nil {
|
||||
return errors.Wrapf(err, "failed to write definition into %s", output)
|
||||
}
|
||||
cmd.Printf("Definition written to %s\n", output)
|
||||
@@ -431,7 +430,7 @@ func NewDefinitionEditCommand(c common.Args) *cobra.Command {
|
||||
}
|
||||
filename := fmt.Sprintf("vela-def-%d", time.Now().UnixNano())
|
||||
tempFilePath := filepath.Join(os.TempDir(), filename+".cue")
|
||||
if err := ioutil.WriteFile(tempFilePath, []byte(cueString), 0600); err != nil {
|
||||
if err := os.WriteFile(tempFilePath, []byte(cueString), 0600); err != nil {
|
||||
return errors.Wrapf(err, "failed to write temporary file")
|
||||
}
|
||||
defer cleanup(tempFilePath)
|
||||
@@ -440,7 +439,7 @@ func NewDefinitionEditCommand(c common.Args) *cobra.Command {
|
||||
editor = "vi"
|
||||
}
|
||||
scriptFilePath := filepath.Join(os.TempDir(), filename+".sh")
|
||||
if err := ioutil.WriteFile(scriptFilePath, []byte(editor+" "+tempFilePath), 0600); err != nil {
|
||||
if err := os.WriteFile(scriptFilePath, []byte(editor+" "+tempFilePath), 0600); err != nil {
|
||||
return errors.Wrapf(err, "failed to write temporary script file")
|
||||
}
|
||||
defer cleanup(scriptFilePath)
|
||||
@@ -452,7 +451,7 @@ func NewDefinitionEditCommand(c common.Args) *cobra.Command {
|
||||
if err = editCmd.Run(); err != nil {
|
||||
return errors.Wrapf(err, "failed to run editor %s at path %s", editor, scriptFilePath)
|
||||
}
|
||||
newBuf, err := ioutil.ReadFile(path.Clean(tempFilePath))
|
||||
newBuf, err := os.ReadFile(path.Clean(tempFilePath))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to read temporary file %s", tempFilePath)
|
||||
}
|
||||
@@ -540,7 +539,7 @@ func NewDefinitionRenderCommand(c common.Args) *cobra.Command {
|
||||
s = "# " + strings.ReplaceAll(message, "{{INPUT_FILENAME}}", filepath.Base(inputFilename)) + "\n" + s
|
||||
}
|
||||
s = "# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.\n" + s
|
||||
if err := ioutil.WriteFile(outputFilename, []byte(s), 0600); err != nil {
|
||||
if err := os.WriteFile(outputFilename, []byte(s), 0600); err != nil {
|
||||
return errors.Wrapf(err, "failed to write YAML format definition to file %s", outputFilename)
|
||||
}
|
||||
}
|
||||
@@ -741,7 +740,7 @@ func NewDefinitionValidateCommand(c common.Args) *cobra.Command {
|
||||
"> vela def vet my-def.cue",
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cueBytes, err := ioutil.ReadFile(args[0])
|
||||
cueBytes, err := os.ReadFile(args[0])
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to read %s", args[0])
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package cli
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -53,8 +53,8 @@ func initCommand(cmd *cobra.Command) {
|
||||
cmd.SilenceErrors = true
|
||||
cmd.SilenceUsage = true
|
||||
cmd.Flags().StringP("env", "", "", "")
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetErr(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetErr(io.Discard)
|
||||
}
|
||||
|
||||
func createTrait(c common2.Args, t *testing.T) string {
|
||||
@@ -119,7 +119,7 @@ func createLocalTrait(t *testing.T) (string, string) {
|
||||
}
|
||||
|
||||
func createLocalTraits(t *testing.T) string {
|
||||
dirname, err := ioutil.TempDir(os.TempDir(), "vela-def-test-*")
|
||||
dirname, err := os.MkdirTemp(os.TempDir(), "vela-def-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temporary directory: %v", err)
|
||||
}
|
||||
@@ -286,7 +286,7 @@ func TestNewDefinitionRenderCommand(t *testing.T) {
|
||||
_ = os.Setenv(HelmChartFormatEnvName, "system")
|
||||
dirname := createLocalTraits(t)
|
||||
defer removeDir(dirname, t)
|
||||
outputDir, err := ioutil.TempDir(os.TempDir(), "vela-def-tests-output-*")
|
||||
outputDir, err := os.MkdirTemp(os.TempDir(), "vela-def-tests-output-*")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temporary output dir: %v", err)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -171,7 +170,7 @@ func ReadObjectsFromFile(path string) ([]oam.Object, error) {
|
||||
|
||||
var objs []oam.Object
|
||||
//nolint:gosec
|
||||
fis, err := ioutil.ReadDir(path)
|
||||
fis, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -195,7 +194,7 @@ func ReadObjectsFromFile(path string) ([]oam.Object, error) {
|
||||
|
||||
func readApplicationFromFile(filename string) (*corev1beta1.Application, error) {
|
||||
|
||||
fileContent, err := ioutil.ReadFile(filepath.Clean(filename))
|
||||
fileContent, err := os.ReadFile(filepath.Clean(filename))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
@@ -96,7 +96,7 @@ func NewInitCommand(c common2.Args, ioStreams cmdutil.IOStreams) *cobra.Command
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile("./vela.yaml", b, 0600)
|
||||
err = os.WriteFile("./vela.yaml", b, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -288,7 +287,7 @@ func generateIndexHTML(docsPath string) error {
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
return ioutil.WriteFile(filepath.Join(docsPath, IndexHTML), []byte(indexHTML), 0600)
|
||||
return os.WriteFile(filepath.Join(docsPath, IndexHTML), []byte(indexHTML), 0600)
|
||||
}
|
||||
|
||||
func generateCustomCSS(docsPath string) error {
|
||||
@@ -296,7 +295,7 @@ func generateCustomCSS(docsPath string) error {
|
||||
body {
|
||||
overflow: auto !important;
|
||||
}`
|
||||
return ioutil.WriteFile(filepath.Join(docsPath, CSS), []byte(css), 0600)
|
||||
return os.WriteFile(filepath.Join(docsPath, CSS), []byte(css), 0600)
|
||||
}
|
||||
|
||||
func generateREADME(capabilities []types.Capability, docsPath string) error {
|
||||
|
||||
@@ -18,7 +18,6 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -73,7 +72,7 @@ func TestGenerateSideBar(t *testing.T) {
|
||||
if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" {
|
||||
t.Errorf("\n%s\ngenerateSideBar(...): -want error, +got error:\n%s", tc.reason, diff)
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(filepath.Join(TestDir, SideBar)))
|
||||
data, err := os.ReadFile(filepath.Clean(filepath.Join(TestDir, SideBar)))
|
||||
assert.NoError(t, err)
|
||||
for _, c := range tc.capabilities {
|
||||
assert.Contains(t, string(data), c.Name)
|
||||
@@ -130,7 +129,7 @@ func TestGenerateREADME(t *testing.T) {
|
||||
if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" {
|
||||
t.Errorf("\n%s\ngenerateREADME(...): -want error, +got error:\n%s", tc.reason, diff)
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(filepath.Join(TestDir, README)))
|
||||
data, err := os.ReadFile(filepath.Clean(filepath.Join(TestDir, README)))
|
||||
assert.NoError(t, err)
|
||||
for _, c := range tc.capabilities {
|
||||
switch c.Type {
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package cli
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -61,7 +61,7 @@ func NewUpCommand(c common2.Args, ioStream cmdutil.IOStreams) *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileContent, err := ioutil.ReadFile(filepath.Clean(filePath))
|
||||
fileContent, err := os.ReadFile(filepath.Clean(filePath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
j "encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -362,7 +361,7 @@ func saveAndLoadRemoteAppfile(url string) (*api.AppFile, error) {
|
||||
return nil, err
|
||||
}
|
||||
//nolint:gosec
|
||||
return af, ioutil.WriteFile(dest, body, 0644)
|
||||
return af, os.WriteFile(dest, body, 0644)
|
||||
}
|
||||
|
||||
// ExportFromAppFile exports Application from appfile object
|
||||
@@ -450,7 +449,7 @@ func (o *AppfileOptions) BaseAppFileRun(result *BuildResult, data []byte, args c
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(deployFilePath, data, 0600); err != nil {
|
||||
if err := os.WriteFile(deployFilePath, data, 0600); err != nil {
|
||||
return errors.Wrap(err, "write deploy config manifests failed")
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -108,7 +107,7 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
|
||||
return err
|
||||
}
|
||||
defDir, _ := system.GetCapabilityDir()
|
||||
fileContent, err := ioutil.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.Name+".yaml")))
|
||||
fileContent, err := os.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.Name+".yaml")))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -384,7 +383,7 @@ func ListCapabilities(userNamespace string, c common.Args, capabilityCenterName
|
||||
if capabilityCenterName != "" {
|
||||
return listCenterCapabilities(userNamespace, c, filepath.Join(dir, capabilityCenterName))
|
||||
}
|
||||
dirs, err := ioutil.ReadDir(dir)
|
||||
dirs, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return capabilityList, err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -189,7 +188,7 @@ func LoadRepos() ([]CapCenterConfig, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(config))
|
||||
data, err := os.ReadFile(filepath.Clean(config))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return []CapCenterConfig{defaultRepo}, nil
|
||||
@@ -224,7 +223,7 @@ func StoreRepos(repos []CapCenterConfig) error {
|
||||
return err
|
||||
}
|
||||
//nolint:gosec
|
||||
return ioutil.WriteFile(config, data, 0644)
|
||||
return os.WriteFile(config, data, 0644)
|
||||
}
|
||||
|
||||
// ParseCapability will convert config from remote center to capability
|
||||
@@ -292,7 +291,7 @@ func (g *GithubRegistry) SyncCapabilityFromCenter() error {
|
||||
continue
|
||||
}
|
||||
//nolint:gosec
|
||||
err = ioutil.WriteFile(filepath.Join(repoDir, addon.Name+".yaml"), item.data, 0644)
|
||||
err = os.WriteFile(filepath.Join(repoDir, addon.Name+".yaml"), item.data, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("write definition %s to %s err %v\n", addon.Name+".yaml", repoDir, err)
|
||||
continue
|
||||
@@ -333,7 +332,7 @@ func (o *OssRegistry) SyncCapabilityFromCenter() error {
|
||||
continue
|
||||
}
|
||||
//nolint:gosec
|
||||
err = ioutil.WriteFile(filepath.Join(repoDir, addon.Name+".yaml"), item.data, 0644)
|
||||
err = os.WriteFile(filepath.Join(repoDir, addon.Name+".yaml"), item.data, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("write definition %s to %s err %v\n", addon.Name+".yaml", repoDir, err)
|
||||
continue
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -184,13 +184,13 @@ var _ = Describe("test GetCapabilityByName", func() {
|
||||
Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: defaultNS}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
By("create ComponentDefinition")
|
||||
data, _ := ioutil.ReadFile("testdata/componentDef.yaml")
|
||||
data, _ := os.ReadFile("testdata/componentDef.yaml")
|
||||
yaml.Unmarshal(data, &cd1)
|
||||
yaml.Unmarshal(data, &cd2)
|
||||
data2, _ := ioutil.ReadFile("testdata/kube-worker.yaml")
|
||||
data2, _ := os.ReadFile("testdata/kube-worker.yaml")
|
||||
yaml.Unmarshal(data2, &cd3)
|
||||
|
||||
helmYaml, _ := ioutil.ReadFile("testdata/helm.yaml")
|
||||
helmYaml, _ := os.ReadFile("testdata/helm.yaml")
|
||||
yaml.Unmarshal(helmYaml, &cd4)
|
||||
|
||||
cd1.Namespace = ns
|
||||
@@ -210,10 +210,10 @@ var _ = Describe("test GetCapabilityByName", func() {
|
||||
Expect(k8sClient.Create(ctx, &cd4)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
By("create TraitDefinition")
|
||||
data, _ = ioutil.ReadFile("testdata/manualscalars.yaml")
|
||||
data, _ = os.ReadFile("testdata/manualscalars.yaml")
|
||||
yaml.Unmarshal(data, &td1)
|
||||
yaml.Unmarshal(data, &td2)
|
||||
data3, _ := ioutil.ReadFile("testdata/svcTraitDef.yaml")
|
||||
data3, _ := os.ReadFile("testdata/svcTraitDef.yaml")
|
||||
yaml.Unmarshal(data3, &td3)
|
||||
td1.Namespace = ns
|
||||
td1.Name = trait1
|
||||
@@ -311,7 +311,7 @@ var _ = Describe("test GetNamespacedCapabilitiesFromCluster", func() {
|
||||
Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: defaultNS}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
By("create ComponentDefinition")
|
||||
data, _ := ioutil.ReadFile("testdata/componentDef.yaml")
|
||||
data, _ := os.ReadFile("testdata/componentDef.yaml")
|
||||
yaml.Unmarshal(data, &cd1)
|
||||
yaml.Unmarshal(data, &cd2)
|
||||
cd1.Namespace = ns
|
||||
@@ -323,7 +323,7 @@ var _ = Describe("test GetNamespacedCapabilitiesFromCluster", func() {
|
||||
Expect(k8sClient.Create(ctx, &cd2)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
By("create TraitDefinition")
|
||||
data, _ = ioutil.ReadFile("testdata/manualscalars.yaml")
|
||||
data, _ = os.ReadFile("testdata/manualscalars.yaml")
|
||||
yaml.Unmarshal(data, &td1)
|
||||
yaml.Unmarshal(data, &td2)
|
||||
td1.Namespace = ns
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -125,7 +124,7 @@ func loadInstalledCapabilityWithCapName(dir string, capT types.CapType, capName
|
||||
|
||||
func loadInstalledCapability(dir string, name string) ([]types.Capability, error) {
|
||||
var tmps []types.Capability
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
@@ -139,7 +138,7 @@ func loadInstalledCapability(dir string, name string) ([]types.Capability, error
|
||||
if strings.HasSuffix(f.Name(), ".cue") {
|
||||
continue
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(filepath.Join(dir, f.Name())))
|
||||
data, err := os.ReadFile(filepath.Clean(filepath.Join(dir, f.Name())))
|
||||
if err != nil {
|
||||
fmt.Printf("read file %s err %v\n", f.Name(), err)
|
||||
continue
|
||||
@@ -192,7 +191,7 @@ func SinkTemp2Local(templates []types.Capability, dir string) int {
|
||||
continue
|
||||
}
|
||||
//nolint:gosec
|
||||
err = ioutil.WriteFile(filepath.Join(subDir, tmp.Name), data, 0644)
|
||||
err = os.WriteFile(filepath.Join(subDir, tmp.Name), data, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("sync %s err: %v\n", tmp.Name, err)
|
||||
continue
|
||||
@@ -240,7 +239,7 @@ func RemoveLegacyTemps(retainedTemps []types.Capability, dir string) int {
|
||||
// LoadCapabilityFromSyncedCenter will load capability from dir
|
||||
func LoadCapabilityFromSyncedCenter(mapper discoverymapper.DiscoveryMapper, dir string) ([]types.Capability, error) {
|
||||
var tmps []types.Capability
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
@@ -254,7 +253,7 @@ func LoadCapabilityFromSyncedCenter(mapper discoverymapper.DiscoveryMapper, dir
|
||||
if strings.HasSuffix(f.Name(), ".cue") {
|
||||
continue
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(filepath.Join(dir, f.Name())))
|
||||
data, err := os.ReadFile(filepath.Clean(filepath.Join(dir, f.Name())))
|
||||
if err != nil {
|
||||
fmt.Printf("read file %s err %v\n", f.Name(), err)
|
||||
continue
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -668,7 +667,7 @@ func (ref *MarkdownReference) generateConflictWithAndMore(capabilityName string,
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to locate conflictWith file: %w", err)
|
||||
}
|
||||
data, err := ioutil.ReadFile(filepath.Clean(conflictWithFile))
|
||||
data, err := os.ReadFile(filepath.Clean(conflictWithFile))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -179,7 +179,7 @@ func (o OssRegistry) GetCap(addonName string) (types.Capability, []byte, error)
|
||||
if err != nil {
|
||||
return types.Capability{}, nil, err
|
||||
}
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if err != nil {
|
||||
return types.Capability{}, nil, err
|
||||
@@ -224,7 +224,7 @@ func (o OssRegistry) getRegFiles() ([]RegistryFile, error) {
|
||||
if err != nil {
|
||||
return []RegistryFile{}, err
|
||||
}
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if err != nil {
|
||||
return []RegistryFile{}, err
|
||||
@@ -248,7 +248,7 @@ func (o OssRegistry) getRegFiles() ([]RegistryFile, error) {
|
||||
fmt.Printf("[WARN] %s download fail\n", fileName)
|
||||
continue
|
||||
}
|
||||
data, _ := ioutil.ReadAll(resp.Body)
|
||||
data, _ := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
rf := RegistryFile{
|
||||
data: data,
|
||||
@@ -291,7 +291,7 @@ func (l LocalRegistry) ListCaps() ([]types.Capability, error) {
|
||||
capas := make([]types.Capability, 0)
|
||||
for _, file := range files {
|
||||
// nolint:gosec
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -96,7 +95,7 @@ var _ = BeforeSuite(func(done Done) {
|
||||
|
||||
Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: DefinitionNamespace}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
workloaddata, err := ioutil.ReadFile("testdata/workloadDef.yaml")
|
||||
workloaddata, err := os.ReadFile("testdata/workloadDef.yaml")
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
Expect(yaml.Unmarshal(workloaddata, &wd)).Should(BeNil())
|
||||
@@ -105,7 +104,7 @@ var _ = BeforeSuite(func(done Done) {
|
||||
logf.Log.Info("Creating workload definition", "data", wd)
|
||||
Expect(k8sClient.Create(ctx, &wd)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
componentdata, err := ioutil.ReadFile("testdata/componentDef.yaml")
|
||||
componentdata, err := os.ReadFile("testdata/componentDef.yaml")
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
Expect(yaml.Unmarshal(componentdata, &cd)).Should(BeNil())
|
||||
@@ -114,7 +113,7 @@ var _ = BeforeSuite(func(done Done) {
|
||||
logf.Log.Info("Creating component definition", "data", cd)
|
||||
Expect(k8sClient.Create(ctx, &cd)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
websvcWorkloadData, err := ioutil.ReadFile("testdata/websvcWorkloadDef.yaml")
|
||||
websvcWorkloadData, err := os.ReadFile("testdata/websvcWorkloadDef.yaml")
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
Expect(yaml.Unmarshal(websvcWorkloadData, &websvcWD)).Should(BeNil())
|
||||
@@ -122,7 +121,7 @@ var _ = BeforeSuite(func(done Done) {
|
||||
logf.Log.Info("Creating workload definition whose CUE template from remote", "data", &websvcWD)
|
||||
Expect(k8sClient.Create(ctx, &websvcWD)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
websvcComponentDefData, err := ioutil.ReadFile("testdata/websvcComponentDef.yaml")
|
||||
websvcComponentDefData, err := os.ReadFile("testdata/websvcComponentDef.yaml")
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
Expect(yaml.Unmarshal(websvcComponentDefData, &websvcCD)).Should(BeNil())
|
||||
|
||||
@@ -19,7 +19,6 @@ package main // #nosec
|
||||
// generate compatibility testdata
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -40,7 +39,7 @@ func main() {
|
||||
return nil
|
||||
}
|
||||
/* #nosec */
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to read file", err)
|
||||
return err
|
||||
@@ -54,7 +53,7 @@ func main() {
|
||||
}
|
||||
dstpath := dstdir + "/" + fileName
|
||||
/* #nosec */
|
||||
if err = ioutil.WriteFile(dstpath, []byte(newdata), 0644); err != nil {
|
||||
if err = os.WriteFile(dstpath, []byte(newdata), 0644); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to write file:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -85,7 +84,7 @@ type AddonInfo struct {
|
||||
}
|
||||
|
||||
func walkAllAddons(path string) ([]string, error) {
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -112,7 +111,7 @@ func newWalkFn(files *[]velaFile) filepath.WalkFunc {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
content, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
content, err := os.ReadFile(filepath.Clean(path))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user