Skip to content

Commit 78b4870

Browse files
committed
Fix more lint errors in previously unlinted code
These changes mainly involved: - adding error checks where they were needed (or explicitly ignoring an error return value with _) - removing unused methods/fields/variables - in a couple of places, adding "//nolint" comments (may be addressed later) [#172389465] Authored-by: Reid Mitchell <[email protected]>
1 parent 6d68a19 commit 78b4870

26 files changed

+117
-167
lines changed

actor/v2action/buildpack_unix_test.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ var _ = Describe("Buildpack", func() {
3838
source, err = ioutil.TempDir("", "zipit-source-")
3939
Expect(err).ToNot(HaveOccurred())
4040

41-
ioutil.WriteFile(filepath.Join(source, "file1"), []byte{}, 0700)
42-
ioutil.WriteFile(filepath.Join(source, "file2"), []byte{}, 0644)
41+
err = ioutil.WriteFile(filepath.Join(source, "file1"), []byte{}, 0700)
42+
Expect(err).ToNot(HaveOccurred())
43+
44+
err = ioutil.WriteFile(filepath.Join(source, "file2"), []byte{}, 0644)
45+
Expect(err).ToNot(HaveOccurred())
46+
4347
subDir, err = ioutil.TempDir(source, "zipit-subdir-")
4448
Expect(err).ToNot(HaveOccurred())
45-
ioutil.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0755)
49+
50+
err = ioutil.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0755)
51+
Expect(err).ToNot(HaveOccurred())
4652

4753
p := filepath.FromSlash(fmt.Sprintf("buildpack-%s.zip", helpers.RandomName()))
4854
target, err = filepath.Abs(p)
@@ -60,7 +66,7 @@ var _ = Describe("Buildpack", func() {
6066
Expect(err).ToNot(HaveOccurred())
6167
defer zipFile.Close()
6268

63-
zipStat, err := zipFile.Stat()
69+
zipStat, _ := zipFile.Stat()
6470
reader, err := ykk.NewReader(zipFile, zipStat.Size())
6571
Expect(err).ToNot(HaveOccurred())
6672

actor/v2action/logging_test.go

-22
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"code.cloudfoundry.org/cli/integration/helpers"
1515
logcache "code.cloudfoundry.org/go-log-cache"
1616
"code.cloudfoundry.org/go-loggregator/rpc/loggregator_v2"
17-
"github.com/cloudfoundry/sonde-go/events"
1817
. "github.com/onsi/ginkgo"
1918
. "github.com/onsi/gomega"
2019
)
@@ -189,27 +188,6 @@ var _ = Describe("Logging Actions", func() {
189188

190189
When("LogCache returns logs", func() {
191190
BeforeEach(func() {
192-
outMessage := events.LogMessage_OUT
193-
ts1 := int64(10)
194-
ts2 := int64(20)
195-
sourceType := "some-source-type"
196-
sourceInstance := "some-source-instance"
197-
198-
var messages []*events.LogMessage
199-
messages = append(messages, &events.LogMessage{
200-
Message: []byte("message-2"),
201-
MessageType: &outMessage,
202-
Timestamp: &ts2,
203-
SourceType: &sourceType,
204-
SourceInstance: &sourceInstance,
205-
})
206-
messages = append(messages, &events.LogMessage{
207-
Message: []byte("message-1"),
208-
MessageType: &outMessage,
209-
Timestamp: &ts1,
210-
SourceType: &sourceType,
211-
SourceInstance: &sourceInstance,
212-
})
213191
fakeConfig.DialTimeoutReturns(60 * time.Minute)
214192

215193
fakeLogCacheClient.ReadReturns([]*loggregator_v2.Envelope{{

actor/v2action/v2action_suite_test.go

+3-70
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
package v2action_test
22

33
import (
4-
"archive/zip"
5-
"io"
6-
"os"
7-
"path/filepath"
8-
"strings"
4+
"testing"
95
"time"
106

7+
. "code.cloudfoundry.org/cli/actor/v2action"
8+
"code.cloudfoundry.org/cli/actor/v2action/v2actionfakes"
119
. "github.com/onsi/ginkgo"
1210
. "github.com/onsi/gomega"
13-
14-
"testing"
15-
1611
log "github.com/sirupsen/logrus"
17-
18-
. "code.cloudfoundry.org/cli/actor/v2action"
19-
"code.cloudfoundry.org/cli/actor/v2action/v2actionfakes"
2012
)
2113

2214
func TestV2Action(t *testing.T) {
@@ -37,62 +29,3 @@ func NewTestActor() (*Actor, *v2actionfakes.FakeCloudControllerClient, *v2action
3729

3830
return actor, fakeCloudControllerClient, fakeUAAClient, fakeConfig
3931
}
40-
41-
// Thanks to Svett Ralchev
42-
// http://blog.ralch.com/tutorial/golang-working-with-zip/
43-
func zipit(source, target, prefix string) error {
44-
zipfile, err := os.Create(target)
45-
if err != nil {
46-
return err
47-
}
48-
defer zipfile.Close()
49-
50-
if prefix != "" {
51-
_, err = io.WriteString(zipfile, prefix)
52-
if err != nil {
53-
return err
54-
}
55-
}
56-
57-
archive := zip.NewWriter(zipfile)
58-
defer archive.Close()
59-
60-
err = filepath.Walk(source, func(path string, info os.FileInfo, err error) error {
61-
if err != nil {
62-
return err
63-
}
64-
65-
header, err := zip.FileInfoHeader(info)
66-
if err != nil {
67-
return err
68-
}
69-
70-
header.Name = strings.TrimPrefix(path, source)
71-
72-
if info.IsDir() {
73-
header.Name += string(os.PathSeparator)
74-
} else {
75-
header.Method = zip.Deflate
76-
}
77-
78-
writer, err := archive.CreateHeader(header)
79-
if err != nil {
80-
return err
81-
}
82-
83-
if info.IsDir() {
84-
return nil
85-
}
86-
87-
file, err := os.Open(path)
88-
if err != nil {
89-
return err
90-
}
91-
defer file.Close()
92-
93-
_, err = io.Copy(writer, file)
94-
return err
95-
})
96-
97-
return err
98-
}

actor/v3action/application_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ var _ = Describe("Application Actions", func() {
552552
})
553553

554554
It("gets polling and timeout values from the config", func() {
555-
actor.PollStart("some-guid", warningsChannel)
555+
err := actor.PollStart("some-guid", warningsChannel)
556+
Expect(err).To(MatchError(actionerror.StartupTimeoutError{}))
556557
funcDone <- nil
557558

558559
Expect(fakeConfig.StartupTimeoutCallCount()).To(Equal(1))

actor/v3action/package_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ var _ = Describe("Package Actions", func() {
580580
Expect(bitsPathFile.Close()).To(Succeed())
581581
bitsPath = bitsPathFile.Name()
582582

583-
zipit(tempFilePath, bitsPath, "")
583+
err = zipit(tempFilePath, bitsPath, "")
584+
Expect(err).ToNot(HaveOccurred())
584585
Expect(os.Remove(tempFilePath)).To(Succeed())
585586
})
586587

@@ -682,7 +683,8 @@ var _ = Describe("Package Actions", func() {
682683
Expect(archivePathFile.Close()).To(Succeed())
683684
archivePath = archivePathFile.Name()
684685

685-
zipit(tempArchiveFilePath, archivePath, "")
686+
err = zipit(tempArchiveFilePath, archivePath, "")
687+
Expect(err).ToNot(HaveOccurred())
686688
Expect(os.Remove(tempArchiveFilePath)).To(Succeed())
687689

688690
tempFile, err := ioutil.TempFile("", "example-file-")

actor/v3action/zdt_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,12 @@ var _ = Describe("v3-zdt-push", func() {
305305
})
306306

307307
It("gets polling and timeout values from the config", func() {
308-
actor.ZeroDowntimePollStart("some-guid", warningsChannel)
308+
err := actor.ZeroDowntimePollStart("some-guid", warningsChannel)
309309
funcDone <- nil
310310

311311
Expect(fakeConfig.StartupTimeoutCallCount()).To(Equal(1))
312312
Expect(fakeConfig.PollingIntervalCallCount()).To(Equal(1))
313+
Expect(err).To(MatchError(actionerror.StartupTimeoutError{}))
313314
})
314315
})
315316

api/cloudcontroller/ccv2/client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var _ = Describe("Cloud Controller Client", func() {
3434
client.WrapConnection(fakeConnectionWrapper)
3535
Expect(fakeConnectionWrapper.WrapCallCount()).To(Equal(1))
3636

37-
client.DeleteServiceBinding("does-not-matter", true)
37+
_, _, _ = client.DeleteServiceBinding("does-not-matter", true)
3838
Expect(fakeConnectionWrapper.MakeCallCount()).To(Equal(1))
3939
})
4040
})
@@ -52,7 +52,7 @@ var _ = Describe("Cloud Controller Client", func() {
5252
})
5353

5454
It("adds a user agent header", func() {
55-
client.GetApplications()
55+
_, _, _ = client.GetApplications()
5656
Expect(server.ReceivedRequests()).To(HaveLen(2))
5757
})
5858
})

api/cloudcontroller/ccv2/domain.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,16 @@ func (client *Client) CreateSharedDomain(domainName string, routerGroupdGUID str
7070
RouterGroupGUID: routerGroupdGUID,
7171
Internal: isInternal,
7272
}
73+
7374
bodyBytes, err := json.Marshal(body)
75+
if err != nil {
76+
return nil, err
77+
}
78+
7479
request, err := client.newHTTPRequest(requestOptions{
7580
RequestName: internal.PostSharedDomainRequest,
7681
Body: bytes.NewReader(bodyBytes),
7782
})
78-
7983
if err != nil {
8084
return nil, err
8185
}

api/cloudcontroller/ccv2/domain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ var _ = Describe("Domain", func() {
599599
),
600600
)
601601

602-
client.GetOrganizationPrivateDomains("some-org-guid", Filter{
602+
_, _, _ = client.GetOrganizationPrivateDomains("some-org-guid", Filter{
603603
Type: constant.NameFilter,
604604
Operator: constant.EqualOperator,
605605
Values: []string{"private-domain-name"},

api/cloudcontroller/ccv2/job_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ var _ = Describe("Job", func() {
617617
Expect(ioutil.ReadAll(resourcesPart)).To(MatchJSON(expectedJSON))
618618

619619
// Verify that the application bits are not sent
620-
resourcesPart, err = requestReader.NextPart()
620+
_, err = requestReader.NextPart()
621621
Expect(err).To(MatchError(io.EOF))
622622
}
623623

api/cloudcontroller/ccv2/route.go

-24
Original file line numberDiff line numberDiff line change
@@ -298,27 +298,3 @@ func (client *Client) UpdateRouteApplication(routeGUID string, appGUID string) (
298298

299299
return route, response.Warnings, err
300300
}
301-
302-
func (client *Client) checkRouteDeprecated(domainGUID string, host string, path string) (bool, Warnings, error) {
303-
request, err := client.newHTTPRequest(requestOptions{
304-
RequestName: internal.GetRouteReservedDeprecatedRequest,
305-
URIParams: map[string]string{"domain_guid": domainGUID, "host": host},
306-
})
307-
if err != nil {
308-
return false, nil, err
309-
}
310-
311-
queryParams := url.Values{}
312-
if path != "" {
313-
queryParams.Add("path", path)
314-
}
315-
request.URL.RawQuery = queryParams.Encode()
316-
317-
var response cloudcontroller.Response
318-
err = client.connection.Make(request, &response)
319-
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
320-
return false, response.Warnings, nil
321-
}
322-
323-
return response.HTTPResponse.StatusCode == http.StatusNoContent, response.Warnings, err
324-
}

api/plugin/client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var _ = Describe("Plugin Client", func() {
3131
client.WrapConnection(fakeConnectionWrapper)
3232
Expect(fakeConnectionWrapper.WrapCallCount()).To(Equal(1))
3333

34-
client.GetPluginRepository("does-not-matter")
34+
_, _ = client.GetPluginRepository("does-not-matter")
3535
Expect(fakeConnectionWrapper.MakeCallCount()).To(Equal(1))
3636
})
3737
})
@@ -48,7 +48,7 @@ var _ = Describe("Plugin Client", func() {
4848
})
4949

5050
It("adds a user agent header", func() {
51-
client.GetPluginRepository(server.URL())
51+
_, _ = client.GetPluginRepository(server.URL())
5252
Expect(server.ReceivedRequests()).To(HaveLen(1))
5353
})
5454
})

api/plugin/plugin_connection.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// PluginConnection represents a connection to a plugin repo.
1919
type PluginConnection struct {
2020
HTTPClient *http.Client
21-
proxyReader ProxyReader
21+
proxyReader ProxyReader // nolint
2222
}
2323

2424
// NewConnection returns a new PluginConnection

api/router/client.go

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
// Client is a client that can be used to talk to a Cloud Controller's V2
1414
// Endpoints.
1515
type Client struct {
16-
routerGroupEndpoint string
17-
1816
connection Connection
1917
router *rata.RequestGenerator
2018
userAgent string

integration/v6/experimental/v3_delete_command_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ var _ = Describe("v3-delete command", func() {
137137

138138
When("the user enters 'y'", func() {
139139
BeforeEach(func() {
140-
buffer.Write([]byte("y\n"))
140+
_, err := buffer.Write([]byte("y\n"))
141+
Expect(err).NotTo(HaveOccurred())
141142
})
142143

143144
It("it displays the app does not exist", func() {
@@ -153,7 +154,8 @@ var _ = Describe("v3-delete command", func() {
153154

154155
When("the user enters 'n'", func() {
155156
BeforeEach(func() {
156-
buffer.Write([]byte("n\n"))
157+
_, err := buffer.Write([]byte("n\n"))
158+
Expect(err).NotTo(HaveOccurred())
157159
})
158160

159161
It("does not delete the app", func() {
@@ -166,7 +168,8 @@ var _ = Describe("v3-delete command", func() {
166168

167169
When("the user enters the default input (hits return)", func() {
168170
BeforeEach(func() {
169-
buffer.Write([]byte("\n"))
171+
_, err := buffer.Write([]byte("\n"))
172+
Expect(err).NotTo(HaveOccurred())
170173
})
171174

172175
It("does not delete the app", func() {
@@ -182,7 +185,8 @@ var _ = Describe("v3-delete command", func() {
182185
// The second '\n' is intentional. Otherwise the buffer will be
183186
// closed while the interaction is still waiting for input; it gets
184187
// an EOF and causes an error.
185-
buffer.Write([]byte("wat\n\n"))
188+
_, err := buffer.Write([]byte("wat\n\n"))
189+
Expect(err).NotTo(HaveOccurred())
186190
})
187191

188192
It("asks again", func() {

0 commit comments

Comments
 (0)