1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-09 13:47:31 +02:00

chore(deps): Replace io/ioutil package (#4494)

* update all deprecated ioutil usages

* forgotten changes

* add missing imports

* undo changing comment

* add missing 'os' import

* fix integration test

---------

Co-authored-by: I557621 <jordi.van.liempt@sap.com>
Co-authored-by: Gulom Alimov <gulomjon.alimov@sap.com>
This commit is contained in:
Jordi van Liempt 2023-08-16 12:57:04 +02:00 committed by GitHub
parent 69347fe2af
commit 0ba4c2206c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
162 changed files with 566 additions and 657 deletions

View File

@ -2,7 +2,7 @@ package cmd
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
@ -98,7 +98,7 @@ func uploadSarFiles(repos []abaputils.Repository, conn abapbuild.Connector, read
type readFile func(path string) ([]byte, error)
func reader(path string) ([]byte, error) {
return ioutil.ReadFile(path)
return os.ReadFile(path)
}
func registerPackages(repos []abaputils.Repository, conn abapbuild.Connector) ([]abaputils.Repository, error) {

View File

@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http/cookiejar"
"reflect"
"time"
@ -127,7 +127,7 @@ func triggerCheckout(repositoryName string, branchName string, checkoutConnectio
// Parse Response
var body abaputils.PullEntity
var abapResp map[string]*json.RawMessage
bodyText, errRead := ioutil.ReadAll(resp.Body)
bodyText, errRead := io.ReadAll(resp.Body)
if errRead != nil {
return uriConnectionDetails, err
}

View File

@ -5,7 +5,6 @@ package cmd
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
@ -172,7 +171,7 @@ repositories:
- name: 'testRepo3'
branch: 'testBranch3'`
err := ioutil.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
err := os.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
config := abapEnvironmentCheckoutBranchOptions{
CfAPIEndpoint: "https://api.endpoint.com",
@ -215,7 +214,7 @@ repositories:
manifestFileString := ``
manifestFileStringBody := []byte(manifestFileString)
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
config := abapEnvironmentCheckoutBranchOptions{
CfAPIEndpoint: "https://api.endpoint.com",
@ -263,7 +262,7 @@ repositories:
- repo: 'testRepo2'`
manifestFileStringBody := []byte(manifestFileString)
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
config := abapEnvironmentCheckoutBranchOptions{
CfAPIEndpoint: "https://api.endpoint.com",

View File

@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"reflect"
@ -149,7 +149,7 @@ func triggerClone(repo abaputils.Repository, cloneConnectionDetails abaputils.Co
// Parse Response
var body abaputils.CloneEntity
var abapResp map[string]*json.RawMessage
bodyText, errRead := ioutil.ReadAll(resp.Body)
bodyText, errRead := io.ReadAll(resp.Body)
if errRead != nil {
return uriConnectionDetails, err, false
}

View File

@ -6,7 +6,7 @@ package cmd
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"os"
"testing"
@ -421,7 +421,7 @@ func TestALreadyCloned(t *testing.T) {
resp := http.Response{
Status: "400 Bad Request",
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
repo := abaputils.Repository{
@ -469,7 +469,7 @@ func TestALreadyCloned(t *testing.T) {
resp := http.Response{
Status: "400 Bad Request",
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
repo := abaputils.Repository{
@ -517,7 +517,7 @@ func TestALreadyCloned(t *testing.T) {
resp := http.Response{
Status: "400 Bad Request",
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
repo := abaputils.Repository{
@ -555,7 +555,7 @@ func TestALreadyCloned(t *testing.T) {
resp := http.Response{
Status: "400 Bad Request",
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
repo := abaputils.Repository{

View File

@ -4,7 +4,6 @@
package cmd
import (
"io/ioutil"
"os"
"testing"
@ -75,7 +74,7 @@ func TestRunAbapEnvironmentCreateSystem(t *testing.T) {
plan: "testPlan"`
manifestFileStringBody := []byte(manifestFileString)
err := ioutil.WriteFile("customManifest.yml", manifestFileStringBody, 0644)
err := os.WriteFile("customManifest.yml", manifestFileStringBody, 0644)
err = runAbapEnvironmentCreateSystem(&config, nil, cf, u)
if assert.NoError(t, err) {
@ -124,7 +123,7 @@ repositories:
`
addonYMLBytes := []byte(addonYML)
err := ioutil.WriteFile("addon.yml", addonYMLBytes, 0644)
err := os.WriteFile("addon.yml", addonYMLBytes, 0644)
expectedResult := "{\"admin_email\":\"user@example.com\",\"is_development_allowed\":true,\"sapsystemname\":\"H02\",\"size_of_persistence\":4,\"size_of_runtime\":4,\"addon_product_name\":\"myProduct\",\"addon_product_version\":\"1.2.3\",\"parent_saas_appname\":\"addon_test\"}"
@ -168,7 +167,7 @@ repositories:
`
addonYMLBytes := []byte(addonYML)
err := ioutil.WriteFile("addon.yml", addonYMLBytes, 0644)
err := os.WriteFile("addon.yml", addonYMLBytes, 0644)
expectedResult := "{\"admin_email\":\"user@example.com\",\"is_development_allowed\":true,\"sapsystemname\":\"H02\",\"size_of_persistence\":4,\"size_of_runtime\":4}"
@ -214,7 +213,7 @@ repositories:
`
addonYMLBytes := []byte(addonYML)
err := ioutil.WriteFile("addon.yml", addonYMLBytes, 0644)
err := os.WriteFile("addon.yml", addonYMLBytes, 0644)
expectedResult := "{\"admin_email\":\"user@example.com\",\"is_development_allowed\":false,\"sapsystemname\":\"H02\",\"size_of_persistence\":4,\"size_of_runtime\":4,\"addon_product_name\":\"myProduct\",\"addon_product_version\":\"1.2.3\",\"parent_saas_appname\":\"addon_test\"}"

View File

@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http/cookiejar"
"strings"
"time"
@ -129,7 +129,7 @@ func createSingleTag(item CreateTagBacklog, index int, telemetryData *telemetry.
// Parse response
var createTagResponse CreateTagResponse
var abapResp map[string]*json.RawMessage
bodyText, _ := ioutil.ReadAll(resp.Body)
bodyText, _ := io.ReadAll(resp.Body)
if err = json.Unmarshal(bodyText, &abapResp); err != nil {
return err

View File

@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http/cookiejar"
"reflect"
"time"
@ -151,7 +151,7 @@ func triggerPull(repo abaputils.Repository, pullConnectionDetails abaputils.Conn
// Parse Response
var body abaputils.PullEntity
var abapResp map[string]*json.RawMessage
bodyText, errRead := ioutil.ReadAll(resp.Body)
bodyText, errRead := io.ReadAll(resp.Body)
if errRead != nil {
return uriConnectionDetails, err
}

View File

@ -5,7 +5,6 @@ package cmd
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
@ -134,7 +133,7 @@ repositories:
- name: 'testRepo3'
branch: 'testBranch3'`
err := ioutil.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
err := os.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
config := abapEnvironmentPullGitRepoOptions{
CfAPIEndpoint: "https://api.endpoint.com",
@ -370,7 +369,7 @@ repositories:
manifestFileString := ``
manifestFileStringBody := []byte(manifestFileString)
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
config := abapEnvironmentPullGitRepoOptions{
CfAPIEndpoint: "https://api.endpoint.com",
@ -419,7 +418,7 @@ repositories:
- repo: 'testRepo2'`
manifestFileStringBody := []byte(manifestFileString)
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
config := abapEnvironmentPullGitRepoOptions{
CfAPIEndpoint: "https://api.endpoint.com",

View File

@ -4,9 +4,10 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"os"
"path/filepath"
"reflect"
"strconv"
@ -151,7 +152,7 @@ func readATCSystemConfigurationFile(config *abapEnvironmentPushATCSystemConfigOp
if err != nil {
return parsedConfigurationJson, atcSystemConfiguartionJsonFile, err
}
atcSystemConfiguartionJsonFile, err = ioutil.ReadFile(filename)
atcSystemConfiguartionJsonFile, err = os.ReadFile(filename)
if err != nil {
return parsedConfigurationJson, atcSystemConfiguartionJsonFile, err
}
@ -412,7 +413,7 @@ func checkConfigExistsInBackend(config *abapEnvironmentPushATCSystemConfigOption
return false, configName, configUUID, configLastChangedAt, err
}
var body []byte
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
if err != nil {
return false, configName, configUUID, configLastChangedAt, err
}
@ -443,7 +444,7 @@ func HandleHttpResponse(resp *http.Response, err error, message string, connecti
log.Entry().WithError(err).WithField("ABAP Endpoint", connectionDetails.URL).Error("Request failed")
} else {
log.Entry().WithField("StatusCode", resp.Status).Info(message)
bodyText, readError = ioutil.ReadAll(resp.Body)
bodyText, readError = io.ReadAll(resp.Body)
if readError != nil {
defer resp.Body.Close()
return readError

View File

@ -4,9 +4,10 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"os"
"reflect"
"strconv"
"strings"
@ -84,7 +85,7 @@ func fetchAndPersistATCResults(resp *http.Response, details abaputils.Connection
// Parse response
var body []byte
if err == nil {
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
}
if err == nil {
defer resp.Body.Close()
@ -225,7 +226,7 @@ func logAndPersistAndEvaluateATCResults(utils piperutils.FileUtils, body []byte,
log.Entry().Info("There were no results from this run, most likely the checked Software Components are empty or contain no ATC findings")
}
err := ioutil.WriteFile(atcResultFileName, body, 0o644)
err := os.WriteFile(atcResultFileName, body, 0o644)
if err == nil {
log.Entry().Infof("Writing %s file was successful", atcResultFileName)
var reports []piperutils.Path
@ -242,7 +243,7 @@ func logAndPersistAndEvaluateATCResults(utils piperutils.FileUtils, body []byte,
htmlString := generateHTMLDocument(parsedXML)
htmlStringByte := []byte(htmlString)
atcResultHTMLFileName := strings.Trim(atcResultFileName, ".xml") + ".html"
err = ioutil.WriteFile(atcResultHTMLFileName, htmlStringByte, 0o644)
err = os.WriteFile(atcResultHTMLFileName, htmlStringByte, 0o644)
if err == nil {
log.Entry().Info("Writing " + atcResultHTMLFileName + " file was successful")
reports = append(reports, piperutils.Path{Target: atcResultFileName, Name: "ATC Results HTML file", Mandatory: true})
@ -317,7 +318,7 @@ func logResponseBody(resp *http.Response) error {
var bodyText []byte
var readError error
if resp != nil {
bodyText, readError = ioutil.ReadAll(resp.Body)
bodyText, readError = io.ReadAll(resp.Body)
if readError != nil {
return readError
}
@ -353,7 +354,7 @@ func pollATCRun(details abaputils.ConnectionDetailsHTTP, body []byte, client pip
if err != nil {
return "", errors.Errorf("Getting HTTP response failed: %v", err)
}
bodyText, err := ioutil.ReadAll(resp.Body)
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
return "", errors.Errorf("Reading response body failed: %v", err)
}

View File

@ -5,7 +5,6 @@ package cmd
import (
"encoding/xml"
"io/ioutil"
"os"
"testing"
@ -655,7 +654,7 @@ atcobjects:
- name: /DMO/SWC
`
err := ioutil.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
err := os.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
if assert.Equal(t, err, nil) {
bodyString, err := buildATCRequestBody(config)
assert.Equal(t, nil, err)
@ -691,7 +690,7 @@ objectset:
`
expectedBodyString := "<?xml version=\"1.0\" encoding=\"UTF-8\"?><atc:runparameters xmlns:atc=\"http://www.sap.com/adt/atc\" xmlns:obj=\"http://www.sap.com/adt/objectset\" checkVariant=\"MY_TEST\" configuration=\"MY_CONFIG\"><osl:objectSet xsi:type=\"multiPropertySet\" xmlns:osl=\"http://www.sap.com/api/osl\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><osl:package name=\"Z_TEST\"/><osl:package name=\"Z_TEST_TREE\" includeSubpackages=\"true\"/><osl:softwareComponent name=\"Z_TEST\"/><osl:softwareComponent name=\"/DMO/SWC\"/></osl:objectSet></atc:runparameters>"
err := ioutil.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
err := os.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
if assert.Equal(t, err, nil) {
bodyString, err := buildATCRequestBody(config)
assert.Equal(t, nil, err)
@ -718,7 +717,7 @@ objectset:
- name: /DMO/SWC
`
err := ioutil.WriteFile(config.Repositories, []byte(yamlBody), 0o644)
err := os.WriteFile(config.Repositories, []byte(yamlBody), 0o644)
if assert.Equal(t, err, nil) {
bodyString, err := buildATCRequestBody(config)
assert.Equal(t, nil, err)

View File

@ -5,9 +5,10 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"os"
"reflect"
"strings"
"time"
@ -148,7 +149,7 @@ func fetchAndPersistAUnitResults(resp *http.Response, details abaputils.Connecti
//Parse response
var body []byte
if err == nil {
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
}
if err == nil {
defer resp.Body.Close()
@ -293,7 +294,7 @@ func pollAUnitRun(details abaputils.ConnectionDetailsHTTP, body []byte, client p
if err != nil {
return "", fmt.Errorf("Getting HTTP response failed: %w", err)
}
bodyText, err := ioutil.ReadAll(resp.Body)
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Reading response body failed: %w", err)
}
@ -360,7 +361,7 @@ func persistAUnitResult(utils piperutils.FileUtils, body []byte, aunitResultFile
}
//Write Results
err = ioutil.WriteFile(aunitResultFileName, body, 0644)
err = os.WriteFile(aunitResultFileName, body, 0644)
if err != nil {
return fmt.Errorf("Writing results failed: %w", err)
}
@ -387,7 +388,7 @@ func persistAUnitResult(utils piperutils.FileUtils, body []byte, aunitResultFile
htmlString := generateHTMLDocumentAUnit(parsedXML)
htmlStringByte := []byte(htmlString)
aUnitResultHTMLFileName := strings.Trim(aunitResultFileName, ".xml") + ".html"
err = ioutil.WriteFile(aUnitResultHTMLFileName, htmlStringByte, 0644)
err = os.WriteFile(aUnitResultHTMLFileName, htmlStringByte, 0644)
if err != nil {
return fmt.Errorf("Writing HTML document failed: %w", err)
}

View File

@ -8,7 +8,6 @@ import (
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"os"
"testing"
@ -280,7 +279,7 @@ func TestBuildAUnitRequestBody(t *testing.T) {
branch: main
`
expectedBodyString := "<?xml version=\"1.0\" encoding=\"UTF-8\"?><aunit:run title=\"AUnit Test Run\" context=\"ABAP Environment Pipeline\" xmlns:aunit=\"http://www.sap.com/adt/api/aunit\"><aunit:options><aunit:measurements type=\"none\"/><aunit:scope ownTests=\"true\" foreignTests=\"true\"/><aunit:riskLevel harmless=\"true\" dangerous=\"true\" critical=\"true\"/><aunit:duration short=\"true\" medium=\"true\" long=\"true\"/></aunit:options><osl:objectSet xsi:type=\"multiPropertySet\" xmlns:osl=\"http://www.sap.com/api/osl\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><osl:softwareComponent name=\"/DMO/REPO\"/></osl:objectSet></aunit:run>"
err := ioutil.WriteFile(config.Repositories, []byte(repositories), 0o644)
err := os.WriteFile(config.Repositories, []byte(repositories), 0o644)
if assert.Equal(t, err, nil) {
bodyString, err := buildAUnitRequestBody(config)
assert.Equal(t, nil, err)
@ -311,7 +310,7 @@ objectset:
- name: /DMO/SWC
`
expectedBodyString := "<?xml version=\"1.0\" encoding=\"UTF-8\"?><aunit:run title=\"My AUnit run\" context=\"ABAP Environment Pipeline\" xmlns:aunit=\"http://www.sap.com/adt/api/aunit\"><aunit:options><aunit:measurements type=\"none\"/><aunit:scope ownTests=\"true\" foreignTests=\"true\"/><aunit:riskLevel harmless=\"true\" dangerous=\"true\" critical=\"true\"/><aunit:duration short=\"true\" medium=\"true\" long=\"true\"/></aunit:options><osl:objectSet xsi:type=\"multiPropertySet\" xmlns:osl=\"http://www.sap.com/api/osl\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><osl:package name=\"Z_TEST\"/><osl:softwareComponent name=\"Z_TEST\"/><osl:softwareComponent name=\"/DMO/SWC\"/></osl:objectSet></aunit:run>"
err := ioutil.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
err := os.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
if assert.Equal(t, err, nil) {
bodyString, err := buildAUnitRequestBody(config)
assert.Equal(t, nil, err)
@ -344,7 +343,7 @@ objectset:
- name: /DMO/SWC
`
expectedBodyString := "<?xml version=\"1.0\" encoding=\"UTF-8\"?><aunit:run title=\"My AUnit run\" context=\"ABAP Environment Pipeline\" xmlns:aunit=\"http://www.sap.com/adt/api/aunit\"><aunit:options><aunit:measurements type=\"none\"/><aunit:scope ownTests=\"true\" foreignTests=\"true\"/><aunit:riskLevel harmless=\"true\" dangerous=\"true\" critical=\"true\"/><aunit:duration short=\"true\" medium=\"true\" long=\"true\"/></aunit:options><osl:objectSet xsi:type=\"multiPropertySet\" xmlns:osl=\"http://www.sap.com/api/osl\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><osl:package name=\"Z_TEST\"/><osl:softwareComponent name=\"Z_TEST\"/><osl:softwareComponent name=\"/DMO/SWC\"/></osl:objectSet></aunit:run>"
err := ioutil.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
err := os.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
if assert.Equal(t, err, nil) {
bodyString, err := buildAUnitRequestBody(config)
assert.Equal(t, nil, err)
@ -419,7 +418,7 @@ objectset:
- name: Z_TEST
`
err := ioutil.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
err := os.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
if assert.Equal(t, err, nil) {
_, err := triggerAUnitrun(config, con, client)
assert.Equal(t, nil, err)
@ -473,7 +472,7 @@ objectset:
- name: Z_TEST_SC
`
err := ioutil.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
err := os.WriteFile(config.AUnitConfig, []byte(yamlBody), 0o644)
if assert.Equal(t, err, nil) {
_, err := triggerAUnitrun(config, con, client)
assert.Equal(t, nil, err)

View File

@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
@ -71,7 +70,7 @@ func runApiKeyValueMapDownload(config *apiKeyValueMapDownloadOptions, telemetryD
}
return nil
}
responseBody, readErr := ioutil.ReadAll(downloadResp.Body)
responseBody, readErr := io.ReadAll(downloadResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code : %v", downloadResp.StatusCode)

View File

@ -4,7 +4,6 @@
package cmd
import (
"io/ioutil"
"os"
"testing"
@ -15,7 +14,7 @@ func TestRunApiKeyValueMapDownload(t *testing.T) {
t.Parallel()
t.Run("Successfull Download of API Key Value Map", func(t *testing.T) {
file, err := ioutil.TempFile("", "CustKVM.json")
file, err := os.CreateTemp("", "CustKVM.json")
if err != nil {
t.FailNow()
}

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"github.com/Jeffail/gabs/v2"
@ -76,7 +76,7 @@ func runApiKeyValueMapUpload(config *apiKeyValueMapUploadOptions, telemetryData
Info("Successfully created api key value map artefact in API Portal")
return nil
}
response, readErr := ioutil.ReadAll(apiProxyUploadStatusResp.Body)
response, readErr := io.ReadAll(apiProxyUploadStatusResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", apiProxyUploadStatusResp.StatusCode)

View File

@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
@ -75,7 +75,7 @@ func runApiProviderDownload(config *apiProviderDownloadOptions, telemetryData *t
}
if downloadResp.StatusCode == 200 {
jsonFilePath := config.DownloadPath
content, err := ioutil.ReadAll(downloadResp.Body)
content, err := io.ReadAll(downloadResp.Body)
if err != nil {
return err
}

View File

@ -3,8 +3,8 @@ package cmd
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/SAP/jenkins-library/pkg/apim"
"github.com/SAP/jenkins-library/pkg/cpi"
@ -30,7 +30,7 @@ func runApiProviderUpload(config *apiProviderUploadOptions, telemetryData *telem
if err != nil {
return err
}
return createApiProvider(config, apimData, ioutil.ReadFile)
return createApiProvider(config, apimData, os.ReadFile)
}
func createApiProvider(config *apiProviderUploadOptions, apim apim.Bundle, readFile func(string) ([]byte, error)) error {

View File

@ -4,7 +4,6 @@
package cmd
import (
"io/ioutil"
"os"
"testing"
@ -18,7 +17,7 @@ func TestRunApiProviderUpload(t *testing.T) {
t.Parallel()
t.Run("API Provider upload succesfull test", func(t *testing.T) {
file, tmpErr := ioutil.TempFile("", "test.json")
file, tmpErr := os.CreateTemp("", "test.json")
if tmpErr != nil {
t.FailNow()
}
@ -44,7 +43,7 @@ func TestRunApiProviderUpload(t *testing.T) {
})
t.Run("API Provider upload failed test", func(t *testing.T) {
file, tmpErr := ioutil.TempFile("", "test.json")
file, tmpErr := os.CreateTemp("", "test.json")
if tmpErr != nil {
t.FailNow()
}

View File

@ -5,7 +5,6 @@ package cmd
import (
"io"
"io/ioutil"
"os"
"os/exec"
"strings"
@ -39,7 +38,7 @@ steps:
default:
fileContent = ""
}
return ioutil.NopCloser(strings.NewReader(fileContent)), nil
return io.NopCloser(strings.NewReader(fileContent)), nil
}
func checkStepActiveFileExistsMock(filename string) (bool, error) {

View File

@ -9,7 +9,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
@ -321,7 +320,7 @@ func (c *checkmarxExecuteScanUtilsMock) WriteFile(filename string, data []byte,
if c.errorOnWriteFile {
return fmt.Errorf("error on WriteFile")
}
return ioutil.WriteFile(filename, data, perm)
return os.WriteFile(filename, data, perm)
}
func (c *checkmarxExecuteScanUtilsMock) MkdirAll(path string, perm os.FileMode) error {
@ -399,17 +398,17 @@ func TestZipFolder(t *testing.T) {
t.Parallel()
dir := t.TempDir()
err := ioutil.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abcd.yaml"), []byte("abcd.yaml"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abcd.yaml"), []byte("abcd.yaml"), 0o700)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(dir, "somepath"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
err = os.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
assert.NoError(t, err)
var zipFileMock bytes.Buffer
@ -430,15 +429,15 @@ func TestZipFolder(t *testing.T) {
t.Parallel()
dir := t.TempDir()
err := ioutil.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(dir, "somepath"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
err = os.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
assert.NoError(t, err)
var zipFileMock bytes.Buffer
@ -453,15 +452,15 @@ func TestZipFolder(t *testing.T) {
t.Parallel()
dir := t.TempDir()
err := ioutil.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(dir, "somepath"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
err = os.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
assert.NoError(t, err)
var zipFileMock bytes.Buffer
@ -476,15 +475,15 @@ func TestZipFolder(t *testing.T) {
t.Parallel()
dir := t.TempDir()
err := ioutil.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(dir, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(dir, "somepath"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
err = os.WriteFile(filepath.Join(dir, "somepath", "abcd.txt"), []byte("somepath/abcd.txt"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abcd_test.go"), []byte("abcd_test.go"), 0o700)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
err = os.WriteFile(filepath.Join(dir, "abc_test.go"), []byte("abc_test.go"), 0o700)
assert.NoError(t, err)
var zipFileMock bytes.Buffer
@ -588,7 +587,7 @@ func TestRunScan(t *testing.T) {
sys := &systemMockForExistingProject{response: []byte(`<?xml version="1.0" encoding="utf-8"?><CxXMLResults />`)}
options := checkmarxExecuteScanOptions{ProjectName: "TestExisting", VulnerabilityThresholdUnit: "absolute", FullScanCycle: "2", Incremental: true, FullScansScheduled: true, Preset: "10048", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -612,7 +611,7 @@ func TestRunScan_nonNumeralPreset(t *testing.T) {
sys := &systemMockForExistingProject{response: []byte(`<?xml version="1.0" encoding="utf-8"?><CxXMLResults />`)}
options := checkmarxExecuteScanOptions{ProjectName: "TestExisting", VulnerabilityThresholdUnit: "absolute", FullScanCycle: "2", Incremental: true, FullScansScheduled: true, Preset: "SAP_JS_Default", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -632,7 +631,7 @@ func TestRunOptimizedScan(t *testing.T) {
sys := &systemMockForExistingProject{response: []byte(`<?xml version="1.0" encoding="utf-8"?><CxXMLResults />`)}
options := checkmarxExecuteScanOptions{IsOptimizedAndScheduled: true, ProjectName: "TestExisting", VulnerabilityThresholdUnit: "absolute", FullScanCycle: "1", Incremental: true, FullScansScheduled: true, Preset: "10048", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -713,7 +712,7 @@ func TestRunScanWOtherCycle(t *testing.T) {
sys := &systemMock{response: []byte(`<?xml version="1.0" encoding="utf-8"?><CxXMLResults />`), createProject: true}
options := checkmarxExecuteScanOptions{ProjectName: "test", VulnerabilityThresholdUnit: "percentage", FullScanCycle: "3", Incremental: true, FullScansScheduled: true, Preset: "123", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -754,7 +753,7 @@ func TestRunScanForPullRequest(t *testing.T) {
sys := &systemMock{response: []byte(`<?xml version="1.0" encoding="utf-8"?><CxXMLResults />`)}
options := checkmarxExecuteScanOptions{PullRequestName: "PR-19", ProjectName: "Test", VulnerabilityThresholdUnit: "percentage", FullScanCycle: "3", Incremental: true, FullScansScheduled: true, Preset: "123", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true, AvoidDuplicateProjectScans: false}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -776,7 +775,7 @@ func TestRunScanForPullRequestProjectNew(t *testing.T) {
sys := &systemMock{response: []byte(`<?xml version="1.0" encoding="utf-8"?><CxXMLResults />`), createProject: true}
options := checkmarxExecuteScanOptions{PullRequestName: "PR-17", ProjectName: "Test", AvoidDuplicateProjectScans: true, VulnerabilityThresholdUnit: "percentage", FullScanCycle: "3", Incremental: true, FullScansScheduled: true, Preset: "10048", TeamName: "OpenSource/Cracks/15", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -799,7 +798,7 @@ func TestRunScanForPullRequestProjectNew_nonNumeralPreset(t *testing.T) {
sys := &systemMock{response: []byte(`<?xml version="1.0" encoding="utf-8"?><CxXMLResults />`), createProject: true}
options := checkmarxExecuteScanOptions{PullRequestName: "PR-17", ProjectName: "Test", AvoidDuplicateProjectScans: true, VulnerabilityThresholdUnit: "percentage", FullScanCycle: "3", Incremental: true, FullScansScheduled: true, Preset: "SAP_JS_Default", TeamName: "OpenSource/Cracks/15", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -838,7 +837,7 @@ func TestRunScanHighViolationPercentage(t *testing.T) {
</CxXMLResults>`)}
options := checkmarxExecuteScanOptions{ProjectName: "test", VulnerabilityThresholdUnit: "percentage", VulnerabilityThresholdResult: "FAILURE", VulnerabilityThresholdHigh: 100, FullScanCycle: "10", FullScansScheduled: true, Preset: "10048", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"
@ -877,7 +876,7 @@ func TestRunScanHighViolationAbsolute(t *testing.T) {
</CxXMLResults>`)}
options := checkmarxExecuteScanOptions{ProjectName: "test", VulnerabilityThresholdUnit: "absolute", VulnerabilityThresholdResult: "FAILURE", VulnerabilityThresholdLow: 1, FullScanCycle: "10", FullScansScheduled: true, Preset: "10048", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true}
workspace := t.TempDir()
err := ioutil.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
err := os.WriteFile(filepath.Join(workspace, "abcd.go"), []byte("abcd.go"), 0o700)
assert.NoError(t, err)
options.FilterPattern = "**/abcd.go"

View File

@ -4,7 +4,6 @@
package cmd
import (
"io/ioutil"
"os"
"testing"
@ -149,7 +148,7 @@ func TestCloudFoundryCreateService(t *testing.T) {
plan: "testPlan"`
manifestFileStringBody := []byte(manifestFileString)
err := ioutil.WriteFile("manifestTest.yml", manifestFileStringBody, 0644)
err := os.WriteFile("manifestTest.yml", manifestFileStringBody, 0644)
assert.NoError(t, err)
var manifestVariables = []string{"name1=Test1", "name2=Test2"}
@ -203,11 +202,11 @@ func TestCloudFoundryCreateService(t *testing.T) {
varsFileStringBody := []byte(varsFileString)
manifestFileStringBody := []byte(manifestFileString)
err := ioutil.WriteFile("varsTest.yml", varsFileStringBody, 0644)
err := os.WriteFile("varsTest.yml", varsFileStringBody, 0644)
assert.NoError(t, err)
err = ioutil.WriteFile("varsTest2.yml", varsFileStringBody, 0644)
err = os.WriteFile("varsTest2.yml", varsFileStringBody, 0644)
assert.NoError(t, err)
err = ioutil.WriteFile("manifestTest.yml", manifestFileStringBody, 0644)
err = os.WriteFile("manifestTest.yml", manifestFileStringBody, 0644)
assert.NoError(t, err)
var manifestVariablesFiles = []string{"varsTest.yml", "varsTest2.yml"}

View File

@ -9,7 +9,6 @@ import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -66,7 +65,7 @@ func (c *httpMockClient) SendRequest(method, url string, body io.Reader, header
c.header[url] = header
response := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
Body: io.NopCloser(bytes.NewReader([]byte(""))),
}
if c.errorMessageForURL[url] != "" {
@ -75,7 +74,7 @@ func (c *httpMockClient) SendRequest(method, url string, body io.Reader, header
}
if c.responseBodyForURL[url] != "" {
response.Body = ioutil.NopCloser(bytes.NewReader([]byte(c.responseBodyForURL[url])))
response.Body = io.NopCloser(bytes.NewReader([]byte(c.responseBodyForURL[url])))
return &response, nil
}

View File

@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"math"
"os"
"os/exec"
@ -342,7 +341,7 @@ func verifyFFProjectCompliance(ctx context.Context, config fortifyExecuteScanOpt
// Generate report
if config.Reporting {
resultURL := []byte(fmt.Sprintf("%v/html/ssc/version/%v/fix/null/", config.ServerURL, projectVersion.ID))
if err := ioutil.WriteFile(fmt.Sprintf("%vtarget/%v-%v.%v", config.ModulePath, *project.Name, *projectVersion.Name, "txt"), resultURL, 0o700); err != nil {
if err := os.WriteFile(fmt.Sprintf("%vtarget/%v-%v.%v", config.ModulePath, *project.Name, *projectVersion.Name, "txt"), resultURL, 0o700); err != nil {
log.Entry().WithError(err).Error("failed to write file")
}
@ -350,7 +349,7 @@ func verifyFFProjectCompliance(ctx context.Context, config fortifyExecuteScanOpt
if err != nil {
return reports, err
}
if err := ioutil.WriteFile(fmt.Sprintf("%vtarget/%v-%v.%v", config.ModulePath, *project.Name, *projectVersion.Name, config.ReportType), data, 0o700); err != nil {
if err := os.WriteFile(fmt.Sprintf("%vtarget/%v-%v.%v", config.ModulePath, *project.Name, *projectVersion.Name, config.ReportType), data, 0o700); err != nil {
log.Entry().WithError(err).Warning("failed to write file")
}
}
@ -874,7 +873,7 @@ func readAllClasspathFiles(file string) string {
}
func readClasspathFile(file string) string {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
log.Entry().WithError(err).Warnf("failed to read classpath from file '%v'", file)
}

View File

@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -438,7 +437,7 @@ func (er *execRunnerMock) RunExecutable(e string, p ...string) error {
}
} else if e == "mvn" {
path := strings.ReplaceAll(p[2], "-Dmdep.outputFile=", "")
err := ioutil.WriteFile(path, []byte(classpathMaven), 0o644)
err := os.WriteFile(path, []byte(classpathMaven), 0o644)
if err != nil {
return err
}

View File

@ -1,7 +1,7 @@
package cmd
import (
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
@ -65,7 +65,7 @@ func cloneRepository(config *gctsCloneRepositoryOptions, telemetryData *telemetr
return errors.Errorf("did not retrieve a HTTP response: %v", httpErr)
}
bodyText, readErr := ioutil.ReadAll(resp.Body)
bodyText, readErr := io.ReadAll(resp.Body)
if readErr != nil {
return errors.Wrap(readErr, "HTTP response body could not be read")

View File

@ -3,7 +3,7 @@ package cmd
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
@ -103,7 +103,7 @@ func createRepository(config *gctsCreateRepositoryOptions, telemetryData *teleme
return errors.Errorf("creating repository on the ABAP system %v failed: %v", config.Host, httpErr)
}
bodyText, readErr := ioutil.ReadAll(resp.Body)
bodyText, readErr := io.ReadAll(resp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "creating repository on the ABAP system %v failed", config.Host)

View File

@ -7,7 +7,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"net/http"
"testing"
@ -169,7 +168,7 @@ func (c *httpMockGcts) SendRequest(method string, url string, r io.Reader, heade
c.URL = url
if r != nil {
_, err := ioutil.ReadAll(r)
_, err := io.ReadAll(r)
if err != nil {
return nil, err
@ -179,7 +178,7 @@ func (c *httpMockGcts) SendRequest(method string, url string, r io.Reader, heade
res := http.Response{
StatusCode: c.StatusCode,
Header: c.Header,
Body: ioutil.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
Body: io.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
}
if c.StatusCode >= 400 {

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"net/url"
@ -558,7 +558,7 @@ func pullByCommit(config *gctsDeployOptions, telemetryData *telemetry.CustomData
return errors.New("did not retrieve a HTTP response")
}
bodyText, readErr := ioutil.ReadAll(resp.Body)
bodyText, readErr := io.ReadAll(resp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read")

View File

@ -5,10 +5,10 @@ import (
"encoding/xml"
"fmt"
"html"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"os"
"regexp"
"strconv"
"strings"
@ -733,7 +733,7 @@ func parseUnitResult(config *gctsExecuteABAPQualityChecksOptions, client piperht
body, _ := xml.Marshal(parsedResult)
writeErr := ioutil.WriteFile(config.AUnitResultsFileName, body, 0644)
writeErr := os.WriteFile(config.AUnitResultsFileName, body, 0644)
if writeErr != nil {
log.Entry().Error("file AUnitResults.xml could not be created")
@ -1051,7 +1051,7 @@ func parseATCCheckResult(config *gctsExecuteABAPQualityChecksOptions, client pip
atcBody, _ := xml.Marshal(atcResults)
writeErr := ioutil.WriteFile(config.AtcResultsFileName, atcBody, 0644)
writeErr := os.WriteFile(config.AtcResultsFileName, atcBody, 0644)
if writeErr != nil {
log.Entry().Error("ATCResults.xml could not be created")
@ -1105,7 +1105,7 @@ func findLine(config *gctsExecuteABAPQualityChecksOptions, client piperhttp.Send
if readableSource {
// the error line that we get from UnitTest Run or ATC Check is not aligned for the readable source, we need to calculated it
rawfile, err := ioutil.ReadFile(filePath)
rawfile, err := os.ReadFile(filePath)
if err != nil {

View File

@ -7,7 +7,6 @@ import (
"bytes"
"encoding/xml"
"io"
"io/ioutil"
"net/http"
"testing"
@ -1835,7 +1834,7 @@ func (c *httpMockGctsT) SendRequest(method string, url string, r io.Reader, head
}
if r != nil {
_, err := ioutil.ReadAll(r)
_, err := io.ReadAll(r)
if err != nil {
return nil, err
@ -1845,7 +1844,7 @@ func (c *httpMockGctsT) SendRequest(method string, url string, r io.Reader, head
res := http.Response{
StatusCode: c.StatusCode,
Header: c.Header,
Body: ioutil.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
Body: io.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
}
if c.StatusCode >= 400 {

View File

@ -1,7 +1,7 @@
package cmd
import (
"io/ioutil"
"io"
"net/http/cookiejar"
"net/url"
@ -156,7 +156,7 @@ func getLastSuccessfullCommit(config *gctsRollbackOptions, telemetryData *teleme
return "", errors.New("did not retrieve a HTTP response")
}
bodyText, readErr := ioutil.ReadAll(resp.Body)
bodyText, readErr := io.ReadAll(resp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read")

View File

@ -6,7 +6,6 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"path/filepath"
"strings"
"testing"
@ -27,7 +26,7 @@ func configOpenFileMock(name string, tokens map[string]string) (io.ReadCloser, e
default:
r = ""
}
return ioutil.NopCloser(strings.NewReader(r)), nil
return io.NopCloser(strings.NewReader(r)), nil
}
func TestConfigCommand(t *testing.T) {

View File

@ -5,7 +5,6 @@ package cmd
import (
"io"
"io/ioutil"
"strings"
"testing"
@ -49,7 +48,7 @@ func defaultsOpenFileMock(name string, tokens map[string]string) (io.ReadCloser,
default:
r = ""
}
return ioutil.NopCloser(strings.NewReader(r)), nil
return io.NopCloser(strings.NewReader(r)), nil
}
func TestDefaultsCommand(t *testing.T) {

View File

@ -6,7 +6,6 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -711,7 +710,7 @@ func TestPrepareLdflags(t *testing.T) {
err := os.Mkdir(filepath.Join(dir, "commonPipelineEnvironment"), 0777)
assert.NoError(t, err, "Error when creating folder structure")
err = ioutil.WriteFile(filepath.Join(dir, "commonPipelineEnvironment", "artifactVersion"), []byte("1.2.3"), 0666)
err = os.WriteFile(filepath.Join(dir, "commonPipelineEnvironment", "artifactVersion"), []byte("1.2.3"), 0666)
assert.NoError(t, err, "Error when creating cpe file")
t.Run("success - default", func(t *testing.T) {

View File

@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"time"
@ -99,14 +99,14 @@ func runIntegrationArtifactDeploy(config *integrationArtifactDeployOptions, tele
log.Entry().
WithField("IntegrationFlowID", config.IntegrationFlowID).
Info("successfully deployed into CPI runtime")
taskId, readErr := ioutil.ReadAll(deployResp.Body)
taskId, readErr := io.ReadAll(deployResp.Body)
if readErr != nil {
return errors.Wrap(readErr, "Task Id not found. HTTP response body could not be read.")
}
deploymentError := pollIFlowDeploymentStatus(string(taskId), retryCount, config, httpClient, serviceKey.OAuth.Host)
return deploymentError
}
responseBody, readErr := ioutil.ReadAll(deployResp.Body)
responseBody, readErr := io.ReadAll(deployResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", deployResp.StatusCode)
@ -154,7 +154,7 @@ func pollIFlowDeploymentStatus(taskId string, retryCount int, config *integratio
// GetHTTPErrorMessage - Return HTTP failure message
func getHTTPErrorMessage(httpErr error, response *http.Response, httpMethod, statusURL string) (string, error) {
responseBody, readErr := ioutil.ReadAll(response.Body)
responseBody, readErr := io.ReadAll(response.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", response.StatusCode)
}
@ -184,7 +184,7 @@ func getIntegrationArtifactDeployStatus(config *integrationArtifactDeployOptions
WithField("IntegrationFlowID", config.IntegrationFlowID).
Info("Successfully started integration flow artefact in CPI runtime")
bodyText, readErr := ioutil.ReadAll(deployStatusResp.Body)
bodyText, readErr := io.ReadAll(deployStatusResp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", deployStatusResp.StatusCode)
}
@ -221,7 +221,7 @@ func getIntegrationArtifactDeployError(config *integrationArtifactDeployOptions,
log.Entry().
WithField("IntegrationFlowID", config.IntegrationFlowID).
Info("Successfully retrieved Integration Flow artefact deploy error details")
responseBody, readErr := ioutil.ReadAll(errorStatusResp.Body)
responseBody, readErr := io.ReadAll(errorStatusResp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", errorStatusResp.StatusCode)
}

View File

@ -7,7 +7,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"testing"
@ -191,7 +190,7 @@ func (c *httpMockCpis) SendRequest(method string, url string, r io.Reader, heade
c.URL = url
if r != nil {
_, err := ioutil.ReadAll(r)
_, err := io.ReadAll(r)
if err != nil {
return nil, err
@ -204,7 +203,7 @@ func (c *httpMockCpis) SendRequest(method string, url string, r io.Reader, heade
res := http.Response{
StatusCode: c.StatusCode,
Header: c.Header,
Body: ioutil.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
Body: io.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
}
return &res, nil
}

View File

@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"mime"
"net/http"
"os"
@ -84,7 +83,7 @@ func runIntegrationArtifactDownload(config *integrationArtifactDownloadOptions,
}
return nil
}
responseBody, readErr := ioutil.ReadAll(downloadResp.Body)
responseBody, readErr := io.ReadAll(downloadResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code : %v", downloadResp.StatusCode)

View File

@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
@ -69,7 +69,7 @@ func runIntegrationArtifactGetMplStatus(
}
if mplStatusResp.StatusCode == 200 {
bodyText, readErr := ioutil.ReadAll(mplStatusResp.Body)
bodyText, readErr := io.ReadAll(mplStatusResp.Body)
if readErr != nil {
return errors.Wrap(readErr, "HTTP response body could not be read")
}
@ -96,7 +96,7 @@ func runIntegrationArtifactGetMplStatus(
}
return nil
}
responseBody, readErr := ioutil.ReadAll(mplStatusResp.Body)
responseBody, readErr := io.ReadAll(mplStatusResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", mplStatusResp.StatusCode)
@ -126,7 +126,7 @@ func getIntegrationArtifactMPLError(commonPipelineEnvironment *integrationArtifa
log.Entry().
WithField("MPLID", mplID).
Info("Successfully retrieved Integration Flow artefact message processing error")
responseBody, readErr := ioutil.ReadAll(errorStatusResp.Body)
responseBody, readErr := io.ReadAll(errorStatusResp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", errorStatusResp.StatusCode)
}

View File

@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
@ -63,7 +63,7 @@ func runIntegrationArtifactGetServiceEndpoint(config *integrationArtifactGetServ
}
if serviceEndpointResp.StatusCode == 200 {
bodyText, readErr := ioutil.ReadAll(serviceEndpointResp.Body)
bodyText, readErr := io.ReadAll(serviceEndpointResp.Body)
if readErr != nil {
return errors.Wrap(readErr, "HTTP response body could not be read")
}
@ -84,7 +84,7 @@ func runIntegrationArtifactGetServiceEndpoint(config *integrationArtifactGetServ
return errors.Errorf("Unable to get integration flow service endpoint '%v', Response body: %v, Response Status code: %v",
config.IntegrationFlowID, string(bodyText), serviceEndpointResp.StatusCode)
}
responseBody, readErr := ioutil.ReadAll(serviceEndpointResp.Body)
responseBody, readErr := io.ReadAll(serviceEndpointResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", serviceEndpointResp.StatusCode)

View File

@ -5,7 +5,7 @@ import (
b64 "encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"path/filepath"
"strings"
@ -221,7 +221,7 @@ func HttpResponseHandler(resp *http.Response, httpErr error, integrationArtifact
return nil
}
if httpErr != nil {
responseBody, readErr := ioutil.ReadAll(resp.Body)
responseBody, readErr := io.ReadAll(resp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", resp.StatusCode)
}

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"math/rand"
"net/http"
"time"
@ -65,7 +65,7 @@ func CreateIntegrationArtifactTransportRequest(config *integrationArtifactTransp
WithField("IntegrationPackageID", config.IntegrationPackageID).
Info("successfully created the integration package transport request")
bodyText, readErr := ioutil.ReadAll(createTransportRequestResp.Body)
bodyText, readErr := io.ReadAll(createTransportRequestResp.Body)
if readErr != nil {
return errors.Wrap(readErr, "HTTP response body could not be read")
}
@ -81,7 +81,7 @@ func CreateIntegrationArtifactTransportRequest(config *integrationArtifactTransp
}
return errors.New("Invalid process id")
}
responseBody, readErr := ioutil.ReadAll(createTransportRequestResp.Body)
responseBody, readErr := io.ReadAll(createTransportRequestResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", createTransportRequestResp.StatusCode)
@ -175,7 +175,7 @@ func getIntegrationTransportProcessingStatus(config *integrationArtifactTranspor
WithField("IntegrationPackageID", config.IntegrationPackageID).
Info("successfully processed the integration package transport response status")
bodyText, readErr := ioutil.ReadAll(transportProcStatusResp.Body)
bodyText, readErr := io.ReadAll(transportProcStatusResp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", transportProcStatusResp.StatusCode)
}
@ -212,7 +212,7 @@ func getIntegrationTransportError(config *integrationArtifactTransportOptions, h
log.Entry().
WithField("IntegrationPackageId", config.IntegrationPackageID).
Info("Successfully retrieved deployment failures error details")
responseBody, readErr := ioutil.ReadAll(errorStatusResp.Body)
responseBody, readErr := io.ReadAll(errorStatusResp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", errorStatusResp.StatusCode)
}

View File

@ -4,8 +4,9 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/cpi"
@ -116,7 +117,7 @@ func callIFlowURL(
}
var fileErr error
fileBody, fileErr = ioutil.ReadFile(config.MessageBodyPath)
fileBody, fileErr = os.ReadFile(config.MessageBodyPath)
if fileErr != nil {
log.SetErrorCategory(log.ErrorUndefined)
return fmt.Errorf("failed to read file %s: %w", config.MessageBodyPath, fileErr)
@ -155,7 +156,7 @@ func callIFlowURL(
log.Entry().
WithField(config.IntegrationFlowID, serviceEndpointUrl).
Infof("successfully triggered %s with status code %d", serviceEndpointUrl, iFlowResp.StatusCode)
bodyText, readErr := ioutil.ReadAll(iFlowResp.Body)
bodyText, readErr := io.ReadAll(iFlowResp.Body)
if readErr != nil {
log.Entry().Warnf("HTTP response body could not be read. Error: %s", readErr.Error())
} else if len(bodyText) > 0 {

View File

@ -4,7 +4,7 @@
package cmd
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -104,7 +104,7 @@ func TestRunIntegrationArtifactTriggerIntegrationTest(t *testing.T) {
utils := newIntegrationArtifactTriggerIntegrationTestTestsUtils()
utils.AddFile(config.MessageBodyPath, []byte("dummycontent1")) //have to add a file here to see in utils
if err := ioutil.WriteFile(config.MessageBodyPath, []byte("dummycontent2"), 0755); err != nil {
if err := os.WriteFile(config.MessageBodyPath, []byte("dummycontent2"), 0755); err != nil {
t.Fail()
}
httpClient := httpMockCpis{CPIFunction: "TriggerIntegrationTest", ResponseBody: ``, TestType: "Positive"}
@ -138,7 +138,7 @@ func TestRunIntegrationArtifactTriggerIntegrationTest(t *testing.T) {
utils := newIntegrationArtifactTriggerIntegrationTestTestsUtils()
//utils.AddFile(config.MessageBodyPath, []byte("dummycontent1")) //have to add a file here to see in utils
//ioutil.WriteFile(config.MessageBodyPath, []byte("dummycontent2"), 0755)
//os.WriteFile(config.MessageBodyPath, []byte("dummycontent2"), 0755)
httpClient := httpMockCpis{CPIFunction: "TriggerIntegrationTest", ResponseBody: ``, TestType: "Positive"}
cpe := integrationArtifactTriggerIntegrationTestCommonPipelineEnvironment{}
@ -172,7 +172,7 @@ func TestRunIntegrationArtifactTriggerIntegrationTest(t *testing.T) {
utils := newIntegrationArtifactTriggerIntegrationTestTestsUtils()
utils.AddFile(config.MessageBodyPath, []byte(nil)) //have to add a file here to see in utils
if err := ioutil.WriteFile(config.MessageBodyPath, []byte(nil), 0755); err != nil {
if err := os.WriteFile(config.MessageBodyPath, []byte(nil), 0755); err != nil {
t.Fail()
}
httpClient := httpMockCpis{CPIFunction: "TriggerIntegrationTest", ResponseBody: ``, TestType: "Positive"}

View File

@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"github.com/SAP/jenkins-library/pkg/cpi"
@ -64,7 +64,7 @@ func runIntegrationArtifactUnDeploy(config *integrationArtifactUnDeployOptions,
Info("successfully undeployed from integration runtime")
return nil
}
responseBody, readErr := ioutil.ReadAll(unDeployResp.Body)
responseBody, readErr := io.ReadAll(unDeployResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", unDeployResp.StatusCode)

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"github.com/Jeffail/gabs/v2"
@ -76,7 +76,7 @@ func runIntegrationArtifactUpdateConfiguration(config *integrationArtifactUpdate
Info("successfully updated the integration flow configuration parameter")
return nil
}
response, readErr := ioutil.ReadAll(configUpdateResp.Body)
response, readErr := io.ReadAll(configUpdateResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", configUpdateResp.StatusCode)

View File

@ -5,7 +5,7 @@ import (
b64 "encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"github.com/Jeffail/gabs/v2"
@ -71,7 +71,7 @@ func runIntegrationArtifactUpload(config *integrationArtifactUploadOptions, tele
}
if httpErr != nil {
responseBody, readErr := ioutil.ReadAll(iFlowStatusResp.Body)
responseBody, readErr := io.ReadAll(iFlowStatusResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", iFlowStatusResp.StatusCode)
}
@ -109,7 +109,7 @@ func UploadIntegrationArtifact(config *integrationArtifactUploadOptions, httpCli
return nil
}
if httpErr != nil {
responseBody, readErr := ioutil.ReadAll(uploadIflowStatusResp.Body)
responseBody, readErr := io.ReadAll(uploadIflowStatusResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", uploadIflowStatusResp.StatusCode)
}
@ -146,7 +146,7 @@ func UpdateIntegrationArtifact(config *integrationArtifactUploadOptions, httpCli
return nil
}
if httpErr != nil {
responseBody, readErr := ioutil.ReadAll(updateIflowStatusResp.Body)
responseBody, readErr := io.ReadAll(updateIflowStatusResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", updateIflowStatusResp.StatusCode)
}

View File

@ -7,7 +7,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"path/filepath"
"strings"
@ -38,7 +37,7 @@ func (c *kanikoMockClient) SendRequest(method, url string, body io.Reader, heade
if len(c.errorMessage) > 0 {
return nil, fmt.Errorf(c.errorMessage)
}
return &http.Response{StatusCode: c.httpStatusCode, Body: ioutil.NopCloser(bytes.NewReader([]byte(c.responseBody)))}, nil
return &http.Response{StatusCode: c.httpStatusCode, Body: io.NopCloser(bytes.NewReader([]byte(c.responseBody)))}, nil
}
func (c *kanikoMockClient) DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error {
if len(c.errorMessage) > 0 {

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
@ -311,7 +310,7 @@ func runKubectlDeploy(config kubernetesDeployOptions, utils kubernetes.DeployUti
tmpFolder := getTempDirForKubeCtlJSON()
defer os.RemoveAll(tmpFolder) // clean up
jsonData, _ := json.Marshal(dockerRegistrySecretData)
if err := ioutil.WriteFile(filepath.Join(tmpFolder, "secret.json"), jsonData, 0777); err != nil {
if err := os.WriteFile(filepath.Join(tmpFolder, "secret.json"), jsonData, 0777); err != nil {
log.Entry().WithError(err).Warning("failed to write secret")
}
@ -465,7 +464,7 @@ func createKey(parts ...string) string {
}
func getTempDirForKubeCtlJSON() string {
tmpFolder, err := ioutil.TempDir(".", "temp-")
tmpFolder, err := os.MkdirTemp(".", "temp-")
if err != nil {
log.Entry().WithError(err).WithField("path", tmpFolder).Debug("creating temp directory failed")
}

View File

@ -1,7 +1,6 @@
package cmd
import (
"io/ioutil"
"os"
"path"
"path/filepath"
@ -258,7 +257,7 @@ func loadRemoteRepoCertificates(certificateList []string, client piperhttp.Downl
}
func getTempDirForCertFile() string {
tmpFolder, err := ioutil.TempDir(".", "temp-")
tmpFolder, err := os.MkdirTemp(".", "temp-")
if err != nil {
log.Entry().WithError(err).WithField("path", tmpFolder).Debug("Creating temp directory failed")
}

View File

@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
@ -55,7 +55,7 @@ func (u *lintUtilsBundle) getGeneralPurposeConfig(configURL string) {
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
content, err := io.ReadAll(response.Body)
if err != nil {
log.Entry().Warnf("error while reading the general purpose configuration: %v", err)
return

View File

@ -7,7 +7,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -217,7 +216,7 @@ func TestGetProjectConfigFile(t *testing.T) {
}
for _, file := range test.filesAvailable {
if err := ioutil.WriteFile(filepath.Join(dir, file), []byte("general:"), 0700); err != nil {
if err := os.WriteFile(filepath.Join(dir, file), []byte("general:"), 0700); err != nil {
t.Fail()
}
}

View File

@ -7,7 +7,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -40,7 +39,7 @@ func TestRunProtecodeScan(t *testing.T) {
if requestURI == "/api/product/4486/" || requestURI == "/api/product/4711/" {
violations := filepath.Join("testdata/TestProtecode", "protecode_result_violations.json")
byteContent, err := ioutil.ReadFile(violations)
byteContent, err := os.ReadFile(violations)
require.NoErrorf(t, err, "failed reading %v", violations)
response := protecode.ResultData{Result: protecode.Result{ProductID: 4711, ReportURL: requestURI}}
err = json.Unmarshal(byteContent, &response)
@ -49,7 +48,7 @@ func TestRunProtecodeScan(t *testing.T) {
} else if requestURI == "/api/fetch/" {
violations := filepath.Join("testdata/TestProtecode", "protecode_result_violations.json")
byteContent, err := ioutil.ReadFile(violations)
byteContent, err := os.ReadFile(violations)
require.NoErrorf(t, err, "failed reading %v", violations)
response := protecode.ResultData{Result: protecode.Result{ProductID: 4486, ReportURL: requestURI}}
err = json.Unmarshal(byteContent, &response)
@ -202,7 +201,7 @@ func TestCreateProtecodeClient(t *testing.T) {
func TestUploadScanOrDeclareFetch(t *testing.T) {
// init
testFile, err := ioutil.TempFile("", "testFileUpload")
testFile, err := os.CreateTemp("", "testFileUpload")
require.NoError(t, err)
defer os.RemoveAll(testFile.Name()) // clean up
fileName := filepath.Base(testFile.Name())
@ -287,7 +286,7 @@ func TestExecuteProtecodeScan(t *testing.T) {
var b bytes.Buffer
if requestURI == "/api/product/4711/" {
byteContent, err := ioutil.ReadFile(violationsAbsPath)
byteContent, err := os.ReadFile(violationsAbsPath)
require.NoErrorf(t, err, "failed reading %v", violationsAbsPath)
response := protecode.ResultData{}
err = json.Unmarshal(byteContent, &response)

View File

@ -2,7 +2,6 @@ package cmd
import (
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
@ -306,7 +305,7 @@ func runSonar(config sonarExecuteScanOptions, client piperhttp.Downloader, runne
log.Entry().Debugf("Influx values: %v", influx.sonarqube_data.fields)
err = SonarUtils.WriteReport(reportData, sonar.workingDir, ioutil.WriteFile)
err = SonarUtils.WriteReport(reportData, sonar.workingDir, os.WriteFile)
if err != nil {
return err
@ -469,7 +468,7 @@ func getWorkingDir() string {
}
func getTempDir() string {
tmpFolder, err := ioutil.TempDir(".", "temp-")
tmpFolder, err := os.MkdirTemp(".", "temp-")
if err != nil {
log.Entry().WithError(err).WithField("path", tmpFolder).Debug("Creating temp directory failed")
}

View File

@ -5,7 +5,6 @@ package cmd
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
@ -96,7 +95,7 @@ func mockGlob(matchesForPatterns map[string][]string) func(pattern string) ([]st
func createTaskReportFile(t *testing.T, workingDir string) {
require.NoError(t, os.MkdirAll(filepath.Join(workingDir, ".scannerwork"), 0o755))
require.NoError(t, ioutil.WriteFile(filepath.Join(workingDir, ".scannerwork", "report-task.txt"), []byte(taskReportContent), 0o755))
require.NoError(t, os.WriteFile(filepath.Join(workingDir, ".scannerwork", "report-task.txt"), []byte(taskReportContent), 0o755))
require.FileExists(t, filepath.Join(workingDir, ".scannerwork", "report-task.txt"))
}

View File

@ -3,12 +3,13 @@ package cmd
import (
"bytes"
"encoding/json"
"io"
"os"
"path/filepath"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperenv"
"github.com/spf13/cobra"
"io/ioutil"
"os"
"path/filepath"
)
// WritePipelineEnv Serializes the commonPipelineEnvironment JSON to disk
@ -36,7 +37,7 @@ func runWritePipelineEnv() error {
inBytes := []byte(pipelineEnv)
if !ok {
var err error
inBytes, err = ioutil.ReadAll(os.Stdin)
inBytes, err = io.ReadAll(os.Stdin)
if err != nil {
return err
}

View File

@ -4,18 +4,18 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/pkg/errors"
"io"
"io/ioutil"
"os"
"regexp"
"strings"
"sync"
"text/template"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/pkg/errors"
)
// DeployMode ...
@ -304,7 +304,7 @@ func handleLog(logDir string) error {
if _, e := os.Stat(logDir); !os.IsNotExist(e) {
log.Entry().Warningf(fmt.Sprintf("Here are the logs (%s):", logDir))
logFiles, e := ioutil.ReadDir(logDir)
logFiles, e := os.ReadDir(logDir)
if e != nil {
return e

View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"sync"
"testing"
@ -135,7 +134,7 @@ func TestDeploy(t *testing.T) {
// this file is not denoted in the file exists mock
myXsDeployOptions.MtaPath = "doesNotExist"
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, ioutil.Discard)
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, io.Discard)
assert.EqualError(t, e, "Deployable 'doesNotExist' does not exist")
})
@ -152,7 +151,7 @@ func TestDeploy(t *testing.T) {
myXsDeployOptions.Action = "NONE"
}()
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, ioutil.Discard)
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, io.Discard)
assert.EqualError(t, e, "Cannot perform action 'RETRY' in mode 'DEPLOY'. Only action 'NONE' is allowed.")
})
@ -167,7 +166,7 @@ func TestDeploy(t *testing.T) {
s.ShouldFailOnCommand = map[string]error{"#!/bin/bash\nxs login -a https://example.org:12345 -u me -p 'secretPassword' -o myOrg -s mySpace --skip-ssl-validation\n": errors.New("Error from underlying process")}
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, ioutil.Discard)
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, io.Discard)
assert.EqualError(t, e, "Error from underlying process")
})
@ -191,7 +190,7 @@ func TestDeploy(t *testing.T) {
myXsDeployOptions.Mode = "BG_DEPLOY"
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, ioutil.Discard)
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, io.Discard)
if assert.NoError(t, e) {
if assert.Len(t, s.Calls, 2) { // There are two entries --> no logout in this case.
@ -220,7 +219,7 @@ func TestDeploy(t *testing.T) {
myXsDeployOptions.Mode = "BG_DEPLOY"
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, ioutil.Discard)
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, io.Discard)
assert.EqualError(t, e, "No operationID found")
})
@ -245,7 +244,7 @@ func TestDeploy(t *testing.T) {
myXsDeployOptions.Action = "ABORT"
myXsDeployOptions.OperationID = "12345"
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, ioutil.Discard)
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, io.Discard)
if assert.NoError(t, e) {
if assert.Len(t, s.Calls, 2) { // There is no login --> we have two calls
@ -275,7 +274,7 @@ func TestDeploy(t *testing.T) {
myXsDeployOptions.Mode = "BG_DEPLOY"
myXsDeployOptions.Action = "ABORT"
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, ioutil.Discard)
e := runXsDeploy(myXsDeployOptions, &cpeOut, &s, &fileUtilsMock, fRemove, io.Discard)
assert.EqualError(t, e, "OperationID was not provided. This is required for action 'ABORT'.")
})
}

View File

@ -5,7 +5,6 @@ package main
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -61,7 +60,7 @@ func TestGenerator(t *testing.T) {
- name: test_cpe
`
ioutil.WriteFile(filepath.Join(dir, "test.yaml"), []byte(metadata), 0755)
os.WriteFile(filepath.Join(dir, "test.yaml"), []byte(metadata), 0755)
openMetaFile := func(name string) (io.ReadCloser, error) { return os.Open(name) }
fileWriter := func(filename string, data []byte, perm os.FileMode) error { return nil }

View File

@ -9,7 +9,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path"
@ -93,7 +92,7 @@ func givenThisContainer(t *testing.T, bundle IntegrationTestDockerExecRunnerBund
projectDir := path.Join(wd, path.Join(bundle.TestDir...))
// 1. Copy test files to a temp dir in order to avoid non-repeatable test executions because of changed state
// 2. Don't remove the temp dir to allow investigation of failed tests. Maybe add an option for cleaning it later?
tempDir, err := ioutil.TempDir("", "piper-integration-test")
tempDir, err := os.MkdirTemp("", "piper-integration-test")
if err != nil {
t.Fatal(err)
}

View File

@ -9,7 +9,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -44,7 +43,7 @@ cd /test
/piperbin/piper gaugeExecuteTests --installCommand="%v" --languageRunner=%v --runCommand="run" >test-log.txt 2>&1
`, installCommand, languageRunner)
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "getgauge/gocd-jdk-mvn-node",
@ -77,7 +76,7 @@ cd /test
assert.NoError(t, nodeContainer.Terminate(ctx))
})
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}

View File

@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"path/filepath"
"strings"
@ -99,11 +98,11 @@ func TestGCSIntegrationClient(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []string{"placeholder", "test/file1", "test/folder/file2"}, fileNames)
go gcsClient.DownloadFile(bucketID, "test/file1", "file1")
fileContent, err := ioutil.ReadAll(file1Reader)
fileContent, err := io.ReadAll(file1Reader)
assert.NoError(t, err)
assert.Equal(t, file1Content, string(fileContent))
go gcsClient.DownloadFile(bucketID, "test/folder/file2", "file2")
fileContent, err = ioutil.ReadAll(file2Reader)
fileContent, err = io.ReadAll(file2Reader)
assert.NoError(t, err)
assert.Equal(t, file2Content, string(fileContent))
@ -166,7 +165,7 @@ func openFileMock(name string) (io.ReadCloser, error) {
default:
return nil, errors.New("open file faled")
}
return ioutil.NopCloser(strings.NewReader(fileContent)), nil
return io.NopCloser(strings.NewReader(fileContent)), nil
}
func getCreateFileMock(file1Writer io.WriteCloser, file2Writer io.WriteCloser) func(name string) (io.WriteCloser, error) {

View File

@ -7,7 +7,6 @@
package main
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -37,10 +36,10 @@ func TestGitHubIntegrationPiperPublishRelease(t *testing.T) {
dir := t.TempDir()
testAsset := filepath.Join(dir, "test.txt")
err := ioutil.WriteFile(testAsset, []byte("Test"), 0644)
err := os.WriteFile(testAsset, []byte("Test"), 0644)
assert.NoError(t, err, "Error when writing temporary file")
test2Asset := filepath.Join(dir, "test2.txt")
err = ioutil.WriteFile(test2Asset, []byte("Test"), 0644)
err = os.WriteFile(test2Asset, []byte("Test"), 0644)
assert.NoError(t, err, "Error when writing temporary file")
t.Run("test single asset - success", func(t *testing.T) {

View File

@ -9,7 +9,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -40,7 +39,7 @@ func TestGradleIntegrationExecuteBuildJavaProjectBOMCreationUsingWrapper(t *test
cd /test
/piperbin/piper gradleExecuteBuild >test-log.txt 2>&1
`)
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "adoptopenjdk/openjdk11:jdk-11.0.11_9-alpine",
@ -60,7 +59,7 @@ cd /test
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}
@ -76,13 +75,13 @@ cd /test
cd /test
ls -l ./build/reports/ >files-list.txt 2>&1
`)
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
code, err = nodeContainer.Exec(ctx, []string{"sh", "/test/runPiper.sh"})
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err = ioutil.ReadFile(filepath.Join(tempDir, "/files-list.txt"))
content, err = os.ReadFile(filepath.Join(tempDir, "/files-list.txt"))
if err != nil {
t.Fatal("Could not read files-list.txt.", err)
}
@ -112,7 +111,7 @@ func TestGradleIntegrationExecuteBuildJavaProjectWithBomPlugin(t *testing.T) {
cd /test
/piperbin/piper gradleExecuteBuild >test-log.txt 2>&1
`)
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "gradle:6-jdk11-alpine",
@ -132,7 +131,7 @@ cd /test
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}
@ -148,13 +147,13 @@ cd /test
cd /test
ls -l ./build/reports/ >files-list.txt 2>&1
`)
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
code, err = nodeContainer.Exec(ctx, []string{"sh", "/test/runPiper.sh"})
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err = ioutil.ReadFile(filepath.Join(tempDir, "/files-list.txt"))
content, err = os.ReadFile(filepath.Join(tempDir, "/files-list.txt"))
if err != nil {
t.Fatal("Could not read files-list.txt.", err)
}

View File

@ -8,7 +8,6 @@ package main
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -40,7 +39,7 @@ func TestKarmaIntegration(t *testing.T) {
cd /test
/piperbin/piper karmaExecuteTests
`
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
networkName := "sidecar-" + uuid.New().String()

View File

@ -8,7 +8,6 @@ package main
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -39,7 +38,7 @@ func TestNPMIntegrationRunScriptsWithOptions(t *testing.T) {
cd /test
/piperbin/piper npmExecuteScripts --runScripts=start --scriptOptions=--tag,tag1 >test-log.txt 2>&1
`
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "node:12-slim",
@ -59,7 +58,7 @@ cd /test
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}
@ -90,7 +89,7 @@ func TestNPMIntegrationRegistrySetInFlags(t *testing.T) {
cd /test
/piperbin/piper npmExecuteScripts --install --runScripts=ci-build,ci-backend-unit-test --defaultNpmRegistry=https://foo.bar >test-log.txt 2>&1
`
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "node:12-slim",
@ -110,7 +109,7 @@ cd /test
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}
@ -140,7 +139,7 @@ func TestNPMIntegrationRegistrySetInNpmrc(t *testing.T) {
cd /test
/piperbin/piper npmExecuteScripts --install --runScripts=ci-build,ci-backend-unit-test >test-log.txt 2>&1
`
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "node:12-slim",
@ -160,7 +159,7 @@ cd /test
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}
@ -190,7 +189,7 @@ func TestNPMIntegrationRegistryWithTwoModules(t *testing.T) {
cd /test
/piperbin/piper npmExecuteScripts --install --runScripts=ci-build,ci-backend-unit-test --defaultNpmRegistry=https://foo.bar >test-log.txt 2>&1
`
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "node:12-slim",
@ -210,7 +209,7 @@ cd /test
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}

View File

@ -10,7 +10,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -57,7 +56,7 @@ func getPiperExecutable() string {
// copyDir copies a directory
func copyDir(source string, target string) error {
var err error
var fileInfo []os.FileInfo
var fileInfo []os.DirEntry
var sourceInfo os.FileInfo
if sourceInfo, err = os.Stat(source); err != nil {
@ -68,7 +67,7 @@ func copyDir(source string, target string) error {
return err
}
if fileInfo, err = ioutil.ReadDir(source); err != nil {
if fileInfo, err = os.ReadDir(source); err != nil {
return err
}
for _, info := range fileInfo {

View File

@ -9,7 +9,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -37,7 +36,7 @@ func TestPythonIntegrationBuildProject(t *testing.T) {
testScript := fmt.Sprintf(`#!/bin/sh
cd /test
/piperbin/piper pythonBuild >test-log.txt 2>&1`)
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
reqNode := testcontainers.ContainerRequest{
Image: "python:3.9",
@ -57,7 +56,7 @@ func TestPythonIntegrationBuildProject(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err := ioutil.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
content, err := os.ReadFile(filepath.Join(tempDir, "/test-log.txt"))
if err != nil {
t.Fatal("Could not read test-log.txt.", err)
}
@ -72,13 +71,13 @@ func TestPythonIntegrationBuildProject(t *testing.T) {
testScript = fmt.Sprintf(`#!/bin/sh
cd /test
ls -l . dist build >files-list.txt 2>&1`)
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
os.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
code, err = nodeContainer.Exec(ctx, []string{"sh", "/test/runPiper.sh"})
assert.NoError(t, err)
assert.Equal(t, 0, code)
content, err = ioutil.ReadFile(filepath.Join(tempDir, "/files-list.txt"))
content, err = os.ReadFile(filepath.Join(tempDir, "/files-list.txt"))
if err != nil {
t.Fatal("Could not read files-list.txt.", err)
}

View File

@ -2,7 +2,7 @@ package handlers
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
@ -49,7 +49,7 @@ func TestHelloHandler(t *testing.T) {
t.Error(err)
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}

View File

@ -2,7 +2,7 @@ package middlewares
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
@ -55,7 +55,7 @@ func TestRecoverMiddleware(t *testing.T) {
t.Errorf("\nactual: %v\nexpected: %v\n", actualStatusCode, tt.statusCode)
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}

View File

@ -3,7 +3,6 @@ package build
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"strings"
@ -37,7 +36,7 @@ func (c *ClMock) SendRequest(method string, url string, bdy io.Reader, hdr http.
body := []byte(fakeResponse(method, url))
return &http.Response{
StatusCode: c.StatusCode,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}, c.Error
} else if method == "HEAD" {
var body []byte
@ -47,7 +46,7 @@ func (c *ClMock) SendRequest(method string, url string, bdy io.Reader, hdr http.
return &http.Response{
StatusCode: c.StatusCode,
Header: header,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}, c.Error
} else {
return nil, c.Error

View File

@ -2,7 +2,7 @@ package build
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"net/url"
@ -60,7 +60,7 @@ func (conn *Connector) GetToken(appendum string) error {
return errors.Wrap(err, "Fetching X-CSRF-Token failed")
}
defer response.Body.Close()
errorbody, _ := ioutil.ReadAll(response.Body)
errorbody, _ := io.ReadAll(response.Body)
return errors.Wrapf(err, "Fetching X-CSRF-Token failed: %v", string(errorbody))
}
@ -79,12 +79,12 @@ func (conn Connector) Get(appendum string) ([]byte, error) {
return nil, errors.Wrap(err, "Get failed")
}
defer response.Body.Close()
errorbody, _ := ioutil.ReadAll(response.Body)
errorbody, _ := io.ReadAll(response.Body)
return errorbody, errors.Wrapf(err, "Get failed: %v", string(errorbody))
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
return body, err
}
@ -103,12 +103,12 @@ func (conn Connector) Post(appendum string, importBody string) ([]byte, error) {
return nil, errors.Wrap(err, "Post failed")
}
defer response.Body.Close()
errorbody, _ := ioutil.ReadAll(response.Body)
errorbody, _ := io.ReadAll(response.Body)
return errorbody, errors.Wrapf(err, "Post failed: %v", string(errorbody))
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
return body, err
}
@ -201,7 +201,7 @@ func (conn Connector) UploadSarFile(appendum string, sarFile []byte) error {
response, err := conn.Client.SendRequest("PUT", url, bytes.NewBuffer(sarFile), conn.Header, nil)
if err != nil {
defer response.Body.Close()
errorbody, _ := ioutil.ReadAll(response.Body)
errorbody, _ := io.ReadAll(response.Body)
return errors.Wrapf(err, "Upload of SAR file failed: %v", string(errorbody))
}
defer response.Body.Close()
@ -236,7 +236,7 @@ func (conn Connector) UploadSarFileInChunks(appendum string, fileName string, sa
response, err := conn.Client.SendRequest("POST", url, nextChunk, header, nil)
if err != nil {
if response != nil && response.Body != nil {
errorbody, _ := ioutil.ReadAll(response.Body)
errorbody, _ := io.ReadAll(response.Body)
response.Body.Close()
return errors.Wrapf(err, "Upload of SAR file failed: %v", string(errorbody))
} else {

View File

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
@ -48,7 +47,7 @@ func (mc *MockClient) Add(Method, Url, Body string) {
mc.AddResponse(Method, Url, http.Response{
StatusCode: http.StatusOK,
Header: http.Header{},
Body: ioutil.NopCloser(bytes.NewReader([]byte(Body))),
Body: io.NopCloser(bytes.NewReader([]byte(Body))),
})
}
@ -57,7 +56,7 @@ func (mc *MockClient) AddBody(Method, Url, Body string, StatusCode int, header h
mc.AddResponse(Method, Url, http.Response{
StatusCode: StatusCode,
Header: header,
Body: ioutil.NopCloser(bytes.NewReader([]byte(Body))),
Body: io.NopCloser(bytes.NewReader([]byte(Body))),
})
}
@ -66,7 +65,7 @@ func (mc *MockClient) AddData(data MockData) {
mc.AddResponse(data.Method, data.Url, http.Response{
StatusCode: data.StatusCode,
Header: data.Header,
Body: ioutil.NopCloser(bytes.NewReader([]byte(data.Body))),
Body: io.NopCloser(bytes.NewReader([]byte(data.Body))),
})
}

View File

@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
@ -155,7 +155,7 @@ func ReadConfigFile(path string) (file []byte, err error) {
if err != nil {
return nil, err
}
yamlFile, err := ioutil.ReadFile(filename)
yamlFile, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
@ -216,7 +216,7 @@ func GetErrorDetailsFromResponse(resp *http.Response) (errorString string, error
// Include the error message of the ABAP Environment system, if available
var abapErrorResponse AbapError
bodyText, readError := ioutil.ReadAll(resp.Body)
bodyText, readError := io.ReadAll(resp.Body)
if readError != nil {
return "", "", readError
}
@ -398,7 +398,7 @@ func (c *ClientMock) SendRequest(method, url string, bdy io.Reader, hdr http.Hea
return &http.Response{
StatusCode: c.StatusCode,
Header: header,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}, c.Error
}

View File

@ -6,7 +6,7 @@ package abaputils
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
@ -304,7 +304,7 @@ func TestHandleHTTPError(t *testing.T) {
resp := http.Response{
Status: "400 Bad Request",
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
receivedErr := errors.New(errorValue)
message := "Custom Error Message"
@ -323,7 +323,7 @@ func TestHandleHTTPError(t *testing.T) {
resp := http.Response{
Status: "400 Bad Request",
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
receivedErr := errors.New(errorValue)
message := "Custom Error Message"
@ -342,7 +342,7 @@ func TestHandleHTTPError(t *testing.T) {
resp := http.Response{
Status: "400 Bad Request",
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
receivedErr := errors.New(errorValue)
message := "Custom Error Message"

View File

@ -3,7 +3,7 @@ package abaputils
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -86,7 +86,7 @@ func readFile(FileName string) ([]byte, error) {
}
var fileContent []byte
fileContent, err = ioutil.ReadFile(absoluteFilename)
fileContent, err = os.ReadFile(absoluteFilename)
if err != nil {
return nil, errors.New(fmt.Sprintf("Could not read %v", FileName))
}

View File

@ -5,7 +5,6 @@ package abaputils
import (
"fmt"
"io/ioutil"
"os"
"testing"
@ -137,7 +136,7 @@ func TestReadAddonDescriptor(t *testing.T) {
- repo: 'testRepo'
- repo: 'testRepo2'`
err := ioutil.WriteFile("repositories.yml", []byte(manifestFileString), 0644)
err := os.WriteFile("repositories.yml", []byte(manifestFileString), 0644)
assert.NoError(t, err)
addonDescriptor, err := ReadAddonDescriptor("repositories.yml")

View File

@ -3,7 +3,7 @@ package abaputils
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"reflect"
"sort"
"strconv"
@ -183,7 +183,7 @@ func GetStatus(failureMessage string, connectionDetails ConnectionDetailsHTTP, c
// Parse response
var abapResp map[string]*json.RawMessage
bodyText, _ := ioutil.ReadAll(resp.Body)
bodyText, _ := io.ReadAll(resp.Body)
marshallError := json.Unmarshal(bodyText, &abapResp)
if marshallError != nil {
@ -214,7 +214,7 @@ func GetProtocol(failureMessage string, connectionDetails ConnectionDetailsHTTP,
// Parse response
var abapResp map[string]*json.RawMessage
bodyText, _ := ioutil.ReadAll(resp.Body)
bodyText, _ := io.ReadAll(resp.Body)
marshallError := json.Unmarshal(bodyText, &abapResp)
if marshallError != nil {

View File

@ -6,7 +6,6 @@ package abaputils
import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"os"
"testing"
@ -154,7 +153,7 @@ repositories:
- name: 'testRepo3'
branch: 'testBranch3'`
err := ioutil.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
err := os.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
config := RepositoriesConfig{
BranchName: "testBranch",
@ -185,7 +184,7 @@ repositories:
- repo: 'testRepo'
- repo: 'testRepo2'`
err := ioutil.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
err := os.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
config := RepositoriesConfig{
Repositories: "repositoriesTest.yml",
@ -213,7 +212,7 @@ repositories:
- repo: 'testRepo'
- repo: 'testRepo2'`
err := ioutil.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
err := os.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
config := RepositoriesConfig{
Repositories: "repositoriesTest.yml",

View File

@ -4,12 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/SAP/jenkins-library/pkg/xsuaa"
"github.com/pkg/errors"
"io"
"io/ioutil"
"net/http"
"strings"
"github.com/SAP/jenkins-library/pkg/xsuaa"
"github.com/pkg/errors"
)
// ANS holds the setup for the xsuaa service to retrieve a bearer token for authorization and
@ -129,7 +129,7 @@ func readResponseBody(response *http.Response) ([]byte, error) {
return nil, errors.Errorf("did not retrieve an HTTP response")
}
defer response.Body.Close()
bodyText, readErr := ioutil.ReadAll(response.Body)
bodyText, readErr := io.ReadAll(response.Body)
if readErr != nil {
return nil, errors.Wrap(readErr, "HTTP response body could not be read")
}

View File

@ -9,7 +9,7 @@ import (
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
@ -77,7 +77,7 @@ func TestANS_Send(t *testing.T) {
})
t.Run("pass request attribute event", func(t *testing.T) {
examinee.initRun(func(rw http.ResponseWriter, req *http.Request) {
eventBody, _ := ioutil.ReadAll(req.Body)
eventBody, _ := io.ReadAll(req.Body)
event := &Event{}
json.Unmarshal(eventBody, event)
assert.Equal(t, eventDefault, *event, "Mismatch in requested event body")

View File

@ -6,7 +6,6 @@ package apim
import (
"bytes"
"io"
"io/ioutil"
"net/http"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
@ -43,7 +42,7 @@ func (c *HttpMockAPIM) SendRequest(method string, url string, r io.Reader, heade
c.URL = url
if r != nil {
_, err := ioutil.ReadAll(r)
_, err := io.ReadAll(r)
if err != nil {
return nil, err
@ -53,7 +52,7 @@ func (c *HttpMockAPIM) SendRequest(method string, url string, r io.Reader, heade
res := http.Response{
StatusCode: c.StatusCode,
Header: c.Header,
Body: ioutil.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
Body: io.NopCloser(bytes.NewReader([]byte(c.ResponseBody))),
}
if c.StatusCode >= 400 {

View File

@ -4,17 +4,17 @@ import (
"bytes"
"encoding/json"
"fmt"
piperHttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net/http"
url2 "net/url"
"strconv"
"strings"
"time"
piperHttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type App struct {
@ -103,8 +103,8 @@ func NewSystemInstance(client *piperHttp.Client, serverURL, token string) (*Syst
func sendRequest(sys *SystemInstance, method, url string, body io.Reader, header http.Header) ([]byte, error) {
var requestBody io.Reader
if body != nil {
closer := ioutil.NopCloser(body)
bodyBytes, _ := ioutil.ReadAll(closer)
closer := io.NopCloser(body)
bodyBytes, _ := io.ReadAll(closer)
requestBody = bytes.NewBuffer(bodyBytes)
defer closer.Close()
}
@ -114,7 +114,7 @@ func sendRequest(sys *SystemInstance, method, url string, body io.Reader, header
return nil, err
}
data, _ := ioutil.ReadAll(response.Body)
data, _ := io.ReadAll(response.Body)
sys.logger.Debugf("Valid response body: %v", string(data))
defer response.Body.Close()
return data, nil

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"path"
@ -518,7 +517,7 @@ func (b *Client) sendRequest(method, apiEndpoint string, params map[string]strin
return responseBody, errors.Wrap(err, "request to BlackDuck API failed")
}
responseBody, err = ioutil.ReadAll(response.Body)
responseBody, err = io.ReadAll(response.Body)
if err != nil {
return responseBody, errors.Wrap(err, "reading BlackDuck response failed")
}

View File

@ -7,7 +7,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"testing"
"time"
@ -27,7 +26,7 @@ func (c *httpMockClient) SendRequest(method, url string, body io.Reader, header
c.header[url] = header
response := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
Body: io.NopCloser(bytes.NewReader([]byte(""))),
}
if c.errorMessageForURL[url] != "" {
@ -36,7 +35,7 @@ func (c *httpMockClient) SendRequest(method, url string, body io.Reader, header
}
if c.responseBodyForURL[url] != "" {
response.Body = ioutil.NopCloser(bytes.NewReader([]byte(c.responseBodyForURL[url])))
response.Body = io.NopCloser(bytes.NewReader([]byte(c.responseBodyForURL[url])))
return &response, nil
}

View File

@ -1,7 +1,7 @@
package certutils
import (
"io/ioutil"
"io"
"net/http"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
@ -28,7 +28,7 @@ func CertificateUpdate(certLinks []string, httpClient piperhttp.Sender, fileUtil
return errors.Wrap(err, "failed to load certificate from url")
}
content, err := ioutil.ReadAll(response.Body)
content, err := io.ReadAll(response.Body)
if err != nil {
return errors.Wrap(err, "error reading response")
}

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
@ -295,8 +294,8 @@ func sendRequestInternal(sys *SystemInstance, method, url string, body io.Reader
var requestBody io.Reader
var requestBodyCopy io.Reader
if body != nil {
closer := ioutil.NopCloser(body)
bodyBytes, _ := ioutil.ReadAll(closer)
closer := io.NopCloser(body)
bodyBytes, _ := io.ReadAll(closer)
requestBody = bytes.NewBuffer(bodyBytes)
requestBodyCopy = bytes.NewBuffer(bodyBytes)
defer closer.Close()
@ -308,7 +307,7 @@ func sendRequestInternal(sys *SystemInstance, method, url string, body io.Reader
return nil, err
}
data, _ := ioutil.ReadAll(response.Body)
data, _ := io.ReadAll(response.Body)
sys.logger.Debugf("Valid response body: %v", string(data))
defer response.Body.Close()
return data, nil
@ -316,11 +315,11 @@ func sendRequestInternal(sys *SystemInstance, method, url string, body io.Reader
func (sys *SystemInstance) recordRequestDetailsInErrorCase(requestBody io.Reader, response *http.Response) {
if requestBody != nil {
data, _ := ioutil.ReadAll(ioutil.NopCloser(requestBody))
data, _ := io.ReadAll(io.NopCloser(requestBody))
sys.logger.Errorf("Request body: %s", data)
}
if response != nil && response.Body != nil {
data, _ := ioutil.ReadAll(response.Body)
data, _ := io.ReadAll(response.Body)
sys.logger.Errorf("Response body: %s", data)
response.Body.Close()
}
@ -499,7 +498,7 @@ func (sys *SystemInstance) UploadProjectSourceCode(projectID int, zipFile string
return errors.Wrap(err, "failed to uploaded zipped sources")
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return errors.Wrap(err, "error reading the response data")

View File

@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
@ -49,19 +48,19 @@ func (sm *senderMock) SendRequest(method, url string, body io.Reader, header htt
if sm.httpStatusCode > 399 {
httpError = fmt.Errorf("http error %v", sm.httpStatusCode)
}
return &http.Response{StatusCode: sm.httpStatusCode, Body: ioutil.NopCloser(strings.NewReader(sm.responseBody))}, httpError
return &http.Response{StatusCode: sm.httpStatusCode, Body: io.NopCloser(strings.NewReader(sm.responseBody))}, httpError
}
func (sm *senderMock) UploadFile(url, file, fieldName string, header http.Header, cookies []*http.Cookie, uploadType string) (*http.Response, error) {
sm.httpMethod = http.MethodPost
sm.urlCalled = url
sm.header = header
return &http.Response{StatusCode: sm.httpStatusCode, Body: ioutil.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
return &http.Response{StatusCode: sm.httpStatusCode, Body: io.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
}
func (sm *senderMock) UploadRequest(method, url, file, fieldName string, header http.Header, cookies []*http.Cookie, uploadType string) (*http.Response, error) {
sm.httpMethod = http.MethodPost
sm.urlCalled = url
sm.header = header
return &http.Response{StatusCode: sm.httpStatusCode, Body: ioutil.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
return &http.Response{StatusCode: sm.httpStatusCode, Body: io.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
}
func (sm *senderMock) Upload(_ piperHttp.UploadRequestData) (*http.Response, error) {
return &http.Response{}, fmt.Errorf("not implemented")

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/xml"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
@ -119,7 +119,7 @@ type Line struct {
func ConvertCxxmlToSarif(sys System, xmlReportName string, scanID int) (format.SARIF, error) {
var sarif format.SARIF
log.Entry().Debug("Reading audit file.")
data, err := ioutil.ReadFile(xmlReportName)
data, err := os.ReadFile(xmlReportName)
if err != nil {
return sarif, err
}

View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
//"strconv"
"strings"
@ -386,8 +386,8 @@ func sendRequestInternal(sys *SystemInstance, method, url string, body io.Reader
var requestBody io.Reader
var reqBody string
if body != nil {
closer := ioutil.NopCloser(body)
bodyBytes, _ := ioutil.ReadAll(closer)
closer := io.NopCloser(body)
bodyBytes, _ := io.ReadAll(closer)
reqBody = string(bodyBytes)
requestBody = bytes.NewBuffer(bodyBytes)
defer closer.Close()
@ -450,7 +450,7 @@ func sendRequestInternal(sys *SystemInstance, method, url string, body io.Reader
}
}
data, _ := ioutil.ReadAll(response.Body)
data, _ := io.ReadAll(response.Body)
//sys.logger.Debugf("Valid response body: %v", string(data))
defer response.Body.Close()
return data, nil
@ -828,7 +828,7 @@ func (sys *SystemInstance) UploadProjectSourceCode(projectID string, zipFile str
header.Add("Content-Type", "application/zip")
header.Add("Accept", "application/json")
zipContents, err := ioutil.ReadFile(zipFile)
zipContents, err := os.ReadFile(zipFile)
if err != nil {
sys.logger.Error("Failed to Read the File " + zipFile + ": " + err.Error())
return "", err

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"testing"
@ -44,19 +43,19 @@ func (sm *senderMock) SendRequest(method, url string, body io.Reader, header htt
if sm.httpStatusCode > 399 {
httpError = fmt.Errorf("http error %v", sm.httpStatusCode)
}
return &http.Response{StatusCode: sm.httpStatusCode, Body: ioutil.NopCloser(strings.NewReader(sm.responseBody))}, httpError
return &http.Response{StatusCode: sm.httpStatusCode, Body: io.NopCloser(strings.NewReader(sm.responseBody))}, httpError
}
func (sm *senderMock) UploadFile(url, file, fieldName string, header http.Header, cookies []*http.Cookie, uploadType string) (*http.Response, error) {
sm.httpMethod = http.MethodPost
sm.urlCalled = url
sm.header = header
return &http.Response{StatusCode: sm.httpStatusCode, Body: ioutil.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
return &http.Response{StatusCode: sm.httpStatusCode, Body: io.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
}
func (sm *senderMock) UploadRequest(method, url, file, fieldName string, header http.Header, cookies []*http.Cookie, uploadType string) (*http.Response, error) {
sm.httpMethod = http.MethodPost
sm.urlCalled = url
sm.header = header
return &http.Response{StatusCode: sm.httpStatusCode, Body: ioutil.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
return &http.Response{StatusCode: sm.httpStatusCode, Body: io.NopCloser(bytes.NewReader([]byte(sm.responseBody)))}, nil
}
func (sm *senderMock) Upload(_ piperHttp.UploadRequestData) (*http.Response, error) {
return &http.Response{}, fmt.Errorf("not implemented")

View File

@ -2,10 +2,11 @@ package cloudfoundry
import (
"fmt"
"os"
"reflect"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
"io/ioutil"
"reflect"
"github.com/SAP/jenkins-library/pkg/log"
)
@ -33,8 +34,8 @@ type manifest struct {
name string
}
var _readFile = ioutil.ReadFile
var _writeFile = ioutil.WriteFile
var _readFile = os.ReadFile
var _writeFile = os.WriteFile
// ReadManifest Reads the manifest denoted by 'name'
func ReadManifest(name string) (Manifest, error) {

View File

@ -8,7 +8,6 @@ import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
)
@ -255,6 +254,6 @@ func TestWriteManifest(t *testing.T) {
}
func cleanup() {
_readFile = ioutil.ReadFile
_writeFile = ioutil.WriteFile
_readFile = os.ReadFile
_writeFile = os.WriteFile
}

View File

@ -4,7 +4,7 @@ package bindings
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
@ -141,7 +141,7 @@ func processBinding(utils cnbutils.BuildUtils, httpClient piperhttp.Sender, plat
return errors.Wrap(err, "failed to load binding from url")
}
bindingContent, err = ioutil.ReadAll(response.Body)
bindingContent, err = io.ReadAll(response.Body)
defer response.Body.Close()
if err != nil {
return errors.Wrap(err, "error reading response")

View File

@ -6,7 +6,7 @@ package command
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"strings"
@ -260,7 +260,7 @@ func TestHelperProcess(*testing.T) {
cmd, args := args[0], args[1:]
switch cmd {
case "/bin/bash":
o, _ := ioutil.ReadAll(os.Stdin)
o, _ := io.ReadAll(os.Stdin)
fmt.Fprintf(os.Stdout, "Stdout: command %v - Stdin: %v\n", cmd, string(o))
fmt.Fprintf(os.Stderr, "Stderr: command %v\n", cmd)
case "echo":

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@ -44,7 +43,7 @@ type StepConfig struct {
func (c *Config) ReadConfig(configuration io.ReadCloser) error {
defer configuration.Close()
content, err := ioutil.ReadAll(configuration)
content, err := io.ReadAll(configuration)
if err != nil {
return errors.Wrapf(err, "error reading %v", configuration)
}

View File

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -29,7 +28,7 @@ func (errReadCloser) Close() error {
}
func customDefaultsOpenFileMock(name string, tokens map[string]string) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("general:\n p0: p0_custom_default\nstages:\n stage1:\n p1: p1_custom_default")), nil
return io.NopCloser(strings.NewReader("general:\n p0: p0_custom_default\nstages:\n stage1:\n p1: p1_custom_default")), nil
}
func TestReadConfig(t *testing.T) {
@ -40,7 +39,7 @@ func TestReadConfig(t *testing.T) {
myConfig := strings.NewReader("general:\n generalTestKey: generalTestValue\nsteps:\n testStep:\n testStepKey: testStepValue")
err := c.ReadConfig(ioutil.NopCloser(myConfig)) // NopCloser "no-ops" the closing interface since strings do not need to be closed
err := c.ReadConfig(io.NopCloser(myConfig)) // NopCloser "no-ops" the closing interface since strings do not need to be closed
if err != nil {
t.Errorf("Got error although no error expected: %v", err)
}
@ -64,7 +63,7 @@ func TestReadConfig(t *testing.T) {
t.Run("Unmarshalling failure", func(t *testing.T) {
myConfig := strings.NewReader("general:\n generalTestKey: generalTestValue\nsteps:\n testStep:\n\ttestStepKey: testStepValue")
err := c.ReadConfig(ioutil.NopCloser(myConfig))
err := c.ReadConfig(io.NopCloser(myConfig))
if err == nil {
t.Errorf("Got no error although error expected.")
}
@ -126,9 +125,9 @@ steps:
flags := map[string]interface{}{"p7": "p7_flag"}
var c Config
defaults := []io.ReadCloser{ioutil.NopCloser(strings.NewReader(defaults1)), ioutil.NopCloser(strings.NewReader(defaults2))}
defaults := []io.ReadCloser{io.NopCloser(strings.NewReader(defaults1)), io.NopCloser(strings.NewReader(defaults2))}
myConfig := ioutil.NopCloser(strings.NewReader(testConfig))
myConfig := io.NopCloser(strings.NewReader(testConfig))
parameterMetadata := []StepParameters{
{
@ -238,9 +237,9 @@ steps:
p0: p0_general_default
`
var c Config
defaults := []io.ReadCloser{ioutil.NopCloser(strings.NewReader(defaults1))}
defaults := []io.ReadCloser{io.NopCloser(strings.NewReader(defaults1))}
myConfig := ioutil.NopCloser(strings.NewReader(testConfig))
myConfig := io.NopCloser(strings.NewReader(testConfig))
stepMeta := StepData{Spec: StepSpec{Inputs: StepInputs{Parameters: []StepParameters{
{Name: "p0", ResourceRef: []ResourceReference{{Name: "commonPipelineEnvironment", Param: "p0"}}},
@ -261,7 +260,7 @@ steps:
c.openFile = customDefaultsOpenFileMock
stepConfig, err := c.GetStepConfig(nil, "", ioutil.NopCloser(strings.NewReader(testConfDefaults)), nil, false, StepFilters{General: []string{"p0"}}, StepData{}, nil, "stage1", "step1")
stepConfig, err := c.GetStepConfig(nil, "", io.NopCloser(strings.NewReader(testConfDefaults)), nil, false, StepFilters{General: []string{"p0"}}, StepData{}, nil, "stage1", "step1")
assert.NoError(t, err, "Error occurred but no error expected")
assert.Equal(t, "p0_custom_default", stepConfig.Config["p0"])
@ -275,7 +274,7 @@ steps:
c.openFile = customDefaultsOpenFileMock
stepConfig, err := c.GetStepConfig(nil, "", ioutil.NopCloser(strings.NewReader(testConfDefaults)), nil, true, StepFilters{General: []string{"p0"}}, StepData{}, nil, "stage1", "step1")
stepConfig, err := c.GetStepConfig(nil, "", io.NopCloser(strings.NewReader(testConfDefaults)), nil, true, StepFilters{General: []string{"p0"}}, StepData{}, nil, "stage1", "step1")
assert.NoError(t, err, "Error occurred but no error expected")
assert.Equal(t, nil, stepConfig.Config["p0"])
@ -296,7 +295,7 @@ steps:
}
testConf := "general:\n p1: p1_conf"
stepConfig, err := c.GetStepConfig(nil, "", ioutil.NopCloser(strings.NewReader(testConf)), nil, false, StepFilters{General: []string{"p0", "p1"}}, metadata, nil, "stage1", "step1")
stepConfig, err := c.GetStepConfig(nil, "", io.NopCloser(strings.NewReader(testConf)), nil, false, StepFilters{General: []string{"p0", "p1"}}, metadata, nil, "stage1", "step1")
assert.NoError(t, err, "Error occurred but no error expected")
assert.Equal(t, "p0_step_default", stepConfig.Config["p0"])
@ -318,7 +317,7 @@ steps:
}
testConf := "general:\n p0: true"
stepConfig, err := c.GetStepConfig(nil, "", ioutil.NopCloser(strings.NewReader(testConf)), nil, false, StepFilters{General: []string{"p0", "p1"}}, metadata, nil, "stage1", "step1")
stepConfig, err := c.GetStepConfig(nil, "", io.NopCloser(strings.NewReader(testConf)), nil, false, StepFilters{General: []string{"p0", "p1"}}, metadata, nil, "stage1", "step1")
assert.NoError(t, err, "Error occurred but no error expected")
assert.Equal(t, true, stepConfig.Config["p0"])
@ -340,7 +339,7 @@ steps:
testConf := ""
paramJSON := "{\"p1\":{\"subParam\":\"p1_value\"}}"
stepConfig, err := c.GetStepConfig(nil, paramJSON, ioutil.NopCloser(strings.NewReader(testConf)), nil, true, StepFilters{Parameters: []string{"p0"}}, metadata, nil, "stage1", "step1")
stepConfig, err := c.GetStepConfig(nil, paramJSON, io.NopCloser(strings.NewReader(testConf)), nil, true, StepFilters{Parameters: []string{"p0"}}, metadata, nil, "stage1", "step1")
assert.NoError(t, err, "Error occurred but no error expected")
assert.Equal(t, "p1_value", stepConfig.Config["p0"])
@ -348,27 +347,27 @@ steps:
t.Run("Failure case config", func(t *testing.T) {
var c Config
myConfig := ioutil.NopCloser(strings.NewReader("invalid config"))
myConfig := io.NopCloser(strings.NewReader("invalid config"))
_, err := c.GetStepConfig(nil, "", myConfig, nil, false, StepFilters{}, StepData{}, nil, "stage1", "step1")
assert.EqualError(t, err, "failed to parse custom pipeline configuration: format of configuration is invalid \"invalid config\": error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type config.Config", "default error expected")
})
t.Run("Failure case defaults", func(t *testing.T) {
var c Config
myConfig := ioutil.NopCloser(strings.NewReader(""))
myDefaults := []io.ReadCloser{ioutil.NopCloser(strings.NewReader("invalid defaults"))}
myConfig := io.NopCloser(strings.NewReader(""))
myDefaults := []io.ReadCloser{io.NopCloser(strings.NewReader("invalid defaults"))}
_, err := c.GetStepConfig(nil, "", myConfig, myDefaults, false, StepFilters{}, StepData{}, nil, "stage1", "step1")
assert.EqualError(t, err, "failed to read default configuration: error unmarshalling \"invalid defaults\": error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type config.Config", "default error expected")
})
t.Run("Test reporting parameters with aliases and cpe resources", func(t *testing.T) {
var c Config
testConfig := ioutil.NopCloser(strings.NewReader(`general:
testConfig := io.NopCloser(strings.NewReader(`general:
gcpJsonKeyFilePath: gcpJsonKeyFilePath_value
steps:
step1:
jsonKeyFilePath: gcpJsonKeyFilePath_from_alias`))
testDefaults := []io.ReadCloser{ioutil.NopCloser(strings.NewReader(`general:
testDefaults := []io.ReadCloser{io.NopCloser(strings.NewReader(`general:
pipelineId: gcsBucketId_from_alias
steps:
step1:
@ -380,7 +379,7 @@ steps:
t.Fatal("Failed to create sub directory")
}
err = ioutil.WriteFile(filepath.Join(cpeDir, "gcsFolderPath.json"), []byte("\"value_from_cpe\""), 0700)
err = os.WriteFile(filepath.Join(cpeDir, "gcsFolderPath.json"), []byte("\"value_from_cpe\""), 0700)
assert.NoError(t, err)
stepMeta := StepData{Spec: StepSpec{Inputs: StepInputs{Parameters: []StepParameters{}}}}
@ -437,9 +436,9 @@ stages:
acceptedParams := []string{"p0", "p1", "p2", "p3"}
var c Config
defaults := []io.ReadCloser{ioutil.NopCloser(strings.NewReader(defaults1))}
defaults := []io.ReadCloser{io.NopCloser(strings.NewReader(defaults1))}
myConfig := ioutil.NopCloser(strings.NewReader(testConfig))
myConfig := io.NopCloser(strings.NewReader(testConfig))
stepConfig, err := c.GetStageConfig(paramJSON, myConfig, defaults, false, acceptedParams, "stage1")
@ -479,9 +478,9 @@ stages:
acceptedParams := []string{}
var c Config
defaults := []io.ReadCloser{ioutil.NopCloser(strings.NewReader(defaults1))}
defaults := []io.ReadCloser{io.NopCloser(strings.NewReader(defaults1))}
myConfig := ioutil.NopCloser(strings.NewReader(testConfig))
myConfig := io.NopCloser(strings.NewReader(testConfig))
stepConfig, err := c.GetStageConfig(paramJSON, myConfig, defaults, false, acceptedParams, "stage1")

View File

@ -3,7 +3,6 @@ package config
import (
"fmt"
"io"
"io/ioutil"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
@ -27,7 +26,7 @@ func (d *PipelineDefaults) ReadPipelineDefaults(defaultSources []io.ReadCloser)
var c Config
var err error
content, err := ioutil.ReadAll(def)
content, err := io.ReadAll(def)
if err != nil {
return errors.Wrapf(err, "error reading %v", def)
}

View File

@ -5,7 +5,6 @@ package config
import (
"io"
"io/ioutil"
"strings"
"testing"
)
@ -17,7 +16,7 @@ func TestReadPipelineDefaults(t *testing.T) {
t.Run("Success case", func(t *testing.T) {
d0 := strings.NewReader("general:\n testStepKey1: testStepValue1")
d1 := strings.NewReader("general:\n testStepKey2: testStepValue2")
err := d.ReadPipelineDefaults([]io.ReadCloser{ioutil.NopCloser(d0), ioutil.NopCloser(d1)})
err := d.ReadPipelineDefaults([]io.ReadCloser{io.NopCloser(d0), io.NopCloser(d1)})
if err != nil {
t.Errorf("Got error although no error expected: %v", err)
@ -48,7 +47,7 @@ func TestReadPipelineDefaults(t *testing.T) {
t.Run("Unmarshalling failure", func(t *testing.T) {
myConfig := strings.NewReader("general:\n\ttestStepKey: testStepValue")
err := d.ReadPipelineDefaults([]io.ReadCloser{ioutil.NopCloser(myConfig)})
err := d.ReadPipelineDefaults([]io.ReadCloser{io.NopCloser(myConfig)})
if err == nil {
t.Errorf("Got no error although error expected.")
}

Some files were not shown because too many files have changed in this diff Show More