Skip to content

Commit

Permalink
Rename PckageRevisionDraft interface method 'Close()' to 'Save()'
Browse files Browse the repository at this point in the history
  • Loading branch information
liamfallon committed Dec 10, 2024
1 parent 6d34cf8 commit 2198141
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions pkg/cache/memory/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func TestPublishedLatest(t *testing.T) {
if err := update.UpdateLifecycle(ctx, api.PackageRevisionLifecyclePublished); err != nil {
t.Fatalf("UpdateLifecycle failed; %v", err)
}
closed, err := update.Close(ctx, "")
saved, err := update.Save(ctx, "")
if err != nil {
t.Fatalf("Close failed: %v", err)
t.Fatalf("Save failed: %v", err)
}
resource, err := closed.GetPackageRevision(ctx)
resource, err := saved.GetPackageRevision(ctx)
if err != nil {
t.Errorf("didn't expect error, but got %v", err)
}
Expand Down Expand Up @@ -158,11 +158,11 @@ func TestDeletePublishedMain(t *testing.T) {
if err := update.UpdateLifecycle(ctx, api.PackageRevisionLifecyclePublished); err != nil {
t.Fatalf("UpdateLifecycle failed; %v", err)
}
closed, err := update.Close(ctx, "")
saved, err := update.Save(ctx, "")
if err != nil {
t.Fatalf("Close failed: %v", err)
t.Fatalf("Save failed: %v", err)
}
_, err = closed.GetPackageRevision(ctx)
_, err = saved.GetPackageRevision(ctx)
if err != nil {
t.Errorf("didn't expect error, but got %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cache/memory/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type cachedDraft struct {

var _ repository.PackageRevisionDraft = &cachedDraft{}

func (cd *cachedDraft) Close(ctx context.Context, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "cachedDraft::Close", trace.WithAttributes())
func (cd *cachedDraft) Save(ctx context.Context, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "cachedDraft::Save", trace.WithAttributes())
defer span.End()
v, err := cd.cache.Version(ctx)
if err != nil {
Expand Down Expand Up @@ -63,9 +63,9 @@ func (cd *cachedDraft) Close(ctx context.Context, version string) (repository.Pa
return nil, err
}

if closed, err := cd.PackageRevisionDraft.Close(ctx, nextVersion); err != nil {
if saved, err := cd.PackageRevisionDraft.Save(ctx, nextVersion); err != nil {
return nil, err
} else {
return cd.cache.update(ctx, closed)
return cd.cache.update(ctx, saved)
}
}
8 changes: 4 additions & 4 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (cad *cadEngine) CreatePackageRevision(ctx context.Context, repositoryObj *
}

// Updates are done.
repoPkgRev, err := draft.Close(ctx, "")
repoPkgRev, err := draft.Save(ctx, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (cad *cadEngine) UpdatePackageRevision(ctx context.Context, version string,
}

// Updates are done.
repoPkgRev, err = draft.Close(ctx, version)
repoPkgRev, err = draft.Save(ctx, version)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -508,7 +508,7 @@ func (cad *cadEngine) UpdatePackageResources(ctx context.Context, repositoryObj
return nil, renderStatus, err
}
// No lifecycle change when updating package resources; updates are done.
repoPkgRev, err := draft.Close(ctx, "")
repoPkgRev, err := draft.Save(ctx, "")
if err != nil {
return nil, renderStatus, err
}
Expand Down Expand Up @@ -561,7 +561,7 @@ func (cad *cadEngine) RecloneAndReplay(ctx context.Context, parentPR repository.
return nil, err
}

repoPkgRev, err := draft.Close(ctx, version)
repoPkgRev, err := draft.Save(ctx, version)

if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/git/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func (d *gitPackageRevisionDraft) UpdateLifecycle(ctx context.Context, new v1alp
}

// Finish round of updates.
func (d *gitPackageRevisionDraft) Close(ctx context.Context, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "gitPackageDraft::Close", trace.WithAttributes())
func (d *gitPackageRevisionDraft) Save(ctx context.Context, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "gitPackageDraft::Save", trace.WithAttributes())
defer span.End()

return d.parent.CloseDraft(ctx, version, d)
return d.parent.SaveDraft(ctx, version, d)
}

func (d *gitPackageRevisionDraft) GetName() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ func (r *gitRepository) UpdateDraftResources(ctx context.Context, draft *gitPack
return nil
}

func (r *gitRepository) CloseDraft(ctx context.Context, version string, d *gitPackageRevisionDraft) (*gitPackageRevision, error) {
func (r *gitRepository) SaveDraft(ctx context.Context, version string, d *gitPackageRevisionDraft) (*gitPackageRevision, error) {
r.mutex.Lock()
defer r.mutex.Unlock()

Expand Down
24 changes: 12 additions & 12 deletions pkg/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ func (g GitSuite) TestGitPackageRoundTrip(t *testing.T) {
t.Fatalf("draft.UpdateResources(%#v, %#v) failed: %v", newResources, task, err)
}

revision, err := draft.Close(ctx, "v1")
revision, err := draft.Save(ctx, "v1")
if err != nil {
t.Fatalf("draft.Close() failed: %v", err)
t.Fatalf("draft.Save() failed: %v", err)
}
klog.Infof("created revision %v", revision.KubeObjectName())
}
Expand All @@ -207,9 +207,9 @@ func (g GitSuite) TestGitPackageRoundTrip(t *testing.T) {
if err := update.UpdateLifecycle(ctx, v1alpha1.PackageRevisionLifecyclePublished); err != nil {
t.Fatalf("UpdateLifecycle failed: %v", err)
}
approved, err := update.Close(ctx, "v1")
approved, err := update.Save(ctx, "v1")
if err != nil {
t.Fatalf("Close() of %q, %q failed: %v", packageName, workspace, err)
t.Fatalf("Save() of %q, %q failed: %v", packageName, workspace, err)
}
if approved.Key().Revision != "v1" {
t.Fatalf("UpdateLifecycle did not assign correct revision number; got %s, want v1",
Expand Down Expand Up @@ -418,9 +418,9 @@ func (g GitSuite) TestListPackagesTrivial(t *testing.T) {
}); err != nil {
t.Fatalf("UpdateResources() failed: %v", err)
}
newRevision, err := draft.Close(ctx, "")
newRevision, err := draft.Save(ctx, "")
if err != nil {
t.Fatalf("draft.Close() failed: %v", err)
t.Fatalf("draft.Save() failed: %v", err)
}

result, err := newRevision.GetPackageRevision(ctx)
Expand Down Expand Up @@ -506,9 +506,9 @@ func (g GitSuite) TestCreatePackageInTrivialRepository(t *testing.T) {
}); err != nil {
t.Fatalf("UpdateResources() failed: %v", err)
}
newRevision, err := draft.Close(ctx, "")
newRevision, err := draft.Save(ctx, "")
if err != nil {
t.Fatalf("draft.Close() failed: %v", err)
t.Fatalf("draft.Save() failed: %v", err)
}

result, err := newRevision.GetPackageRevision(ctx)
Expand Down Expand Up @@ -688,9 +688,9 @@ func (g GitSuite) TestApproveDraft(t *testing.T) {

update.UpdateLifecycle(ctx, v1alpha1.PackageRevisionLifecyclePublished)

new, err := update.Close(ctx, "v1")
new, err := update.Save(ctx, "v1")
if err != nil {
t.Fatalf("Close failed: %v", err)
t.Fatalf("Save failed: %v", err)
}

rev, err := new.GetPackageRevision(ctx)
Expand Down Expand Up @@ -750,9 +750,9 @@ func (g GitSuite) TestApproveDraftWithHistory(t *testing.T) {

update.UpdateLifecycle(ctx, v1alpha1.PackageRevisionLifecyclePublished)

new, err := update.Close(ctx, "v1")
new, err := update.Save(ctx, "v1")
if err != nil {
t.Fatalf("Close failed: %v", err)
t.Fatalf("Save failed: %v", err)
}

rev, err := new.GetPackageRevision(ctx)
Expand Down
4 changes: 2 additions & 2 deletions pkg/oci/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ func (p *ociPackageDraft) GetName() string {
}

// Finish round of updates.
func (p *ociPackageDraft) Close(ctx context.Context, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "ociPackageDraft::Close", trace.WithAttributes())
func (p *ociPackageDraft) Save(ctx context.Context, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "ociPackageDraft::Save", trace.WithAttributes())
defer span.End()

ref := p.tag
Expand Down
4 changes: 2 additions & 2 deletions pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ type Package interface {

type PackageRevisionDraft interface {
UpdateResources(ctx context.Context, new *v1alpha1.PackageRevisionResources, task *v1alpha1.Task) error
// Updates desired lifecycle of the package. The lifecycle is applied on Close.
// Updates desired lifecycle of the package. The lifecycle is applied on Save.
UpdateLifecycle(ctx context.Context, new v1alpha1.PackageRevisionLifecycle) error
// Finish round of updates.
Close(ctx context.Context, version string) (PackageRevision, error)
Save(ctx context.Context, version string) (PackageRevision, error)
GetName() string
}

Expand Down

0 comments on commit 2198141

Please sign in to comment.