Permalink
Browse files

many: fix ineffectal assignments of err

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 <zygmunt.krynicki@canonical.com>
  • Loading branch information...
1 parent 49e0d80 commit d6df05b0ca0d6727d624be3ccc3f9df364d0e221 @zyga zyga committed Nov 22, 2016
@@ -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()
@@ -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",
@@ -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"
@@ -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)
@@ -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},
@@ -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)
@@ -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",
View
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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
@@ -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:
@@ -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
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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
@@ -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@test.com", "macaroon", []string{"discharge2", "discharge1"})
+ c.Assert(err, IsNil)
as.state.Unlock()
expected := []string{"discharge1", "discharge2"}
@@ -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",
@@ -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)
@@ -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)
@@ -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)
@@ -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)
View
@@ -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)
@@ -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"))
@@ -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)
View
@@ -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()
@@ -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)
}

0 comments on commit d6df05b

Please sign in to comment.