Skip to content

Commit

Permalink
many: rename more vars
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Pires <[email protected]>
  • Loading branch information
miguelpires committed Dec 4, 2024
1 parent 5e2b518 commit b9ba8ba
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 73 deletions.
8 changes: 4 additions & 4 deletions overlord/assertstate/assertstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func AutoRefreshAssertions(s *state.State, userID int) error {
// confdb assertions.
func autoRefreshConfdbAssertions(st *state.State, userID int, opts *RefreshAssertionsOptions) error {
db := cachedDB(st)
regAsserts, err := db.FindMany(asserts.ConfdbType, nil)
confdbAsserts, err := db.FindMany(asserts.ConfdbType, nil)
if err != nil {
if errors.Is(err, &asserts.NotFoundError{}) {
return nil
Expand All @@ -406,9 +406,9 @@ func autoRefreshConfdbAssertions(st *state.State, userID int, opts *RefreshAsser
}

var confdbs []*confdb.Confdb
for _, regAs := range regAsserts {
reg := regAs.(*asserts.Confdb).Confdb()
confdbs = append(confdbs, reg)
for _, dbAs := range confdbAsserts {
confdb := dbAs.(*asserts.Confdb).Confdb()
confdbs = append(confdbs, confdb)
}

return refreshConfdbAssertions(st, confdbs, userID, opts)
Expand Down
22 changes: 11 additions & 11 deletions overlord/assertstate/assertstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5580,8 +5580,8 @@ func (s *assertMgrSuite) setupConfdb(c *C) *snap.SideInfo {
}
}
}`
regAs := s.confdb(c, "my-confdb", extraHeaders, schema)
err := s.storeSigning.Add(regAs)
confdbAs := s.confdb(c, "my-confdb", extraHeaders, schema)
err := s.storeSigning.Add(confdbAs)
c.Assert(err, IsNil)

si := &snap.SideInfo{
Expand Down Expand Up @@ -5632,12 +5632,12 @@ func (s *assertMgrSuite) TestFetchConfdbAssertion(c *C) {

c.Assert(chg.Err(), IsNil)

reg, err := assertstate.DB(s.state).Find(asserts.ConfdbType, map[string]string{
confdb, err := assertstate.DB(s.state).Find(asserts.ConfdbType, map[string]string{
"account-id": s.dev1Acct.AccountID(),
"name": "my-confdb",
})
c.Assert(err, IsNil)
c.Check(reg, NotNil)
c.Check(confdb, NotNil)

// store assertion was also fetched
_, err = assertstate.DB(s.state).Find(asserts.StoreType, map[string]string{
Expand Down Expand Up @@ -5691,29 +5691,29 @@ func (s *assertMgrSuite) testConfdbAssertionsAutoRefresh(c *C) {
}
}
}`
regAs := s.confdb(c, "my-confdb", extraHeaders, schema)
err = s.storeSigning.Add(regAs)
confdbAs := s.confdb(c, "my-confdb", extraHeaders, schema)
err = s.storeSigning.Add(confdbAs)
c.Assert(err, IsNil)

// store revision 1 of the confdb assertion locally
for _, as := range []asserts.Assertion{s.storeSigning.StoreAccountKey(""), s.dev1Acct, s.dev1AcctKey, regAs} {
for _, as := range []asserts.Assertion{s.storeSigning.StoreAccountKey(""), s.dev1Acct, s.dev1AcctKey, confdbAs} {
err = assertstate.Add(s.state, as)
c.Assert(err, IsNil)
}

// precondition check
c.Assert(assertstate.AutoRefreshAssertions(s.state, 0), IsNil)
db := assertstate.DB(s.state)
reg, err := db.Find(asserts.ConfdbType, map[string]string{
confdb, err := db.Find(asserts.ConfdbType, map[string]string{
"account-id": s.dev1Acct.AccountID(),
"name": "my-confdb",
})
c.Assert(err, IsNil)
c.Check(reg.Revision(), Equals, 1)
c.Check(confdb.Revision(), Equals, 1)

extraHeaders["revision"] = "2"
regAs = s.confdb(c, "my-confdb", extraHeaders, schema)
err = s.storeSigning.Add(regAs)
confdbAs = s.confdb(c, "my-confdb", extraHeaders, schema)
err = s.storeSigning.Add(confdbAs)
c.Assert(err, IsNil)

// auto-refresh should obtain revision 2
Expand Down
24 changes: 12 additions & 12 deletions overlord/confdbstate/confdbmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (s *hookHandlerSuite) SetUpTest(c *C) {
s.repo = interfaces.NewRepository()
ifacerepo.Replace(s.state, s.repo)

regIface := &ifacetest.TestInterface{InterfaceName: "confdb"}
err := s.repo.AddInterface(regIface)
confdbIface := &ifacetest.TestInterface{InterfaceName: "confdb"}
err := s.repo.AddInterface(confdbIface)
c.Assert(err, IsNil)

const coreYaml = `name: core
Expand Down Expand Up @@ -363,39 +363,39 @@ func (s *confdbTestSuite) TestSetAndUnsetOngoingTransactionHelpers(c *C) {
err := s.state.Get("confdb-commit-tasks", &commitTasks)
c.Assert(err, testutil.ErrorIs, &state.NoStateError{})

err = confdbstate.SetOngoingTransaction(s.state, "my-acc", "my-reg", "1")
err = confdbstate.SetOngoingTransaction(s.state, "my-acc", "my-confdb", "1")
c.Assert(err, IsNil)

// can't overwrite an ongoing commit task, since that could hide errors
err = confdbstate.SetOngoingTransaction(s.state, "my-acc", "my-reg", "3")
c.Assert(err, ErrorMatches, `internal error: cannot set task "3" as ongoing commit task for confdb my-acc/my-reg: already have "1"`)
err = confdbstate.SetOngoingTransaction(s.state, "my-acc", "my-confdb", "3")
c.Assert(err, ErrorMatches, `internal error: cannot set task "3" as ongoing commit task for confdb my-acc/my-confdb: already have "1"`)

err = confdbstate.SetOngoingTransaction(s.state, "other-acc", "other-reg", "2")
err = confdbstate.SetOngoingTransaction(s.state, "other-acc", "other-confdb", "2")
c.Assert(err, IsNil)

err = s.state.Get("confdb-commit-tasks", &commitTasks)
c.Assert(err, IsNil)
c.Assert(commitTasks["my-acc/my-reg"], Equals, "1")
c.Assert(commitTasks["my-acc/my-confdb"], Equals, "1")

err = confdbstate.UnsetOngoingTransaction(s.state, "my-acc", "my-reg")
err = confdbstate.UnsetOngoingTransaction(s.state, "my-acc", "my-confdb")
c.Assert(err, IsNil)

// unsetting non-existing key is fine
err = confdbstate.UnsetOngoingTransaction(s.state, "my-acc", "my-reg")
err = confdbstate.UnsetOngoingTransaction(s.state, "my-acc", "my-confdb")
c.Assert(err, IsNil)

err = s.state.Get("confdb-commit-tasks", &commitTasks)
c.Assert(err, IsNil)
c.Assert(commitTasks["other-acc/other-reg"], Equals, "2")
c.Assert(commitTasks["other-acc/other-confdb"], Equals, "2")

err = confdbstate.UnsetOngoingTransaction(s.state, "other-acc", "other-reg")
err = confdbstate.UnsetOngoingTransaction(s.state, "other-acc", "other-confdb")
c.Assert(err, IsNil)

err = s.state.Get("confdb-commit-tasks", &commitTasks)
c.Assert(err, testutil.ErrorIs, &state.NoStateError{})

// unsetting non-existing key is still fine when there's no map at all
err = confdbstate.UnsetOngoingTransaction(s.state, "my-acc", "my-reg")
err = confdbstate.UnsetOngoingTransaction(s.state, "my-acc", "my-confdb")
c.Assert(err, IsNil)
}

Expand Down
24 changes: 12 additions & 12 deletions overlord/confdbstate/confdbstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func mockInstalledSnap(c *C, st *state.State, snapYaml string, hooks []string) *
}

func (s *confdbTestSuite) TestPlugsAffectedByPaths(c *C) {
reg, err := confdb.New(s.devAccID, "reg", map[string]interface{}{
confdb, err := confdb.New(s.devAccID, "confdb", map[string]interface{}{
// exact match
"view-1": map[string]interface{}{
"rules": []interface{}{
Expand Down Expand Up @@ -397,8 +397,8 @@ func (s *confdbTestSuite) TestPlugsAffectedByPaths(c *C) {
defer s.state.Unlock()
ifacerepo.Replace(s.state, repo)

regIface := &ifacetest.TestInterface{InterfaceName: "confdb"}
err = repo.AddInterface(regIface)
confdbIface := &ifacetest.TestInterface{InterfaceName: "confdb"}
err = repo.AddInterface(confdbIface)
c.Assert(err, IsNil)

snapYaml := fmt.Sprintf(`name: test-snap
Expand All @@ -408,19 +408,19 @@ plugs:
view-1:
interface: confdb
account: %[1]s
view: reg/view-1
view: confdb/view-1
view-2:
interface: confdb
account: %[1]s
view: reg/view-2
view: confdb/view-2
view-3:
interface: confdb
account: %[1]s
view: reg/view-3
view: confdb/view-3
view-4:
interface: confdb
account: %[1]s
view: reg/view-4
view: confdb/view-4
`, s.devAccID)
info := mockInstalledSnap(c, s.state, snapYaml, nil)

Expand Down Expand Up @@ -453,7 +453,7 @@ slots:
c.Assert(err, IsNil)
}

snapPlugs, err := confdbstate.GetPlugsAffectedByPaths(s.state, reg, []string{"foo"})
snapPlugs, err := confdbstate.GetPlugsAffectedByPaths(s.state, confdb, []string{"foo"})
c.Assert(err, IsNil)
c.Assert(snapPlugs, HasLen, 1)

Expand Down Expand Up @@ -652,8 +652,8 @@ func (s *confdbTestSuite) setupConfdbModificationScenario(c *C, custodians, nonC
s.repo = interfaces.NewRepository()
ifacerepo.Replace(s.state, s.repo)

regIface := &ifacetest.TestInterface{InterfaceName: "confdb"}
err := s.repo.AddInterface(regIface)
confdbIface := &ifacetest.TestInterface{InterfaceName: "confdb"}
err := s.repo.AddInterface(confdbIface)
c.Assert(err, IsNil)

// mock the confdb slot
Expand Down Expand Up @@ -1125,7 +1125,7 @@ func (s *confdbTestSuite) TestGetDifferentTransactionThanOngoing(c *C) {
refTask.Set("commit-task", commitTask.ID())

// make some other confdb to access concurrently
reg, err := confdb.New("foo", "bar", map[string]interface{}{
confdb, err := confdb.New("foo", "bar", map[string]interface{}{
"foo": map[string]interface{}{
"rules": []interface{}{
map[string]interface{}{"request": "foo", "storage": "foo"},
Expand All @@ -1139,7 +1139,7 @@ func (s *confdbTestSuite) TestGetDifferentTransactionThanOngoing(c *C) {
c.Assert(err, IsNil)

ctx.Lock()
tx, commitTxFunc, err := confdbstate.GetTransactionToModify(ctx, s.state, reg.View("foo"))
tx, commitTxFunc, err := confdbstate.GetTransactionToModify(ctx, s.state, confdb.View("foo"))
ctx.Unlock()
c.Assert(err, ErrorMatches, fmt.Sprintf(`cannot access confdb foo/bar: ongoing transaction for %s/network`, s.devAccID))
c.Assert(tx, IsNil)
Expand Down
Loading

0 comments on commit b9ba8ba

Please sign in to comment.