Skip to content

Commit

Permalink
Rename Fetch to Get
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Aug 23, 2023
1 parent 3e4d72e commit 1c1faef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions internal/db/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ func (d *Database) ForEachModel(ctx context.Context, f func(m *dbmodel.Model) er
return nil
}

func (d *Database) FetchModelsByUUID(ctx context.Context, modelUUIDs []string) ([]dbmodel.Model, error) {
const op = errors.Op("db.ForEachModel")
// GetModelsByUUID retrieves a list of models where the model UUIDs are in
// the provided modelUUIDs slice.
func (d *Database) GetModelsByUUID(ctx context.Context, modelUUIDs []string) ([]dbmodel.Model, error) {
const op = errors.Op("db.GetModelsByUUID")

if err := d.ready(); err != nil {
return nil, errors.E(op, err)
Expand Down
12 changes: 6 additions & 6 deletions internal/db/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func (s *dbSuite) TestForEachModel(c *qt.C) {
})
}

const testFetchModelsByUUIDEnv = `clouds:
const testGetModelsByUUIDEnv = `clouds:
- name: test
type: test
regions:
Expand Down Expand Up @@ -770,29 +770,29 @@ models:
access: admin
`

func TestFetchModelsByUUIDlUnconfiguredDatabase(t *testing.T) {
func TestGetModelsByUUIDlUnconfiguredDatabase(t *testing.T) {
c := qt.New(t)

var d db.Database
_, err := d.FetchModelsByUUID(context.Background(), nil)
_, err := d.GetModelsByUUID(context.Background(), nil)
c.Check(err, qt.ErrorMatches, `database not configured`)
c.Check(errors.ErrorCode(err), qt.Equals, errors.CodeServerConfiguration)
}

func (s *dbSuite) TestFetchModelsByUUID(c *qt.C) {
func (s *dbSuite) TestGetModelsByUUID(c *qt.C) {
ctx := context.Background()
err := s.Database.Migrate(context.Background(), true)
c.Assert(err, qt.Equals, nil)

env := jimmtest.ParseEnvironment(c, testFetchModelsByUUIDEnv)
env := jimmtest.ParseEnvironment(c, testGetModelsByUUIDEnv)
env.PopulateDB(c, *s.Database, nil)

modelUUIDs := []string{
"00000002-0000-0000-0000-000000000001",
"00000002-0000-0000-0000-000000000002",
"00000002-0000-0000-0000-000000000003",
}
models, err := s.Database.FetchModelsByUUID(ctx, modelUUIDs)
models, err := s.Database.GetModelsByUUID(ctx, modelUUIDs)
c.Assert(err, qt.IsNil)
sort.Slice(models, func(i, j int) bool {
return models[i].UUID.String < models[j].UUID.String
Expand Down
2 changes: 1 addition & 1 deletion internal/jujuapi/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (r *controllerRoot) CrossModelQuery(ctx context.Context, req apiparams.Cros
for i, uuid := range modelUUIDs {
modelUUIDs[i] = strings.Split(uuid, ":")[1]
}
models, err := r.jimm.Database.FetchModelsByUUID(ctx, modelUUIDs)
models, err := r.jimm.Database.GetModelsByUUID(ctx, modelUUIDs)
if err != nil {
return apiparams.CrossModelQueryResponse{}, errors.E(op, errors.Code("failed to get models for user"))
}
Expand Down

0 comments on commit 1c1faef

Please sign in to comment.