mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Bump Go to 1.19 (#6586)
* Set Go version in go.mod go mod edit -go=1.19 * Fix formatting issues reported by gofmt * Fix SA1019 check (usage of deprecated "io/ioutil"), reported by golangci-lint SA1019: "io/ioutil" has been deprecated since Go 1.16: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck) * Use Go 1.19 in our Dockerfiles * Use Go 1.19 in the rpm-prepare.sh script * Update the tag for the IBM Cloud CI image
This commit is contained in:
2
.github/workflows/build-push-ibm-image.yaml
vendored
2
.github/workflows/build-push-ibm-image.yaml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
uses: redhat-actions/buildah-build@v2
|
||||
with:
|
||||
image: ibmcloudtest-image
|
||||
tags: v1.18-1
|
||||
tags: v1.19-1
|
||||
context: ./.ibm/images
|
||||
containerfiles: |
|
||||
./.ibm/images/Dockerfile
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.18
|
||||
FROM golang:1.19
|
||||
|
||||
RUN curl -fsSL https://clis.cloud.ibm.com/install/linux | sh && \
|
||||
curl -sLO https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_amd64.deb && \
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# This Dockerfile builds an image containing the Linux, Mac and Windows version of odo
|
||||
# layered on top of the ubi7/ubi image.
|
||||
|
||||
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.18 AS builder
|
||||
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.19 AS builder
|
||||
|
||||
COPY . /go/src/github.com/redhat-developer/odo
|
||||
WORKDIR /go/src/github.com/redhat-developer/odo
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/redhat-developer/odo
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/ActiveState/termtest v0.7.1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Dockerfile to bootstrap build and test in openshift-ci
|
||||
|
||||
FROM registry.ci.openshift.org/openshift/release:golang-1.18
|
||||
FROM registry.ci.openshift.org/openshift/release:golang-1.19
|
||||
|
||||
RUN yum -y install make wget gcc git httpd-tools
|
||||
|
||||
@@ -3,7 +3,6 @@ package preference
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
@@ -19,7 +18,7 @@ import (
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
|
||||
tempConfigFile, err := ioutil.TempFile("", "odoconfig")
|
||||
tempConfigFile, err := os.CreateTemp("", "odoconfig")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
@@ -262,7 +261,7 @@ func createRegistryDevfiles(registry api.Registry, devfileIndex []indexSchema.Sc
|
||||
func (o RegistryClient) retrieveDevfileDataFromRegistry(ctx context.Context, registryName string, devfileName string) (api.DevfileData, error) {
|
||||
|
||||
// Create random temporary file
|
||||
tmpFile, err := ioutil.TempDir("", "odo")
|
||||
tmpFile, err := os.MkdirTemp("", "odo")
|
||||
if err != nil {
|
||||
return api.DevfileData{}, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -20,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetDevfileRegistries(t *testing.T) {
|
||||
tempConfigFile, err := ioutil.TempFile("", "odoconfig")
|
||||
tempConfigFile, err := os.CreateTemp("", "odoconfig")
|
||||
if err != nil {
|
||||
t.Fatal("Fail to create temporary config file")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package registry
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -143,7 +142,7 @@ func downloadGitProject(starterProject *devfilev1.StarterProject, starterToken,
|
||||
originalPath := ""
|
||||
if starterProject.SubDir != "" {
|
||||
originalPath = path
|
||||
path, err = ioutil.TempDir("", "")
|
||||
path, err = os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestIsSecure(t *testing.T) {
|
||||
tempConfigFile, err := ioutil.TempFile("", "odoconfig")
|
||||
tempConfigFile, err := os.CreateTemp("", "odoconfig")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package segment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -15,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetRegistryOptions(t *testing.T) {
|
||||
tempConfigFile, err := ioutil.TempFile("", "odoconfig")
|
||||
tempConfigFile, err := os.CreateTemp("", "odoconfig")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/user"
|
||||
@@ -205,7 +204,7 @@ func getUserIdentity(telemetryFilePath string) (string, error) {
|
||||
|
||||
// Get-or-Create the anonymousID file that contains a UUID
|
||||
if _, err := os.Stat(telemetryFilePath); !os.IsNotExist(err) {
|
||||
id, err = ioutil.ReadFile(telemetryFilePath)
|
||||
id, err = os.ReadFile(telemetryFilePath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -214,7 +213,7 @@ func getUserIdentity(telemetryFilePath string) (string, error) {
|
||||
// check if the id is a valid uuid, if not, nil is returned
|
||||
if uuid.Parse(strings.TrimSpace(string(id))) == nil {
|
||||
id = []byte(uuid.NewRandom().String())
|
||||
if err := ioutil.WriteFile(telemetryFilePath, id, 0600); err != nil {
|
||||
if err := os.WriteFile(telemetryFilePath, id, 0600); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -53,7 +53,7 @@ func mockServer() (chan []byte, *httptest.Server) {
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
bin, err := ioutil.ReadAll(r.Body)
|
||||
bin, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
|
||||
@@ -2,8 +2,7 @@ package sync
|
||||
|
||||
import (
|
||||
"errors"
|
||||
io "io"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -362,7 +361,7 @@ func TestUpdateIndexWithWatchChanges(t *testing.T) {
|
||||
for _, fileToCreate := range tt.initialFilesToCreate {
|
||||
filePath := filepath.Join(directory, fileToCreate)
|
||||
|
||||
if err := ioutil.WriteFile(filePath, []byte("non-empty-string"), 0644); err != nil {
|
||||
if err := os.WriteFile(filePath, []byte("non-empty-string"), 0644); err != nil {
|
||||
t.Fatalf("TestUpdateIndexWithWatchChangesLocal error: unable to write to index file path: %v", err)
|
||||
}
|
||||
|
||||
@@ -397,7 +396,7 @@ func TestUpdateIndexWithWatchChanges(t *testing.T) {
|
||||
addedFilePath := filepath.Join(directory, addedFile)
|
||||
syncParams.WatchFiles = append(syncParams.WatchFiles, addedFilePath)
|
||||
|
||||
if err := ioutil.WriteFile(addedFilePath, []byte("non-empty-string"), 0644); err != nil {
|
||||
if err := os.WriteFile(addedFilePath, []byte("non-empty-string"), 0644); err != nil {
|
||||
t.Fatalf("TestUpdateIndexWithWatchChangesLocal error: unable to write to index file path: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ limitations under the License.
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DefaultFs implements Filesystem using same-named functions from "os" and "io/ioutil"
|
||||
// DefaultFs implements Filesystem using same-named functions from "os" and "io"
|
||||
type DefaultFs struct{}
|
||||
|
||||
var _ Filesystem = DefaultFs{}
|
||||
@@ -99,22 +99,22 @@ func (DefaultFs) Getwd() (dir string, err error) {
|
||||
|
||||
// ReadFile via ioutil.ReadFile
|
||||
func (DefaultFs) ReadFile(filename string) ([]byte, error) {
|
||||
return ioutil.ReadFile(filename)
|
||||
return os.ReadFile(filename)
|
||||
}
|
||||
|
||||
// WriteFile via ioutil.WriteFile
|
||||
func (DefaultFs) WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||
return ioutil.WriteFile(filename, data, perm)
|
||||
return os.WriteFile(filename, data, perm)
|
||||
}
|
||||
|
||||
// TempDir via ioutil.TempDir
|
||||
func (DefaultFs) TempDir(dir, prefix string) (string, error) {
|
||||
return ioutil.TempDir(dir, prefix)
|
||||
return os.MkdirTemp(dir, prefix)
|
||||
}
|
||||
|
||||
// TempFile via ioutil.TempFile
|
||||
func (DefaultFs) TempFile(dir, prefix string) (File, error) {
|
||||
file, err := ioutil.TempFile(dir, prefix)
|
||||
file, err := os.CreateTemp(dir, prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,7 +123,20 @@ func (DefaultFs) TempFile(dir, prefix string) (File, error) {
|
||||
|
||||
// ReadDir via ioutil.ReadDir
|
||||
func (DefaultFs) ReadDir(dirname string) ([]os.FileInfo, error) {
|
||||
return ioutil.ReadDir(dirname)
|
||||
entries, err := os.ReadDir(dirname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos := make([]fs.FileInfo, 0, len(entries))
|
||||
var info os.FileInfo
|
||||
for _, entry := range entries {
|
||||
info, err = entry.Info()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos = append(infos, info)
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
// Walk via filepath.Walk
|
||||
|
||||
@@ -2,14 +2,14 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
|
||||
)
|
||||
|
||||
// CreateIfNotExists creates the directory and the file if it doesn't exist
|
||||
@@ -59,7 +59,7 @@ func WriteToYAMLFile(c interface{}, filename string) error {
|
||||
if err = CreateIfNotExists(filename); err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filename, data, 0600)
|
||||
err = os.WriteFile(filename, data, 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to write config to file %v: %w", c, err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package util
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -55,7 +54,7 @@ func ReadFileIndex(filePath string) (*FileIndex, error) {
|
||||
return NewFileIndex(), nil
|
||||
}
|
||||
|
||||
byteValue, err := ioutil.ReadFile(filePath)
|
||||
byteValue, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -197,7 +196,7 @@ func write(filePath string, fi *FileIndex) error {
|
||||
}
|
||||
// While 0666 is the mask used when a file is created using os.Create,
|
||||
// gosec objects, so use 0600 instead
|
||||
return ioutil.WriteFile(filePath, jsonData, 0600)
|
||||
return os.WriteFile(filePath, jsonData, 0600)
|
||||
}
|
||||
|
||||
// WriteFile writes a file map to a file, the file map is given by
|
||||
@@ -483,14 +482,18 @@ func recursiveChecker(pathOptions recursiveCheckerPathOptions, ignoreRules []str
|
||||
}
|
||||
|
||||
// read the current folder and read inner files and folders
|
||||
files, err := ioutil.ReadDir(matchedPath)
|
||||
entries, err := os.ReadDir(matchedPath)
|
||||
if err != nil {
|
||||
return IndexerRet{}, err
|
||||
}
|
||||
if len(files) == 0 {
|
||||
if len(entries) == 0 {
|
||||
continue
|
||||
}
|
||||
for _, f := range files {
|
||||
for _, entry := range entries {
|
||||
f, err := entry.Info()
|
||||
if err != nil {
|
||||
return IndexerRet{}, err
|
||||
}
|
||||
if _, ok := remoteDirectories[filepath.Join(joinedRelPath, f.Name())]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -216,7 +215,7 @@ func TestGenerateNewFileDataEntry(t *testing.T) {
|
||||
t.Fatalf("TestUpdateIndexWithWatchChangesLocal error: unable to create directories for %s: %v", tt.absolutePath, err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(tt.absolutePath, []byte("non-empty-string"), 0644); err != nil {
|
||||
if err := os.WriteFile(tt.absolutePath, []byte("non-empty-string"), 0644); err != nil {
|
||||
t.Fatalf("TestUpdateIndexWithWatchChangesLocal error: unable to write to index file path: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -206,13 +205,16 @@ func CheckPathExists(path string) bool {
|
||||
// either empty or contains the devfile used.
|
||||
// TODO(feloy) sync with devfile library?
|
||||
func IsValidProjectDir(path string, devfilePath string) error {
|
||||
files, err := ioutil.ReadDir(path)
|
||||
entries, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(files) >= 1 {
|
||||
for _, file := range files {
|
||||
if len(entries) >= 1 {
|
||||
for _, entry := range entries {
|
||||
file, err := entry.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileName := file.Name()
|
||||
devfilePath = strings.TrimPrefix(devfilePath, "./")
|
||||
if !file.IsDir() && fileName == devfilePath {
|
||||
@@ -824,7 +826,7 @@ func WriteToJSONFile(c interface{}, filename string) error {
|
||||
if err = CreateIfNotExists(filename); err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filename, data, 0600)
|
||||
err = os.WriteFile(filename, data, 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to write data to file %v: %w", c, err)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -23,8 +22,9 @@ import (
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
|
||||
)
|
||||
|
||||
// TODO(feloy) Move tests to devfile library
|
||||
@@ -405,7 +405,7 @@ func TestGetAbsPath(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckPathExists(t *testing.T) {
|
||||
dir, err := ioutil.TempFile("", "")
|
||||
dir, err := os.CreateTemp("", "")
|
||||
defer os.RemoveAll(dir.Name())
|
||||
if err != nil {
|
||||
return
|
||||
@@ -1197,7 +1197,7 @@ func TestDownloadFile(t *testing.T) {
|
||||
t.Errorf("Failed to download file with error %s", err)
|
||||
}
|
||||
|
||||
got, err := ioutil.ReadFile(tt.filepath)
|
||||
got, err := os.ReadFile(tt.filepath)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to read file with error %s", err)
|
||||
}
|
||||
@@ -1562,7 +1562,7 @@ func TestValidateURL(t *testing.T) {
|
||||
func TestValidateFile(t *testing.T) {
|
||||
// Create temp dir and temp file
|
||||
tempDir := t.TempDir()
|
||||
tempFile, err := ioutil.TempFile(tempDir, "")
|
||||
tempFile, err := os.CreateTemp(tempDir, "")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create temp file: %s, error: %v", tempFile.Name(), err)
|
||||
}
|
||||
@@ -1604,7 +1604,7 @@ func TestCopyFile(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
|
||||
// Create temp file under temp dir as source file
|
||||
tempFile, err := ioutil.TempFile(tempDir, "")
|
||||
tempFile, err := os.CreateTemp(tempDir, "")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create temp file: %s, error: %v", tempFile.Name(), err)
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ export ODO_RPM_VERSION
|
||||
|
||||
# Golang version variables, if you are bumping this, please contact redhat maintainers to ensure that internal
|
||||
# build systems can handle these versions
|
||||
export GOLANG_VERSION=${GOLANG_VERSION:-1.18}
|
||||
export GOLANG_VERSION_NODOT=${GOLANG_VERSION_NODOT:-118}
|
||||
export GOLANG_VERSION=${GOLANG_VERSION:-1.19}
|
||||
export GOLANG_VERSION_NODOT=${GOLANG_VERSION_NODOT:-119}
|
||||
|
||||
# Print env for verification
|
||||
echo "Printing envs for verification"
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go-postgres/models"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"go-postgres/models"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
@@ -177,7 +178,7 @@ func DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(res)
|
||||
}
|
||||
|
||||
//------------------------- handler functions ----------------
|
||||
// ------------------------- handler functions ----------------
|
||||
// insert one user in the DB
|
||||
func insertUser(user models.User) int64 {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package helper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -19,5 +19,5 @@ ComponentSettings:
|
||||
`, compName, projectName)
|
||||
dir := filepath.Join(context, ".odo", "env")
|
||||
MakeDir(dir)
|
||||
Expect(ioutil.WriteFile(filepath.Join(dir, "env.yaml"), []byte(config), 0600)).To(BeNil())
|
||||
Expect(os.WriteFile(filepath.Join(dir, "env.yaml"), []byte(config), 0600)).To(BeNil())
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package helper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -19,7 +18,7 @@ import (
|
||||
|
||||
// CreateNewContext create new empty temporary directory
|
||||
func CreateNewContext() string {
|
||||
directory, err := ioutil.TempDir("", "")
|
||||
directory, err := os.MkdirTemp("", "")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
fmt.Fprintf(GinkgoWriter, "Created dir: %s\n", directory)
|
||||
return directory
|
||||
@@ -166,14 +165,14 @@ func CopyExampleDevFile(devfilePath, targetDst string, devfileUpdaters ...Devfil
|
||||
|
||||
// FileShouldContainSubstring check if file contains subString
|
||||
func FileShouldContainSubstring(file string, subString string) {
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(string(data)).To(ContainSubstring(subString))
|
||||
}
|
||||
|
||||
// FileShouldNotContainSubstring check if file does not contain subString
|
||||
func FileShouldNotContainSubstring(file string, subString string) {
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(string(data)).NotTo(ContainSubstring(subString))
|
||||
}
|
||||
@@ -182,12 +181,12 @@ func FileShouldNotContainSubstring(file string, subString string) {
|
||||
func ReplaceString(filename string, oldString string, newString string) {
|
||||
fmt.Fprintf(GinkgoWriter, "Replacing \"%s\" with \"%s\" in %s\n", oldString, newString, filename)
|
||||
|
||||
f, err := ioutil.ReadFile(filename)
|
||||
f, err := os.ReadFile(filename)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
newContent := strings.ReplaceAll(string(f), oldString, newString)
|
||||
|
||||
err = ioutil.WriteFile(filename, []byte(newContent), 0600)
|
||||
err = os.WriteFile(filename, []byte(newContent), 0600)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
@@ -196,7 +195,7 @@ func ReplaceString(filename string, oldString string, newString string) {
|
||||
func ReplaceStrings(filename string, oldStrings []string, newStrings []string) {
|
||||
fmt.Fprintf(GinkgoWriter, "Replacing \"%v\" with \"%v\" in %s\n", oldStrings, newStrings, filename)
|
||||
|
||||
contentByte, err := ioutil.ReadFile(filename)
|
||||
contentByte, err := os.ReadFile(filename)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
newContent := string(contentByte)
|
||||
@@ -204,7 +203,7 @@ func ReplaceStrings(filename string, oldStrings []string, newStrings []string) {
|
||||
newContent = strings.ReplaceAll(newContent, oldStrings[i], newStrings[i])
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filename, []byte(newContent), 0600)
|
||||
err = os.WriteFile(filename, []byte(newContent), 0600)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
@@ -213,12 +212,15 @@ func ReplaceStrings(filename string, oldStrings []string, newStrings []string) {
|
||||
func copyDir(src string, dst string, info os.FileInfo) error {
|
||||
|
||||
if info.IsDir() {
|
||||
files, err := ioutil.ReadDir(src)
|
||||
entries, err := os.ReadDir(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
for _, entry := range entries {
|
||||
file, err := entry.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dsrt := filepath.Join(src, file.Name())
|
||||
ddst := filepath.Join(dst, file.Name())
|
||||
if err := copyDir(dsrt, ddst, file); err != nil {
|
||||
@@ -257,10 +259,11 @@ func CreateFileWithContent(path string, fileContent string) error {
|
||||
// directoryName is the name of the directory
|
||||
func ListFilesInDir(directoryName string) []string {
|
||||
var filesInDirectory []string
|
||||
files, err := ioutil.ReadDir(directoryName)
|
||||
entries, err := os.ReadDir(directoryName)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
for _, file := range files {
|
||||
for _, entry := range entries {
|
||||
file, err := entry.Info()
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
filesInDirectory = append(filesInDirectory, file.Name())
|
||||
}
|
||||
return filesInDirectory
|
||||
@@ -278,7 +281,7 @@ func VerifyFileExists(filename string) bool {
|
||||
|
||||
// ReadFile reads the file from the filePath
|
||||
func ReadFile(filePath string) (string, error) {
|
||||
data, err := ioutil.ReadFile(filePath)
|
||||
data, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -291,7 +294,7 @@ func CreateSimpleFile(context, filePrefix, fileExtension string) (string, string
|
||||
|
||||
FilePath := filepath.Join(context, filePrefix+RandString(10)+fileExtension)
|
||||
content := []byte(RandString(10))
|
||||
err := ioutil.WriteFile(FilePath, content, 0600)
|
||||
err := os.WriteFile(FilePath, content, 0600)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
return FilePath, string(content)
|
||||
|
||||
@@ -3,7 +3,7 @@ package helper
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -36,7 +36,7 @@ func HttpWaitForWithStatus(url string, match string, maxRetry int, interval int,
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == expectedCode {
|
||||
body, _ = ioutil.ReadAll(resp.Body)
|
||||
body, _ = io.ReadAll(resp.Body)
|
||||
if strings.Contains(string(body), match) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package helper
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -498,7 +497,7 @@ func (oc OcRunner) AddSecret(comvar CommonVar) {
|
||||
newYaml := strings.Replace(yaml, "openshift-config", comvar.Project, -1)
|
||||
filename := fmt.Sprint(RandString(4), ".yaml")
|
||||
newYamlinByte := []byte(newYaml)
|
||||
err := ioutil.WriteFile(filename, newYamlinByte, 0600)
|
||||
err := os.WriteFile(filename, newYamlinByte, 0600)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package helper
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
_ "github.com/onsi/ginkgo/v2"
|
||||
@@ -36,7 +35,7 @@ func EnableTelemetryDebug() {
|
||||
cfg, _ := preference.NewClient(ctx)
|
||||
err = cfg.SetConfiguration(preference.ConsentTelemetrySetting, "true")
|
||||
Expect(err).To(BeNil())
|
||||
tempFile, err := ioutil.TempFile("", "telemetry")
|
||||
tempFile, err := os.CreateTemp("", "telemetry")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(setDebugTelemetryFile(tempFile.Name())).NotTo(HaveOccurred())
|
||||
Expect(tempFile.Close()).NotTo(HaveOccurred())
|
||||
@@ -52,11 +51,11 @@ func GetTelemetryDebugData() segment.TelemetryData {
|
||||
var td segment.TelemetryData
|
||||
telemetryFile := GetDebugTelemetryFile()
|
||||
Eventually(func() string {
|
||||
d, err := ioutil.ReadFile(telemetryFile)
|
||||
d, err := os.ReadFile(telemetryFile)
|
||||
Expect(err).To(BeNil())
|
||||
return string(d)
|
||||
}, 10, 1).Should(ContainSubstring("event"))
|
||||
data, err := ioutil.ReadFile(telemetryFile)
|
||||
data, err := os.ReadFile(telemetryFile)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(json.Unmarshal(data, &td)).NotTo(HaveOccurred())
|
||||
return td
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -2830,7 +2829,7 @@ CMD ["npm", "start"]
|
||||
|
||||
It("should remove forwarded ports from state file", func() {
|
||||
Expect(helper.VerifyFileExists(stateFile)).To(BeTrue())
|
||||
contentJSON, err := ioutil.ReadFile(stateFile)
|
||||
contentJSON, err := os.ReadFile(stateFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
helper.JsonPathContentIs(string(contentJSON), "forwardedPorts", "")
|
||||
})
|
||||
@@ -2862,7 +2861,7 @@ CMD ["npm", "start"]
|
||||
|
||||
It("should create a state file containing forwarded ports", func() {
|
||||
Expect(helper.VerifyFileExists(stateFile)).To(BeTrue())
|
||||
contentJSON, err := ioutil.ReadFile(stateFile)
|
||||
contentJSON, err := os.ReadFile(stateFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.0.containerName", "runtime")
|
||||
helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.1.containerName", "runtime")
|
||||
|
||||
@@ -3,7 +3,6 @@ package integration
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -384,7 +383,7 @@ var _ = Describe("odo devfile init command tests", func() {
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
srcDevfile = helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-parent.yaml")
|
||||
originalDevfileContent, err := ioutil.ReadFile(srcDevfile)
|
||||
originalDevfileContent, err := os.ReadFile(srcDevfile)
|
||||
Expect(err).To(BeNil())
|
||||
var content map[string]interface{}
|
||||
Expect(yaml.Unmarshal(originalDevfileContent, &content)).To(BeNil())
|
||||
@@ -395,7 +394,7 @@ var _ = Describe("odo devfile init command tests", func() {
|
||||
|
||||
It("should not replace the original devfile", func() {
|
||||
helper.Cmd("odo", "init", "--name", "aname", "--devfile-path", srcDevfile).ShouldPass()
|
||||
devfileContent, err := ioutil.ReadFile(filepath.Join(commonVar.Context, "devfile.yaml"))
|
||||
devfileContent, err := os.ReadFile(filepath.Join(commonVar.Context, "devfile.yaml"))
|
||||
Expect(err).To(BeNil())
|
||||
var content map[string]interface{}
|
||||
Expect(yaml.Unmarshal(devfileContent, &content)).To(BeNil())
|
||||
|
||||
@@ -2,7 +2,6 @@ package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -25,12 +24,12 @@ var _ = Describe("odo plugin functionality", func() {
|
||||
var handler plugins.PluginHandler
|
||||
var _ = BeforeEach(func() {
|
||||
var err error
|
||||
tempDir, err = ioutil.TempDir(os.TempDir(), "odo")
|
||||
tempDir, err = os.MkdirTemp(os.TempDir(), "odo")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
os.Setenv("PATH", fmt.Sprintf("%s:%s", origPath, tempDir))
|
||||
var baseScriptName = "tst-script"
|
||||
scriptName := path.Join(tempDir, baseScriptName)
|
||||
err = ioutil.WriteFile(scriptName, sampleScript, 0755)
|
||||
err = os.WriteFile(scriptName, sampleScript, 0755)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
handler = plugins.NewExecHandler("tst")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user