Skip to content

Commit 0ba4c22

Browse files
jliemptI557621Gulom Alimov
authored
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 <[email protected]> Co-authored-by: Gulom Alimov <[email protected]>
1 parent 69347fe commit 0ba4c22

File tree

162 files changed

+566
-657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+566
-657
lines changed

cmd/abapAddonAssemblyKitRegisterPackages.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package cmd
22

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"os"
66
"path/filepath"
77

88
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
@@ -98,7 +98,7 @@ func uploadSarFiles(repos []abaputils.Repository, conn abapbuild.Connector, read
9898
type readFile func(path string) ([]byte, error)
9999

100100
func reader(path string) ([]byte, error) {
101-
return ioutil.ReadFile(path)
101+
return os.ReadFile(path)
102102
}
103103

104104
func registerPackages(repos []abaputils.Repository, conn abapbuild.Connector) ([]abaputils.Repository, error) {

cmd/abapEnvironmentCheckoutBranch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http/cookiejar"
88
"reflect"
99
"time"
@@ -127,7 +127,7 @@ func triggerCheckout(repositoryName string, branchName string, checkoutConnectio
127127
// Parse Response
128128
var body abaputils.PullEntity
129129
var abapResp map[string]*json.RawMessage
130-
bodyText, errRead := ioutil.ReadAll(resp.Body)
130+
bodyText, errRead := io.ReadAll(resp.Body)
131131
if errRead != nil {
132132
return uriConnectionDetails, err
133133
}

cmd/abapEnvironmentCheckoutBranch_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package cmd
55

66
import (
77
"encoding/json"
8-
"io/ioutil"
98
"os"
109
"testing"
1110

@@ -172,7 +171,7 @@ repositories:
172171
- name: 'testRepo3'
173172
branch: 'testBranch3'`
174173

175-
err := ioutil.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
174+
err := os.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
176175

177176
config := abapEnvironmentCheckoutBranchOptions{
178177
CfAPIEndpoint: "https://api.endpoint.com",
@@ -215,7 +214,7 @@ repositories:
215214
manifestFileString := ``
216215

217216
manifestFileStringBody := []byte(manifestFileString)
218-
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
217+
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
219218

220219
config := abapEnvironmentCheckoutBranchOptions{
221220
CfAPIEndpoint: "https://api.endpoint.com",
@@ -263,7 +262,7 @@ repositories:
263262
- repo: 'testRepo2'`
264263

265264
manifestFileStringBody := []byte(manifestFileString)
266-
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
265+
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
267266

268267
config := abapEnvironmentCheckoutBranchOptions{
269268
CfAPIEndpoint: "https://api.endpoint.com",

cmd/abapEnvironmentCloneGitRepo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/cookiejar"
99
"reflect"
@@ -149,7 +149,7 @@ func triggerClone(repo abaputils.Repository, cloneConnectionDetails abaputils.Co
149149
// Parse Response
150150
var body abaputils.CloneEntity
151151
var abapResp map[string]*json.RawMessage
152-
bodyText, errRead := ioutil.ReadAll(resp.Body)
152+
bodyText, errRead := io.ReadAll(resp.Body)
153153
if errRead != nil {
154154
return uriConnectionDetails, err, false
155155
}

cmd/abapEnvironmentCloneGitRepo_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package cmd
66
import (
77
"bytes"
88
"encoding/json"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
"os"
1212
"testing"
@@ -421,7 +421,7 @@ func TestALreadyCloned(t *testing.T) {
421421
resp := http.Response{
422422
Status: "400 Bad Request",
423423
StatusCode: 400,
424-
Body: ioutil.NopCloser(bytes.NewReader(body)),
424+
Body: io.NopCloser(bytes.NewReader(body)),
425425
}
426426

427427
repo := abaputils.Repository{
@@ -469,7 +469,7 @@ func TestALreadyCloned(t *testing.T) {
469469
resp := http.Response{
470470
Status: "400 Bad Request",
471471
StatusCode: 400,
472-
Body: ioutil.NopCloser(bytes.NewReader(body)),
472+
Body: io.NopCloser(bytes.NewReader(body)),
473473
}
474474

475475
repo := abaputils.Repository{
@@ -517,7 +517,7 @@ func TestALreadyCloned(t *testing.T) {
517517
resp := http.Response{
518518
Status: "400 Bad Request",
519519
StatusCode: 400,
520-
Body: ioutil.NopCloser(bytes.NewReader(body)),
520+
Body: io.NopCloser(bytes.NewReader(body)),
521521
}
522522

523523
repo := abaputils.Repository{
@@ -555,7 +555,7 @@ func TestALreadyCloned(t *testing.T) {
555555
resp := http.Response{
556556
Status: "400 Bad Request",
557557
StatusCode: 400,
558-
Body: ioutil.NopCloser(bytes.NewReader(body)),
558+
Body: io.NopCloser(bytes.NewReader(body)),
559559
}
560560

561561
repo := abaputils.Repository{

cmd/abapEnvironmentCreateSystem_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package cmd
55

66
import (
7-
"io/ioutil"
87
"os"
98
"testing"
109

@@ -75,7 +74,7 @@ func TestRunAbapEnvironmentCreateSystem(t *testing.T) {
7574
plan: "testPlan"`
7675

7776
manifestFileStringBody := []byte(manifestFileString)
78-
err := ioutil.WriteFile("customManifest.yml", manifestFileStringBody, 0644)
77+
err := os.WriteFile("customManifest.yml", manifestFileStringBody, 0644)
7978

8079
err = runAbapEnvironmentCreateSystem(&config, nil, cf, u)
8180
if assert.NoError(t, err) {
@@ -124,7 +123,7 @@ repositories:
124123
`
125124

126125
addonYMLBytes := []byte(addonYML)
127-
err := ioutil.WriteFile("addon.yml", addonYMLBytes, 0644)
126+
err := os.WriteFile("addon.yml", addonYMLBytes, 0644)
128127

129128
expectedResult := "{\"admin_email\":\"[email protected]\",\"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\"}"
130129

@@ -168,7 +167,7 @@ repositories:
168167
`
169168

170169
addonYMLBytes := []byte(addonYML)
171-
err := ioutil.WriteFile("addon.yml", addonYMLBytes, 0644)
170+
err := os.WriteFile("addon.yml", addonYMLBytes, 0644)
172171

173172
expectedResult := "{\"admin_email\":\"[email protected]\",\"is_development_allowed\":true,\"sapsystemname\":\"H02\",\"size_of_persistence\":4,\"size_of_runtime\":4}"
174173

@@ -214,7 +213,7 @@ repositories:
214213
`
215214

216215
addonYMLBytes := []byte(addonYML)
217-
err := ioutil.WriteFile("addon.yml", addonYMLBytes, 0644)
216+
err := os.WriteFile("addon.yml", addonYMLBytes, 0644)
218217

219218
expectedResult := "{\"admin_email\":\"[email protected]\",\"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\"}"
220219

cmd/abapEnvironmentCreateTag.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http/cookiejar"
88
"strings"
99
"time"
@@ -129,7 +129,7 @@ func createSingleTag(item CreateTagBacklog, index int, telemetryData *telemetry.
129129
// Parse response
130130
var createTagResponse CreateTagResponse
131131
var abapResp map[string]*json.RawMessage
132-
bodyText, _ := ioutil.ReadAll(resp.Body)
132+
bodyText, _ := io.ReadAll(resp.Body)
133133

134134
if err = json.Unmarshal(bodyText, &abapResp); err != nil {
135135
return err

cmd/abapEnvironmentPullGitRepo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http/cookiejar"
88
"reflect"
99
"time"
@@ -151,7 +151,7 @@ func triggerPull(repo abaputils.Repository, pullConnectionDetails abaputils.Conn
151151
// Parse Response
152152
var body abaputils.PullEntity
153153
var abapResp map[string]*json.RawMessage
154-
bodyText, errRead := ioutil.ReadAll(resp.Body)
154+
bodyText, errRead := io.ReadAll(resp.Body)
155155
if errRead != nil {
156156
return uriConnectionDetails, err
157157
}

cmd/abapEnvironmentPullGitRepo_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package cmd
55

66
import (
77
"encoding/json"
8-
"io/ioutil"
98
"os"
109
"testing"
1110

@@ -134,7 +133,7 @@ repositories:
134133
- name: 'testRepo3'
135134
branch: 'testBranch3'`
136135

137-
err := ioutil.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
136+
err := os.WriteFile("repositoriesTest.yml", []byte(manifestFileString), 0644)
138137

139138
config := abapEnvironmentPullGitRepoOptions{
140139
CfAPIEndpoint: "https://api.endpoint.com",
@@ -370,7 +369,7 @@ repositories:
370369
manifestFileString := ``
371370

372371
manifestFileStringBody := []byte(manifestFileString)
373-
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
372+
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
374373

375374
config := abapEnvironmentPullGitRepoOptions{
376375
CfAPIEndpoint: "https://api.endpoint.com",
@@ -419,7 +418,7 @@ repositories:
419418
- repo: 'testRepo2'`
420419

421420
manifestFileStringBody := []byte(manifestFileString)
422-
err := ioutil.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
421+
err := os.WriteFile("repositoriesTest.yml", manifestFileStringBody, 0644)
423422

424423
config := abapEnvironmentPullGitRepoOptions{
425424
CfAPIEndpoint: "https://api.endpoint.com",

cmd/abapEnvironmentPushATCSystemConfig.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/http/cookiejar"
10+
"os"
1011
"path/filepath"
1112
"reflect"
1213
"strconv"
@@ -151,7 +152,7 @@ func readATCSystemConfigurationFile(config *abapEnvironmentPushATCSystemConfigOp
151152
if err != nil {
152153
return parsedConfigurationJson, atcSystemConfiguartionJsonFile, err
153154
}
154-
atcSystemConfiguartionJsonFile, err = ioutil.ReadFile(filename)
155+
atcSystemConfiguartionJsonFile, err = os.ReadFile(filename)
155156
if err != nil {
156157
return parsedConfigurationJson, atcSystemConfiguartionJsonFile, err
157158
}
@@ -412,7 +413,7 @@ func checkConfigExistsInBackend(config *abapEnvironmentPushATCSystemConfigOption
412413
return false, configName, configUUID, configLastChangedAt, err
413414
}
414415
var body []byte
415-
body, err = ioutil.ReadAll(resp.Body)
416+
body, err = io.ReadAll(resp.Body)
416417
if err != nil {
417418
return false, configName, configUUID, configLastChangedAt, err
418419
}
@@ -443,7 +444,7 @@ func HandleHttpResponse(resp *http.Response, err error, message string, connecti
443444
log.Entry().WithError(err).WithField("ABAP Endpoint", connectionDetails.URL).Error("Request failed")
444445
} else {
445446
log.Entry().WithField("StatusCode", resp.Status).Info(message)
446-
bodyText, readError = ioutil.ReadAll(resp.Body)
447+
bodyText, readError = io.ReadAll(resp.Body)
447448
if readError != nil {
448449
defer resp.Body.Close()
449450
return readError

cmd/abapEnvironmentRunATCCheck.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"bytes"
55
"encoding/json"
66
"encoding/xml"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/http/cookiejar"
10+
"os"
1011
"reflect"
1112
"strconv"
1213
"strings"
@@ -84,7 +85,7 @@ func fetchAndPersistATCResults(resp *http.Response, details abaputils.Connection
8485
// Parse response
8586
var body []byte
8687
if err == nil {
87-
body, err = ioutil.ReadAll(resp.Body)
88+
body, err = io.ReadAll(resp.Body)
8889
}
8990
if err == nil {
9091
defer resp.Body.Close()
@@ -225,7 +226,7 @@ func logAndPersistAndEvaluateATCResults(utils piperutils.FileUtils, body []byte,
225226
log.Entry().Info("There were no results from this run, most likely the checked Software Components are empty or contain no ATC findings")
226227
}
227228

228-
err := ioutil.WriteFile(atcResultFileName, body, 0o644)
229+
err := os.WriteFile(atcResultFileName, body, 0o644)
229230
if err == nil {
230231
log.Entry().Infof("Writing %s file was successful", atcResultFileName)
231232
var reports []piperutils.Path
@@ -242,7 +243,7 @@ func logAndPersistAndEvaluateATCResults(utils piperutils.FileUtils, body []byte,
242243
htmlString := generateHTMLDocument(parsedXML)
243244
htmlStringByte := []byte(htmlString)
244245
atcResultHTMLFileName := strings.Trim(atcResultFileName, ".xml") + ".html"
245-
err = ioutil.WriteFile(atcResultHTMLFileName, htmlStringByte, 0o644)
246+
err = os.WriteFile(atcResultHTMLFileName, htmlStringByte, 0o644)
246247
if err == nil {
247248
log.Entry().Info("Writing " + atcResultHTMLFileName + " file was successful")
248249
reports = append(reports, piperutils.Path{Target: atcResultFileName, Name: "ATC Results HTML file", Mandatory: true})
@@ -317,7 +318,7 @@ func logResponseBody(resp *http.Response) error {
317318
var bodyText []byte
318319
var readError error
319320
if resp != nil {
320-
bodyText, readError = ioutil.ReadAll(resp.Body)
321+
bodyText, readError = io.ReadAll(resp.Body)
321322
if readError != nil {
322323
return readError
323324
}
@@ -353,7 +354,7 @@ func pollATCRun(details abaputils.ConnectionDetailsHTTP, body []byte, client pip
353354
if err != nil {
354355
return "", errors.Errorf("Getting HTTP response failed: %v", err)
355356
}
356-
bodyText, err := ioutil.ReadAll(resp.Body)
357+
bodyText, err := io.ReadAll(resp.Body)
357358
if err != nil {
358359
return "", errors.Errorf("Reading response body failed: %v", err)
359360
}

cmd/abapEnvironmentRunATCCheck_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package cmd
55

66
import (
77
"encoding/xml"
8-
"io/ioutil"
98
"os"
109
"testing"
1110

@@ -655,7 +654,7 @@ atcobjects:
655654
- name: /DMO/SWC
656655
`
657656

658-
err := ioutil.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
657+
err := os.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
659658
if assert.Equal(t, err, nil) {
660659
bodyString, err := buildATCRequestBody(config)
661660
assert.Equal(t, nil, err)
@@ -691,7 +690,7 @@ objectset:
691690
`
692691
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>"
693692

694-
err := ioutil.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
693+
err := os.WriteFile(config.AtcConfig, []byte(yamlBody), 0o644)
695694
if assert.Equal(t, err, nil) {
696695
bodyString, err := buildATCRequestBody(config)
697696
assert.Equal(t, nil, err)
@@ -718,7 +717,7 @@ objectset:
718717
- name: /DMO/SWC
719718
`
720719

721-
err := ioutil.WriteFile(config.Repositories, []byte(yamlBody), 0o644)
720+
err := os.WriteFile(config.Repositories, []byte(yamlBody), 0o644)
722721
if assert.Equal(t, err, nil) {
723722
bodyString, err := buildATCRequestBody(config)
724723
assert.Equal(t, nil, err)

0 commit comments

Comments
 (0)