Skip to content

Commit

Permalink
fix: More flexible context config unmarshaller (#1132)
Browse files Browse the repository at this point in the history
## Description:
Without this it's a massive pain to make changes to the context config
shape, as it is also consumed by the portal

## Is this change user facing?
NO
<!-- If yes, please add the "user facing" label to the PR -->
<!-- If yes, don't forget to include docs changes where relevant -->

## References (if applicable):
<!-- Add relevant Github Issues, Discord threads, or other helpful
information. -->
  • Loading branch information
Guillaume Bouvignies committed Aug 18, 2023
1 parent e014a6f commit 7892bda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion contexts-config-store/store/serde/contexts_config.go
Expand Up @@ -16,7 +16,8 @@ func SerializeKurtosisContextsConfig(kurtosisContextsConfig *generated.KurtosisC

func DeserializeKurtosisContextsConfig(serializedKurtosisContextsConfig []byte) (*generated.KurtosisContextsConfig, error) {
kurtosisContextsConfig := new(generated.KurtosisContextsConfig)
if err := protojson.Unmarshal(serializedKurtosisContextsConfig, kurtosisContextsConfig); err != nil {
unmarshaller := protojson.UnmarshalOptions{DiscardUnknown: true} // nolint: exhaustruct
if err := unmarshaller.Unmarshal(serializedKurtosisContextsConfig, kurtosisContextsConfig); err != nil {
return nil, stacktrace.Propagate(err, "Unable to deserialize Kurtosis contexts config object")
}
return kurtosisContextsConfig, nil
Expand Down
7 changes: 5 additions & 2 deletions contexts-config-store/store/serde/contexts_config_test.go
Expand Up @@ -53,7 +53,8 @@ var (
}],
"currentContextUuid":{
"value":"dc2a9471c70649b7aafae2448970dd2e"
}
},
"unknownField": "shouldBeIgnored"
}`
)

Expand All @@ -69,7 +70,9 @@ func TestSerializeContextsConfig(t *testing.T) {
writtenContextsConfig := new(generated.KurtosisContextsConfig)
require.NoError(t, protojson.Unmarshal(result, writtenContextsConfig))
expectedContextsConfig := new(generated.KurtosisContextsConfig)
require.NoError(t, protojson.Unmarshal([]byte(serializedContextsConfig), expectedContextsConfig))

unmarshaller := protojson.UnmarshalOptions{DiscardUnknown: true} // nolint: exhaustruct
require.NoError(t, unmarshaller.Unmarshal([]byte(serializedContextsConfig), expectedContextsConfig))

require.True(t, proto.Equal(writtenContextsConfig, expectedContextsConfig))
}
Expand Down

0 comments on commit 7892bda

Please sign in to comment.