-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add catalog update env metadata changeset #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gustavogama-cll
merged 2 commits into
main
from
ggama/feat/add-catalog-update-env-metadata-changeset
May 8, 2026
+245
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package changesets | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| cldfdatastore "github.com/smartcontractkit/chainlink-deployments-framework/datastore" | ||
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
| cldfops "github.com/smartcontractkit/chainlink-deployments-framework/operations" | ||
|
|
||
| "github.com/smartcontractkit/cld-changesets/catalog/operations" | ||
| ) | ||
|
|
||
| // UpdateEnvMetadataChangeset updates existing env metadata entries in the Catalog service. | ||
| type UpdateEnvMetadataChangeset struct{} | ||
|
|
||
| type UpdateEnvMetadataChangesetInput struct { | ||
| EnvMetadata cldfdatastore.EnvMetadata `json:"envMetadata"` | ||
| } | ||
|
|
||
| // VerifyPreconditions ensures the input is valid. | ||
| func (UpdateEnvMetadataChangeset) VerifyPreconditions(e cldf.Environment, input UpdateEnvMetadataChangesetInput) error { | ||
| if input.EnvMetadata.Metadata == nil { | ||
| return errors.New("missing env metadata input") | ||
| } | ||
| if e.DataStore == nil { | ||
| return errors.New("missing datastore in environment") | ||
| } | ||
|
|
||
| return nil | ||
|
gustavogama-cll marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // Apply executes the changeset, updating the env metadata in the Catalog service. | ||
| func (UpdateEnvMetadataChangeset) Apply( | ||
| e cldf.Environment, input UpdateEnvMetadataChangesetInput, | ||
| ) (cldf.ChangesetOutput, error) { | ||
| deps := operations.UpdateEnvMetadataDeps{DataStore: e.DataStore} | ||
| opInput := operations.UpdateEnvMetadataInput{EnvMetadata: input.EnvMetadata} | ||
|
|
||
| report, err := cldfops.ExecuteOperation(e.OperationsBundle, operations.UpdateEnvMetadataOp, deps, opInput) | ||
| out := cldf.ChangesetOutput{ | ||
| DataStore: report.Output.DataStore, | ||
| Reports: []cldfops.Report[any, any]{report.ToGenericReport()}, | ||
| } | ||
| if err != nil { | ||
| return out, err | ||
| } | ||
|
|
||
| return out, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| package changesets | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/google/go-cmp/cmp/cmpopts" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| cldfdatastore "github.com/smartcontractkit/chainlink-deployments-framework/datastore" | ||
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
| cldfoperations "github.com/smartcontractkit/chainlink-deployments-framework/operations" | ||
| cldflogger "github.com/smartcontractkit/chainlink-deployments-framework/pkg/logger" | ||
|
|
||
| "github.com/smartcontractkit/cld-changesets/catalog/operations" | ||
| ) | ||
|
|
||
| func TestUpdateEnvMetadataChangeset_VerifyPreconditions(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| envMetadata := cldfdatastore.EnvMetadata{Metadata: "value"} | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| env cldf.Environment | ||
| input UpdateEnvMetadataChangesetInput | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "success: valid preconditions", | ||
| env: cldf.Environment{DataStore: func() cldfdatastore.DataStore { | ||
| ds := cldfdatastore.NewMemoryDataStore() | ||
| err := ds.EnvMetadata().Set(envMetadata) | ||
| require.NoError(t, err) | ||
|
|
||
| return ds.Seal() | ||
| }()}, | ||
| input: UpdateEnvMetadataChangesetInput{ | ||
| EnvMetadata: envMetadata, | ||
| }, | ||
| }, | ||
| { | ||
| name: "failure: missing datastore", | ||
| env: cldf.Environment{}, | ||
| input: UpdateEnvMetadataChangesetInput{ | ||
| EnvMetadata: envMetadata, | ||
| }, | ||
| wantErr: "missing datastore in environment", | ||
| }, | ||
| { | ||
| name: "failure: no env metadata given", | ||
| env: cldf.Environment{DataStore: cldfdatastore.NewMemoryDataStore().Seal()}, | ||
| input: UpdateEnvMetadataChangesetInput{ | ||
| EnvMetadata: cldfdatastore.EnvMetadata{}, | ||
| }, | ||
| wantErr: "missing env metadata input", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| err := UpdateEnvMetadataChangeset{}.VerifyPreconditions(tt.env, tt.input) | ||
|
|
||
| if tt.wantErr == "" { | ||
| require.NoError(t, err) | ||
| } else { | ||
| require.ErrorContains(t, err, tt.wantErr) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestUpdateEnvMetadataChangeset_Apply(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| envMetadata := cldfdatastore.EnvMetadata{Metadata: "value"} | ||
| envMetadataUpdated := cldfdatastore.EnvMetadata{Metadata: "updated-value"} | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| env cldf.Environment | ||
| input UpdateEnvMetadataChangesetInput | ||
| want cldf.ChangesetOutput | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "success: updates env metadata", | ||
| env: cldf.Environment{ | ||
| DataStore: testDataStoreWithEnvMetadata(t, envMetadata).Seal(), | ||
| OperationsBundle: cldfoperations.NewBundle(t.Context, cldflogger.Test(t), cldfoperations.NewMemoryReporter()), | ||
| }, | ||
|
gustavogama-cll marked this conversation as resolved.
|
||
| input: UpdateEnvMetadataChangesetInput{ | ||
| EnvMetadata: envMetadataUpdated, | ||
| }, | ||
| want: cldf.ChangesetOutput{ | ||
| DataStore: testDataStoreWithEnvMetadata(t, envMetadataUpdated), | ||
| Reports: []cldfoperations.Report[any, any]{{ | ||
| Def: cldfoperations.Definition{ | ||
| ID: "catalog-update-env-metadata", | ||
| Version: semver.MustParse("1.0.0"), | ||
| Description: "Update env metadata entries in the Catalog service", | ||
| }, | ||
| Input: operations.UpdateEnvMetadataInput{ | ||
| EnvMetadata: envMetadataUpdated, | ||
| }, | ||
| Output: operations.UpdateEnvMetadataOutput{ | ||
| DataStore: testDataStoreWithEnvMetadata(t, envMetadataUpdated), | ||
| }, | ||
| }}, | ||
| }, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| got, err := UpdateEnvMetadataChangeset{}.Apply(tt.env, tt.input) | ||
|
|
||
| if tt.wantErr == "" { | ||
| require.NoError(t, err) | ||
| require.Empty(t, | ||
| cmp.Diff(tt.want, got, | ||
| cmpopts.IgnoreFields(cldfoperations.Report[any, any]{}, "ID", "Timestamp"), | ||
| cmpopts.IgnoreUnexported(cldfdatastore.MemoryAddressRefStore{}, cldfdatastore.MemoryChainMetadataStore{}, | ||
| cldfdatastore.MemoryContractMetadataStore{}, cldfdatastore.MemoryEnvMetadataStore{}))) | ||
| } else { | ||
| require.ErrorContains(t, err, tt.wantErr) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // ----- helpers ----- | ||
|
|
||
| func testDataStoreWithEnvMetadata( | ||
| t *testing.T, metadata cldfdatastore.EnvMetadata, | ||
| ) cldfdatastore.MutableDataStore { | ||
| t.Helper() | ||
|
|
||
| ds := cldfdatastore.NewMemoryDataStore() | ||
| err := ds.EnvMetadata().Set(metadata) | ||
| require.NoError(t, err) | ||
|
|
||
| return ds | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package operations | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
|
|
||
| cldfdatastore "github.com/smartcontractkit/chainlink-deployments-framework/datastore" | ||
| cldfops "github.com/smartcontractkit/chainlink-deployments-framework/operations" | ||
| ) | ||
|
|
||
| // UpdateEnvMetadataDeps holds non-serializable dependencies for the | ||
| // UpdateEnvMetadataOp operation. | ||
| type UpdateEnvMetadataDeps struct { | ||
| DataStore cldfdatastore.DataStore | ||
| } | ||
|
|
||
| // UpdateEnvMetadataInput is the serializable input of an UpdateEnvMetadataOp invocation. | ||
| type UpdateEnvMetadataInput struct { | ||
| EnvMetadata cldfdatastore.EnvMetadata | ||
| } | ||
|
|
||
| // UpdateEnvMetadataOutput is the serializable output of an UpdateEnvMetadataOp invocation. | ||
| type UpdateEnvMetadataOutput struct { | ||
| DataStore cldfdatastore.MutableDataStore | ||
| } | ||
|
|
||
| // UpdateEnvMetadataOp updates existing env metadata entries in the Catalog service. | ||
| var UpdateEnvMetadataOp = cldfops.NewOperation( | ||
| "catalog-update-env-metadata", | ||
| semver.MustParse("1.0.0"), | ||
| "Update env metadata entries in the Catalog service", | ||
| func(b cldfops.Bundle, deps UpdateEnvMetadataDeps, input UpdateEnvMetadataInput) (UpdateEnvMetadataOutput, error) { | ||
| dataStore := cldfdatastore.NewMemoryDataStore() | ||
| err := dataStore.Merge(deps.DataStore) | ||
| if err != nil { | ||
| return UpdateEnvMetadataOutput{}, fmt.Errorf("failed to create memory data store: %w", err) | ||
|
gustavogama-cll marked this conversation as resolved.
|
||
| } | ||
|
|
||
| err = dataStore.EnvMetadata().Set(input.EnvMetadata) | ||
|
gustavogama-cll marked this conversation as resolved.
|
||
| if err != nil { | ||
| return UpdateEnvMetadataOutput{}, fmt.Errorf("failed to update env metadata in catalog store: %w", err) | ||
| } | ||
|
|
||
| b.Logger.Infow("Catalog EnvMetadata updated successfully") | ||
|
|
||
| return UpdateEnvMetadataOutput{DataStore: dataStore}, nil | ||
| }, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.