Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
This commit fixes the linter errors popping up in
#1400
to unblock this PR, to allow rebase other branches
to master without getting stuck on linter errors.

Details of changes
* add missing error-return-check
* remove references to deprecated ioutil package
  • Loading branch information
gargnitingoogle committed Sep 29, 2023
1 parent 66b8100 commit 76bf68d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
3 changes: 2 additions & 1 deletion internal/gcsx/append_object_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ func (t *AppendObjectCreatorTest) CallsComposeObjectsWithObjectProperties() {
WillOnce(Return(nil))

// Call
t.call()
_, err := t.call()
ExpectEq(nil, err)

AssertNe(nil, req)
ExpectEq(t.srcObject.Name, req.DstName)
Expand Down
11 changes: 8 additions & 3 deletions internal/monitor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ func EnableOpenTelemetryCollectorExporter(address string) error {

// CloseOpenTelemetryCollectorExporter ensures all collected metrics are sent to
// the OpenTelemetry Collect and closes the exporter.
func CloseOpenTelemetryCollectorExporter() {
func CloseOpenTelemetryCollectorExporter() error {
if ocExporter != nil {
ocExporter.Stop()
if err := ocExporter.Stop(); err != nil {
return fmt.Errorf("failed to stop opencensus-exporter: %w", err)
}

ocExporter.Flush()
ocExporter = nil
}
ocExporter = nil

return nil
}
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,14 @@ func runCLIApp(c *cli.Context) (err error) {

// Wait for the file system to be unmounted.
err = mfs.Join(context.Background())
if err != nil {
return fmt.Errorf("failed MountedFileSystem.Join: %w", err)
}

monitor.CloseStackdriverExporter()
monitor.CloseOpenTelemetryCollectorExporter()

if err != nil {
err = fmt.Errorf("MountedFileSystem.Join: %w", err)
return
if err := monitor.CloseOpenTelemetryCollectorExporter(); err != nil {
return fmt.Errorf("failed to close open-telemetry collector exporter: %w", err)
}

return
Expand Down
4 changes: 3 additions & 1 deletion tools/integration_tests/mounting/gcsfuse_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (t *GcsfuseTest) Statfs() {

err = t.runGcsfuse(args)
AssertEq(nil, err)
defer util.Unmount(t.dir)
defer func() {
AssertEq(nil, util.Unmount(t.dir))
}()

// Stat the file system.
err = syscall.Statfs(t.dir, &stat)
Expand Down
30 changes: 17 additions & 13 deletions tools/integration_tests/mounting/gcsfuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ package integration_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
//"runtime"
"syscall"
"testing"
"time"
Expand Down Expand Up @@ -156,7 +154,7 @@ func (t *GcsfuseTest) NonEmptyMountPoint() {
// Write a file into the mount point.
p := path.Join(t.dir, "foo")
err = ioutil.WriteFile(p, nil, 0600)
err = os.WriteFile(p, nil, 0600)
AssertEq(nil, err)
defer os.Remove(p)
Expand All @@ -175,7 +173,7 @@ func (t *GcsfuseTest) MountPointIsAFile() {
// Write a file.
p := path.Join(t.dir, "foo")

err = ioutil.WriteFile(p, []byte{}, 0500)
err = os.WriteFile(p, []byte{}, 0500)
AssertEq(nil, err)
defer os.Remove(p)

Expand Down Expand Up @@ -216,11 +214,11 @@ func (t *GcsfuseTest) KeyFile() {
cmd := t.gcsfuseCommand(args, tc.env)

output, err := cmd.CombinedOutput()
util.Unmount(t.dir)

ExpectThat(err, Error(HasSubstr("exit status")), "case %d", i)
ExpectThat(string(output), HasSubstr(nonexistent), "case %d", i)
ExpectThat(string(output), HasSubstr("no such file"), "case %d", i)

ExpectEq(nil, util.Unmount(t.dir))
}
}

Expand All @@ -233,14 +231,16 @@ func (t *GcsfuseTest) CannedContents() {

err = t.runGcsfuse(args)
AssertEq(nil, err)
defer util.Unmount(t.dir)
defer func() {
ExpectEq(nil, util.Unmount(t.dir))
}()

// Check the expected contents of the file system.
fi, err = os.Lstat(path.Join(t.dir, canned.TopLevelFile))
AssertEq(nil, err)
ExpectEq(os.FileMode(0644), fi.Mode())

contents, err := ioutil.ReadFile(path.Join(t.dir, canned.TopLevelFile))
contents, err := os.ReadFile(path.Join(t.dir, canned.TopLevelFile))
AssertEq(nil, err)
ExpectEq(canned.TopLevelFile_Contents, string(contents))

Expand All @@ -265,7 +265,7 @@ func (t *GcsfuseTest) ReadOnlyMode() {
defer util.Unmount(t.dir)

// Writing to the file system should fail.
err = ioutil.WriteFile(path.Join(t.dir, "blah"), []byte{}, 0400)
err = os.WriteFile(path.Join(t.dir, "blah"), []byte{}, 0400)
ExpectThat(err, Error(HasSubstr("read-only")))
}

Expand All @@ -282,10 +282,10 @@ func (t *GcsfuseTest) ReadWriteMode() {
// Overwrite the canned file.
p := path.Join(t.dir, canned.TopLevelFile)

err = ioutil.WriteFile(p, []byte("enchilada"), 0400)
err = os.WriteFile(p, []byte("enchilada"), 0400)
AssertEq(nil, err)

contents, err := ioutil.ReadFile(p)
contents, err := os.ReadFile(p)
AssertEq(nil, err)
ExpectEq("enchilada", string(contents))
}
Expand Down Expand Up @@ -491,8 +491,12 @@ func (t *GcsfuseTest) ForegroundMode() {

err = cmd.Start()
AssertEq(nil, err)
defer cmd.Wait()
defer cmd.Process.Kill()
defer func() {
ExpectEq(nil, cmd.Wait())
}()
defer func() {
ExpectEq(nil, cmd.Process.Kill())
}()

// Accumulate output from stderr until we see a successful mount message,
// hackily synchronizing. Yes, this is an O(n^2) loop.
Expand Down
7 changes: 3 additions & 4 deletions tools/integration_tests/mounting/mount_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package integration_test

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -66,7 +65,7 @@ func (t *MountHelperTest) SetUp(_ *TestInfo) {
}

// Set up the temporary directory.
t.dir, err = ioutil.TempDir("", "mount_helper_test")
t.dir, err = os.MkdirTemp("", "mount_helper_test")
AssertEq(nil, err)
}

Expand Down Expand Up @@ -199,7 +198,7 @@ func (t *MountHelperTest) ReadOnlyMode() {
defer util.Unmount(t.dir)

// Writing to the file system should fail.
err = ioutil.WriteFile(path.Join(t.dir, "blah"), []byte{}, 0400)
err = os.WriteFile(path.Join(t.dir, "blah"), []byte{}, 0400)
ExpectThat(err, Error(HasSubstr("read-only")))
}

Expand Down Expand Up @@ -236,7 +235,7 @@ func (t *MountHelperTest) LinuxArgumentOrder() {
defer util.Unmount(t.dir)

// Writing to the file system should fail.
err = ioutil.WriteFile(path.Join(t.dir, "blah"), []byte{}, 0400)
err = os.WriteFile(path.Join(t.dir, "blah"), []byte{}, 0400)
ExpectThat(err, Error(HasSubstr("read-only")))
}

Expand Down

0 comments on commit 76bf68d

Please sign in to comment.