Skip to content

Commit

Permalink
many: fix ineffectal assignments of err
Browse files Browse the repository at this point in the history
This patch corrects a number of issues that have the form of:

    err := ...
    c.Check(err, IsNil)
    ...
    err = ...
    // err is not used again

That is, the last assignment of err is never used again and in practice
the error is not checked.

Thanks to https://github.com/gordonklaus/ineffassign

Signed-off-by: Zygmunt Krynicki <[email protected]>
  • Loading branch information
zyga committed Nov 22, 2016
1 parent 49e0d80 commit d6df05b
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions asserts/account_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ func (aks *accountKeySuite) TestAccountKeyCheckSameAccountAndDifferentName(c *C)
newPubKey, err := db.PublicKey(newPrivKey.PublicKey().ID())
c.Assert(err, IsNil)
newPubKeyEncoded, err := asserts.EncodePublicKey(newPubKey)
c.Assert(err, IsNil)

headers["name"] = "another"
headers["public-key-sha3-384"] = newPubKey.ID()
Expand Down Expand Up @@ -432,6 +433,7 @@ func (aks *accountKeySuite) TestAccountKeyCheckSameNameAndDifferentAccount(c *C)
newPubKey, err := db.PublicKey(newPrivKey.PublicKey().ID())
c.Assert(err, IsNil)
newPubKeyEncoded, err := asserts.EncodePublicKey(newPubKey)
c.Assert(err, IsNil)

acct2 := assertstest.NewAccount(db, "acc-id2", map[string]interface{}{
"authority-id": "canonical",
Expand Down Expand Up @@ -475,6 +477,7 @@ func (aks *accountKeySuite) TestAccountKeyCheckNameClash(c *C) {
newPubKey, err := db.PublicKey(newPrivKey.PublicKey().ID())
c.Assert(err, IsNil)
newPubKeyEncoded, err := asserts.EncodePublicKey(newPubKey)
c.Assert(err, IsNil)

headers["public-key-sha3-384"] = newPubKey.ID()
headers["revision"] = "1"
Expand Down
1 change: 1 addition & 0 deletions asserts/asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ func (as *assertsSuite) TestSignFormatAndRevision(c *C) {
}

a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey1)
c.Assert(err, IsNil)

c.Check(a.Revision(), Equals, 11)
c.Check(a.Format(), Equals, 1)
Expand Down
1 change: 1 addition & 0 deletions asserts/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (opens *openSuite) TestOpenDatabaseTrustedWrongType(c *C) {
"primary-key": "0",
}
a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey0)
c.Assert(err, IsNil)

cfg := &asserts.DatabaseConfig{
Trusted: []asserts.Assertion{a},
Expand Down
1 change: 1 addition & 0 deletions asserts/snap_asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ AXNpZw==`
baseDecl := a.(*asserts.BaseDeclaration)
c.Check(baseDecl.Series(), Equals, "16")
ts, err := time.Parse(time.RFC3339, "2016-09-29T19:50:49Z")
c.Assert(err, IsNil)
c.Check(baseDecl.Timestamp().Equal(ts), Equals, true)

c.Check(baseDecl.PlugRule("interfaceX"), IsNil)
Expand Down
1 change: 1 addition & 0 deletions cmd/snap/cmd_delete_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *SnapKeysSuite) TestDeleteKey(c *C) {
c.Check(s.Stdout(), Equals, "")
c.Check(s.Stderr(), Equals, "")
_, err = snap.Parser().ParseArgs([]string{"keys", "--json"})
c.Assert(err, IsNil)
expectedResponse := []snap.Key{
snap.Key{
Name: "default",
Expand Down
2 changes: 2 additions & 0 deletions daemon/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4305,6 +4305,7 @@ func (s *postCreateUserSuite) TestPostCreateUserFromAssertion(c *check.C) {
st := s.d.overlord.State()
st.Lock()
users, err := auth.Users(st)
c.Assert(err, check.IsNil)
st.Unlock()
c.Check(users, check.HasLen, 1)
}
Expand Down Expand Up @@ -4359,6 +4360,7 @@ func (s *postCreateUserSuite) TestPostCreateUserFromAssertionAllKnown(c *check.C
st := s.d.overlord.State()
st.Lock()
users, err := auth.Users(st)
c.Assert(err, check.IsNil)
st.Unlock()
c.Check(users, check.HasLen, 2)
}
Expand Down
1 change: 1 addition & 0 deletions interfaces/apparmor/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ func (s *backendSuite) TestCombineSnippets(c *C) {
c.Assert(err, IsNil)
c.Check(string(data), Equals, scenario.content)
stat, err := os.Stat(profile)
c.Assert(err, IsNil)
c.Check(stat.Mode(), Equals, os.FileMode(0644))
s.RemoveSnap(c, snapInfo)
}
Expand Down
1 change: 1 addition & 0 deletions interfaces/dbus/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func (s *backendSuite) TestCombineSnippetsWithActualSnippets(c *C) {
c.Assert(err, IsNil)
c.Check(string(data), Equals, "<?xml>\n<policy>...</policy>\n</xml>")
stat, err := os.Stat(profile)
c.Assert(err, IsNil)
c.Check(stat.Mode(), Equals, os.FileMode(0644))
s.RemoveSnap(c, snapInfo)
}
Expand Down
4 changes: 4 additions & 0 deletions interfaces/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ slots:
// ResolveConnect detects lack of candidates
func (s *RepositorySuite) TestResolveConnectNoImplicitCandidates(c *C) {
err := s.testRepo.AddInterface(&TestInterface{InterfaceName: "other-interface"})
c.Assert(err, IsNil)
coreSnap := snaptest.MockInfo(c, `
name: core
type: os
Expand Down Expand Up @@ -1183,11 +1184,13 @@ func (s *AddRemoveSuite) TestAddSnapComplexErrorHandling(c *C) {
SanitizePlugCallback: func(plug *Plug) error { return fmt.Errorf("plug is invalid") },
SanitizeSlotCallback: func(slot *Slot) error { return fmt.Errorf("slot is invalid") },
})
c.Assert(err, IsNil)
err = s.repo.AddInterface(&TestInterface{
InterfaceName: "invalid-slot-iface",
SanitizePlugCallback: func(plug *Plug) error { return fmt.Errorf("plug is invalid") },
SanitizeSlotCallback: func(slot *Slot) error { return fmt.Errorf("slot is invalid") },
})
c.Assert(err, IsNil)
snapInfo := snaptest.MockInfo(c, `
name: complex
plugs:
Expand Down Expand Up @@ -1385,6 +1388,7 @@ func contentAutoConnect(plug *Plug, slot *Slot) bool {
func makeContentConnectionTestSnaps(c *C, plugContentToken, slotContentToken string) (*Repository, *snap.Info, *snap.Info) {
repo := NewRepository()
err := repo.AddInterface(&TestInterface{InterfaceName: "content", AutoConnectCallback: contentAutoConnect})
c.Assert(err, IsNil)

plugSnap := snaptest.MockInfo(c, fmt.Sprintf(`
name: content-plug-snap
Expand Down
1 change: 1 addition & 0 deletions interfaces/seccomp/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (s *backendSuite) TestCombineSnippets(c *C) {
c.Assert(err, IsNil)
c.Check(string(data), Equals, scenario.content)
stat, err := os.Stat(profile)
c.Assert(err, IsNil)
c.Check(stat.Mode(), Equals, os.FileMode(0644))
s.RemoveSnap(c, snapInfo)
}
Expand Down
3 changes: 3 additions & 0 deletions interfaces/udev/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (s *backendSuite) TestCombineSnippetsWithActualSnippets(c *C) {
c.Assert(err, IsNil)
c.Check(string(data), Equals, "# This file is automatically generated.\ndummy\n")
stat, err := os.Stat(fname)
c.Assert(err, IsNil)
c.Check(stat.Mode(), Equals, os.FileMode(0644))
s.RemoveSnap(c, snapInfo)
}
Expand All @@ -284,6 +285,7 @@ func (s *backendSuite) TestCombineSnippetsWithActualSnippetsWhenPlugNoApps(c *C)
c.Assert(err, IsNil)
c.Check(string(data), Equals, "# This file is automatically generated.\ndummy\n")
stat, err := os.Stat(fname)
c.Assert(err, IsNil)
c.Check(stat.Mode(), Equals, os.FileMode(0644))
s.RemoveSnap(c, snapInfo)
}
Expand All @@ -301,6 +303,7 @@ func (s *backendSuite) TestCombineSnippetsWithActualSnippetsWhenSlotNoApps(c *C)
c.Assert(err, IsNil)
c.Check(string(data), Equals, "# This file is automatically generated.\ndummy\n")
stat, err := os.Stat(fname)
c.Assert(err, IsNil)
c.Check(stat.Mode(), Equals, os.FileMode(0644))
s.RemoveSnap(c, snapInfo)
}
Expand Down
1 change: 1 addition & 0 deletions osutil/exitcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (ts *ExitCodeTestSuite) TestExitCode(c *C) {
cmd = exec.Command("sh", "-c", "exit 7")
err = cmd.Run()
e, err = ExitCode(err)
c.Assert(err, IsNil)
c.Assert(e, Equals, 7)

// ensure that non exec.ExitError values give a error
Expand Down
1 change: 1 addition & 0 deletions overlord/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (as *authSuite) TestNewUser(c *C) {
func (as *authSuite) TestNewUserSortsDischarges(c *C) {
as.state.Lock()
user, err := auth.NewUser(as.state, "", "[email protected]", "macaroon", []string{"discharge2", "discharge1"})
c.Assert(err, IsNil)
as.state.Unlock()

expected := []string{"discharge1", "discharge2"}
Expand Down
1 change: 1 addition & 0 deletions overlord/devicestate/devicemgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ func (s *deviceMgrSuite) TestDeviceAssertionsDeviceSessionRequest(c *C) {
s.state.Lock()
devKey, _ := assertstest.GenerateKey(1024)
encDevKey, err := asserts.EncodePublicKey(devKey.PublicKey())
c.Check(err, IsNil)
seriala, err := s.storeSigning.Sign(asserts.SerialType, map[string]interface{}{
"brand-id": "canonical",
"model": "pc",
Expand Down
1 change: 1 addition & 0 deletions overlord/devicestate/firstboot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ snaps:
defer st.Unlock()

tsAll, err := devicestate.PopulateStateFromSeedImpl(st)
c.Assert(err, IsNil)
chg := st.NewChange("run-it", "run the populate from seed changes")
for _, ts := range tsAll {
chg.AddAll(ts)
Expand Down
2 changes: 2 additions & 0 deletions overlord/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ func (ss *stateSuite) TestNewChangeAndCheckpoint(c *C) {

var v int
err = chg0.Get("a", &v)
c.Check(err, IsNil)
c.Check(v, Equals, 1)

c.Check(chg0.Status(), Equals, state.ErrorStatus)
Expand Down Expand Up @@ -434,6 +435,7 @@ func (ss *stateSuite) TestNewTaskAndCheckpoint(c *C) {

var v int
err = task0_1.Get("a", &v)
c.Check(err, IsNil)
c.Check(v, Equals, 1)

c.Check(task0_1.Status(), Equals, state.DoneStatus)
Expand Down
1 change: 1 addition & 0 deletions partition/bootloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (s *PartitionTestSuite) TestInstallBootloaderConfig(c *C) {
} {
mockGadgetDir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(mockGadgetDir, t.gadgetFile), nil, 0644)
c.Assert(err, IsNil)
err = InstallBootConfig(mockGadgetDir)
c.Assert(err, IsNil)
fn := filepath.Join(dirs.GlobalRootDir, t.systemFile)
Expand Down
1 change: 1 addition & 0 deletions snap/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func makeTestSnap(c *C, yaml string) string {
snapSource := filepath.Join(tmp, "snapsrc")

err := os.MkdirAll(filepath.Join(snapSource, "meta"), 0755)
c.Assert(err, IsNil)

// our regular snap.yaml
err = ioutil.WriteFile(filepath.Join(snapSource, "meta", "snap.yaml"), []byte(yaml), 0644)
Expand Down
2 changes: 2 additions & 0 deletions snap/snaptest/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ printf "hello world"
err = ioutil.WriteFile(someFile, []byte(""), 0666)
c.Assert(err, IsNil)
err = os.Chmod(someFile, 0666)
c.Assert(err, IsNil)

// an example symlink
err = os.Symlink("bin/hello-world", filepath.Join(tempdir, "symlink"))
Expand Down Expand Up @@ -260,6 +261,7 @@ integration:
outputDir := filepath.Join(c.MkDir(), "output")
snapOutput := filepath.Join(outputDir, "hello_1.0.1_multi.snap")
resultSnap, err := snaptest.BuildSquashfsSnap(sourceDir, outputDir)
c.Assert(err, IsNil)

// check that there is result
_, err = os.Stat(resultSnap)
Expand Down
2 changes: 2 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ func (t *remoteRepoTestSuite) TestUbuntuStoreRepositoryRevision(c *C) {
defer mockPurchasesServer.Close()

ordersURI, err := url.Parse(mockPurchasesServer.URL + ordersPath)
c.Assert(err, IsNil)
detailsURI, err := url.Parse(mockServer.URL + "/details/")
c.Assert(err, IsNil)
cfg := DefaultConfig()
Expand Down Expand Up @@ -2673,6 +2674,7 @@ func (t *remoteRepoTestSuite) TestUbuntuStoreRepositoryAssertion500(c *C) {
repo := New(&cfg, nil)

_, err = repo.Assertion(asserts.SnapDeclarationType, []string{"16", "snapidfoo"}, nil)
c.Assert(err, ErrorMatches, `cannot fetch assertion: got unexpected HTTP status code 500 via .+`)
c.Assert(n, Equals, 6)
}

Expand Down

0 comments on commit d6df05b

Please sign in to comment.