Skip to content

Commit f1d065a

Browse files
committed
Merge branch 'upgrade-go-1-6' into 'master'
refactor: upgrade Go to 1.16 See merge request postgres-ai/database-lab!326
2 parents 88b35db + f775d30 commit f1d065a

File tree

32 files changed

+89
-135
lines changed

32 files changed

+89
-135
lines changed

.gitlab-ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: golang:1.15
1+
image: golang:1.16
22

33
include:
44
- template: Security/SAST.gitlab-ci.yml
@@ -43,7 +43,7 @@ lint:
4343
when: manual
4444

4545
build-binary-alpine:
46-
image: golang:1.15-alpine
46+
image: golang:1.16-alpine
4747
stage: build-binary
4848
only:
4949
refs:

cmd/cli/commands/config/file.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package config
66

77
import (
8-
"io/ioutil"
8+
"os"
99
"os/user"
1010
"path"
1111

@@ -46,7 +46,7 @@ func BuildFileName(dirname string) string {
4646

4747
// Load loads a CLI config by a provided filename.
4848
func Load(filename string) (*CLIConfig, error) {
49-
configData, err := ioutil.ReadFile(filename)
49+
configData, err := os.ReadFile(filename)
5050
if err != nil {
5151
return nil, err
5252
}
@@ -76,7 +76,7 @@ func SaveConfig(filename string, cfg *CLIConfig) error {
7676
return err
7777
}
7878

79-
if err := ioutil.WriteFile(filename, configData, 0600); err != nil {
79+
if err := os.WriteFile(filename, configData, 0600); err != nil {
8080
return err
8181
}
8282

cmd/runci/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"context"
5-
"io/ioutil"
65
"net/url"
76
"os"
87
"strings"
@@ -137,7 +136,7 @@ func loadConfiguration() (*runci.Config, error) {
137136
return nil, errors.Wrap(err, "failed to get config path")
138137
}
139138

140-
b, err := ioutil.ReadFile(configPath)
139+
b, err := os.ReadFile(configPath)
141140
if err != nil {
142141
return nil, errors.Errorf("error loading %s config file", configPath)
143142
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module gitlab.com/postgres-ai/database-lab/v2
22

3-
go 1.15
3+
go 1.16
44

55
require (
66
github.com/AlekSi/pointer v1.1.0

go.sum

-32
Large diffs are not rendered by default.

pkg/client/dblabapi/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"crypto/tls"
1111
"encoding/json"
1212
"fmt"
13-
"io/ioutil"
13+
"io"
1414
"net/http"
1515
"net/http/httputil"
1616
"net/url"
@@ -127,7 +127,7 @@ func (c *Client) Do(ctx context.Context, request *http.Request) (response *http.
127127

128128
// Extract error if the status code is not successful.
129129
if response.StatusCode >= http.StatusBadRequest {
130-
b, err := ioutil.ReadAll(response.Body)
130+
b, err := io.ReadAll(response.Body)
131131
if err != nil {
132132
return response, err
133133
}

pkg/client/dblabapi/clone.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/json"
1111
"fmt"
1212
"io"
13-
"io/ioutil"
1413
"net/http"
1514
"net/url"
1615
"time"
@@ -372,7 +371,7 @@ func (c *Client) DownloadArtifact(ctx context.Context, cloneID, sessionID, artif
372371
}
373372

374373
if response.StatusCode != http.StatusOK {
375-
content, err := ioutil.ReadAll(response.Body)
374+
content, err := io.ReadAll(response.Body)
376375
if err != nil {
377376
return nil, errors.Wrapf(err, "failed to read response, status code: %d", response.StatusCode)
378377
}

pkg/client/dblabapi/clone_test.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"testing"
1010
"time"
@@ -46,7 +46,7 @@ func TestClientListClones(t *testing.T) {
4646

4747
return &http.Response{
4848
StatusCode: 200,
49-
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
49+
Body: io.NopCloser(bytes.NewBuffer(body)),
5050
Header: make(http.Header),
5151
}
5252
})
@@ -70,7 +70,7 @@ func TestClientListClonesWithFailedRequest(t *testing.T) {
7070
mockClient := NewTestClient(func(r *http.Request) *http.Response {
7171
return &http.Response{
7272
StatusCode: 200,
73-
Body: ioutil.NopCloser(bytes.NewBuffer([]byte{})),
73+
Body: io.NopCloser(bytes.NewBuffer([]byte{})),
7474
Header: make(http.Header),
7575
}
7676
})
@@ -116,7 +116,7 @@ func TestClientCreateClone(t *testing.T) {
116116
if r.Method == http.MethodPost {
117117
assert.Equal(t, r.URL.String(), "https://example.com/clone")
118118

119-
requestBody, err := ioutil.ReadAll(r.Body)
119+
requestBody, err := io.ReadAll(r.Body)
120120
require.NoError(t, err)
121121
defer func() { _ = r.Body.Close() }()
122122

@@ -135,7 +135,7 @@ func TestClientCreateClone(t *testing.T) {
135135

136136
return &http.Response{
137137
StatusCode: 200,
138-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
138+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
139139
Header: make(http.Header),
140140
}
141141
})
@@ -191,7 +191,7 @@ func TestClientCreateCloneAsync(t *testing.T) {
191191
mockClient := NewTestClient(func(r *http.Request) *http.Response {
192192
assert.Equal(t, r.URL.String(), "https://example.com/clone")
193193

194-
requestBody, err := ioutil.ReadAll(r.Body)
194+
requestBody, err := io.ReadAll(r.Body)
195195
require.NoError(t, err)
196196
defer func() { _ = r.Body.Close() }()
197197

@@ -204,7 +204,7 @@ func TestClientCreateCloneAsync(t *testing.T) {
204204

205205
return &http.Response{
206206
StatusCode: 200,
207-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
207+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
208208
Header: make(http.Header),
209209
}
210210
})
@@ -239,7 +239,7 @@ func TestClientCreateCloneWithFailedRequest(t *testing.T) {
239239
mockClient := NewTestClient(func(req *http.Request) *http.Response {
240240
return &http.Response{
241241
StatusCode: 200,
242-
Body: ioutil.NopCloser(bytes.NewBuffer([]byte{})),
242+
Body: io.NopCloser(bytes.NewBuffer([]byte{})),
243243
Header: make(http.Header),
244244
}
245245
})
@@ -287,7 +287,7 @@ func TestClientGetClone(t *testing.T) {
287287

288288
return &http.Response{
289289
StatusCode: 200,
290-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
290+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
291291
Header: make(http.Header),
292292
}
293293
})
@@ -311,7 +311,7 @@ func TestClientGetCloneWithFailedRequest(t *testing.T) {
311311
mockClient := NewTestClient(func(req *http.Request) *http.Response {
312312
return &http.Response{
313313
StatusCode: 200,
314-
Body: ioutil.NopCloser(bytes.NewBuffer([]byte{})),
314+
Body: io.NopCloser(bytes.NewBuffer([]byte{})),
315315
Header: make(http.Header),
316316
}
317317
})
@@ -353,7 +353,7 @@ func TestClientUpdateClone(t *testing.T) {
353353
mockClient := NewTestClient(func(r *http.Request) *http.Response {
354354
assert.Equal(t, r.URL.String(), "https://example.com/clone/testCloneID")
355355

356-
requestBody, err := ioutil.ReadAll(r.Body)
356+
requestBody, err := io.ReadAll(r.Body)
357357
require.NoError(t, err)
358358
defer func() { _ = r.Body.Close() }()
359359

@@ -369,7 +369,7 @@ func TestClientUpdateClone(t *testing.T) {
369369

370370
return &http.Response{
371371
StatusCode: 200,
372-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
372+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
373373
Header: make(http.Header),
374374
}
375375
})
@@ -403,7 +403,7 @@ func TestClientUpdateCloneWithFailedRequest(t *testing.T) {
403403

404404
return &http.Response{
405405
StatusCode: 400,
406-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
406+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
407407
Header: make(http.Header),
408408
}
409409
})
@@ -443,7 +443,7 @@ func TestClientDestroyClone(t *testing.T) {
443443

444444
return &http.Response{
445445
StatusCode: statusCode,
446-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
446+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
447447
Header: make(http.Header),
448448
}
449449
})
@@ -468,7 +468,7 @@ func TestClientDestroyCloneAsync(t *testing.T) {
468468

469469
return &http.Response{
470470
StatusCode: 200,
471-
Body: ioutil.NopCloser(bytes.NewBuffer(nil)),
471+
Body: io.NopCloser(bytes.NewBuffer(nil)),
472472
Header: make(http.Header),
473473
}
474474
})
@@ -499,7 +499,7 @@ func TestClientDestroyCloneWithFailedRequest(t *testing.T) {
499499

500500
return &http.Response{
501501
StatusCode: 404,
502-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
502+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
503503
Header: make(http.Header),
504504
}
505505
})
@@ -541,7 +541,7 @@ func TestClientResetClone(t *testing.T) {
541541

542542
return &http.Response{
543543
StatusCode: 200,
544-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
544+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
545545
Header: make(http.Header),
546546
}
547547
})
@@ -566,7 +566,7 @@ func TestClientResetCloneAsync(t *testing.T) {
566566

567567
return &http.Response{
568568
StatusCode: 200,
569-
Body: ioutil.NopCloser(bytes.NewBuffer(nil)),
569+
Body: io.NopCloser(bytes.NewBuffer(nil)),
570570
Header: make(http.Header),
571571
}
572572
})
@@ -597,7 +597,7 @@ func TestClientResetCloneWithFailedRequest(t *testing.T) {
597597

598598
return &http.Response{
599599
StatusCode: 401,
600-
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
600+
Body: io.NopCloser(bytes.NewBuffer(responseBody)),
601601
Header: make(http.Header),
602602
}
603603
})

pkg/client/dblabapi/snapshot_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"testing"
1010

@@ -34,7 +34,7 @@ func TestClientListSnapshots(t *testing.T) {
3434

3535
return &http.Response{
3636
StatusCode: 200,
37-
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
37+
Body: io.NopCloser(bytes.NewBuffer(body)),
3838
Header: make(http.Header),
3939
}
4040
})
@@ -58,7 +58,7 @@ func TestClientListSnapshotsWithFailedRequest(t *testing.T) {
5858
mockClient := NewTestClient(func(r *http.Request) *http.Response {
5959
return &http.Response{
6060
StatusCode: 200,
61-
Body: ioutil.NopCloser(bytes.NewBuffer([]byte{})),
61+
Body: io.NopCloser(bytes.NewBuffer([]byte{})),
6262
Header: make(http.Header),
6363
}
6464
})

pkg/client/dblabapi/status_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"testing"
1010

@@ -60,7 +60,7 @@ func TestClientStatus(t *testing.T) {
6060

6161
return &http.Response{
6262
StatusCode: 200,
63-
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
63+
Body: io.NopCloser(bytes.NewBuffer(body)),
6464
Header: make(http.Header),
6565
}
6666
})
@@ -84,7 +84,7 @@ func TestClientStatusWithFailedRequest(t *testing.T) {
8484
mockClient := NewTestClient(func(r *http.Request) *http.Response {
8585
return &http.Response{
8686
StatusCode: 200,
87-
Body: ioutil.NopCloser(bytes.NewBuffer([]byte{})),
87+
Body: io.NopCloser(bytes.NewBuffer([]byte{})),
8888
Header: make(http.Header),
8989
}
9090
})

pkg/client/platform/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"context"
1111
"encoding/json"
1212
"fmt"
13-
"io/ioutil"
13+
"io"
1414
"net/http"
1515
"net/url"
1616
"path"
@@ -111,14 +111,14 @@ func (p *Client) doRequest(ctx context.Context, request *http.Request, parser re
111111
defer func() { _ = response.Body.Close() }()
112112

113113
if response.StatusCode != http.StatusOK {
114-
body, err := ioutil.ReadAll(response.Body)
114+
body, err := io.ReadAll(response.Body)
115115
if err != nil {
116116
return errors.Wrap(err, "failed to read response")
117117
}
118118

119119
log.Dbg(fmt.Sprintf("Response: %v", string(body)))
120120

121-
response.Body = ioutil.NopCloser(bytes.NewBuffer(body))
121+
response.Body = io.NopCloser(bytes.NewBuffer(body))
122122
if err := parser(response); err != nil {
123123
return errors.Wrap(err, "failed to parse response")
124124
}

pkg/client/platform/client_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"bytes"
99
"context"
1010
"encoding/json"
11-
"io/ioutil"
11+
"io"
1212
"net/http"
1313
"testing"
1414

@@ -89,7 +89,7 @@ func TestClientChecksPlatformToken(t *testing.T) {
8989

9090
return &http.Response{
9191
StatusCode: http.StatusOK,
92-
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
92+
Body: io.NopCloser(bytes.NewBuffer(body)),
9393
}
9494
})
9595

@@ -122,7 +122,7 @@ func TestClientChecksPlatformTokenFailed(t *testing.T) {
122122

123123
return &http.Response{
124124
StatusCode: http.StatusUnauthorized,
125-
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
125+
Body: io.NopCloser(bytes.NewBuffer(body)),
126126
}
127127
})
128128

pkg/config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package config
77

88
import (
9-
"io/ioutil"
9+
"os"
1010

1111
"github.com/pkg/errors"
1212
"gopkg.in/yaml.v2"
@@ -43,7 +43,7 @@ func LoadConfig(name string) (*Config, error) {
4343
return nil, errors.Wrap(err, "failed to get config path")
4444
}
4545

46-
b, err := ioutil.ReadFile(configPath)
46+
b, err := os.ReadFile(configPath)
4747
if err != nil {
4848
return nil, errors.Errorf("error loading %s config file", name)
4949
}

0 commit comments

Comments
 (0)