Skip to content
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

api: OptionValueList helper #3473

Merged
merged 1 commit into from
Jun 20, 2024
Merged

api: OptionValueList helper #3473

merged 1 commit into from
Jun 20, 2024

Conversation

akutz
Copy link
Member

@akutz akutz commented Jun 20, 2024

Description

This patch introduces the type OptionValueList in the object package. This new type simplifies working with []vimtypes.BaseOptionValue properties such as ExtraConfig.

Closes: NA

Type of change

Please mark options that are relevant:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Build related change

How Has This Been Tested?

  • Running go test -v -count 1 -run TestOptionValueList ./object:

    === RUN   TestOptionValueList
    === RUN   TestOptionValueList/OptionValueListFromMap
    === RUN   TestOptionValueList/OptionValueListFromMap/a_nil_map_should_return_nil
    === RUN   TestOptionValueList/OptionValueListFromMap/a_map_with_string_values_should_return_OptionValues
    === RUN   TestOptionValueList/OptionValueListFromMap/a_map_with_values_of_varying_numeric_types_should_return_OptionValues
    === RUN   TestOptionValueList/OptionValueListFromMap/a_map_with_pointer_values_should_return_OptionValues
    === RUN   TestOptionValueList/Get
    === RUN   TestOptionValueList/Get/a_nil_receiver_should_not_panic_and_return_nil,_false
    === RUN   TestOptionValueList/Get/a_non-existent_key_should_return_nil,_false
    === RUN   TestOptionValueList/Get/an_existing_key_should_return_its_value,_true
    === RUN   TestOptionValueList/Get/an_existing_key_should_return_its_value,_true_when_data_includes_a_nillable_types.BaseOptionValue
    === RUN   TestOptionValueList/GetString
    === RUN   TestOptionValueList/GetString/a_nil_receiver_should_not_panic_and_return_"",_false
    === RUN   TestOptionValueList/GetString/a_non-existent_key_should_return_"",_false
    === RUN   TestOptionValueList/GetString/an_existing_key_for_a_string_value_should_return_its_string_value,_true
    === RUN   TestOptionValueList/GetString/an_existing_key_for_a_*string_value_that_is_not_nil_should_return_its_string_value,_true
    === RUN   TestOptionValueList/GetString/an_existing_key_for_a_*string_value_that_is_nil_should_return_"",_true
    === RUN   TestOptionValueList/GetString/an_existing_key_for_an_int32_value_should_return_its_string_value,_true
    === RUN   TestOptionValueList/GetString/an_existing_key_for_a_*uint64_value_that_is_not_nil_should_return_its_string_value,_true
    === RUN   TestOptionValueList/GetString/an_existing_key_for_a_*uint64_value_that_is_nil_should_return_"",_true
    === RUN   TestOptionValueList/GetString/an_existing_key_for_a_string_value_should_return_its_string_value,_true_when_data_includes_a_nillable_types.BaseOptionValue
    === RUN   TestOptionValueList/Map
    === RUN   TestOptionValueList/Map/a_nil_receiver_should_not_panic_and_return_nil
    === RUN   TestOptionValueList/Map/data_with_homogeneous_values_should_return_a_map
    === RUN   TestOptionValueList/Map/data_with_heterogeneous_values_should_return_a_map
    === RUN   TestOptionValueList/Map/data_with_just_a_nillable_types.BaseOptionValue_should_return_nil
    === RUN   TestOptionValueList/StringMap
    === RUN   TestOptionValueList/StringMap/a_nil_receiver_should_not_panic_and_return_nil
    === RUN   TestOptionValueList/StringMap/data_with_homogeneous_values_should_return_a_map
    === RUN   TestOptionValueList/StringMap/data_with_heterogeneous_values_should_return_a_map
    === RUN   TestOptionValueList/StringMap/data_with_just_a_nillable_types.BaseOptionValue_should_return_nil
    === RUN   TestOptionValueList/Additions
    === RUN   TestOptionValueList/Additions/a_nil_receiver_and_nil_input_should_not_panic_and_return_nil
    === RUN   TestOptionValueList/Additions/a_nil_receiver_and_non-nil_input_should_not_panic_and_return_the_diff
    === RUN   TestOptionValueList/Additions/a_non-nil_receiver_and_nil_input_should_return_nil
    === RUN   TestOptionValueList/Additions/a_non-nil_receiver_and_non-nil_input_should_return_the_diff
    === RUN   TestOptionValueList/Diff
    === RUN   TestOptionValueList/Diff/a_nil_receiver_and_nil_input_should_not_panic_and_return_nil
    === RUN   TestOptionValueList/Diff/a_nil_receiver_and_non-nil_input_should_not_panic_and_return_the_diff
    === RUN   TestOptionValueList/Diff/a_non-nil_receiver_and_nil_input_should_return_nil
    === RUN   TestOptionValueList/Diff/a_non-nil_receiver_and_non-nil_input_should_return_the_diff
    === RUN   TestOptionValueList/Join
    === RUN   TestOptionValueList/Join/a_nil_receiver_and_nil_input_should_not_panic_and_return_nil
    === RUN   TestOptionValueList/Join/a_nil_receiver_and_non-nil_input_should_not_panic_and_return_the_joined_data
    === RUN   TestOptionValueList/Join/a_non-nil_receiver_and_nil_input_should_return_the_joined_data
    === RUN   TestOptionValueList/Join/a_non-nil_receiver_and_non-nil_input_should_return_the_joined_data
    === RUN   TestOptionValueList/Join/a_non-nil_receiver_and_non-nil_input,_flipping_left_and_right,_should_return_the_joined_data
    --- PASS: TestOptionValueList (0.00s)
        --- PASS: TestOptionValueList/OptionValueListFromMap (0.00s)
            --- PASS: TestOptionValueList/OptionValueListFromMap/a_nil_map_should_return_nil (0.00s)
            --- PASS: TestOptionValueList/OptionValueListFromMap/a_map_with_string_values_should_return_OptionValues (0.00s)
            --- PASS: TestOptionValueList/OptionValueListFromMap/a_map_with_values_of_varying_numeric_types_should_return_OptionValues (0.00s)
            --- PASS: TestOptionValueList/OptionValueListFromMap/a_map_with_pointer_values_should_return_OptionValues (0.00s)
        --- PASS: TestOptionValueList/Get (0.00s)
            --- PASS: TestOptionValueList/Get/a_nil_receiver_should_not_panic_and_return_nil,_false (0.00s)
            --- PASS: TestOptionValueList/Get/a_non-existent_key_should_return_nil,_false (0.00s)
            --- PASS: TestOptionValueList/Get/an_existing_key_should_return_its_value,_true (0.00s)
            --- PASS: TestOptionValueList/Get/an_existing_key_should_return_its_value,_true_when_data_includes_a_nillable_types.BaseOptionValue (0.00s)
        --- PASS: TestOptionValueList/GetString (0.00s)
            --- PASS: TestOptionValueList/GetString/a_nil_receiver_should_not_panic_and_return_"",_false (0.00s)
            --- PASS: TestOptionValueList/GetString/a_non-existent_key_should_return_"",_false (0.00s)
            --- PASS: TestOptionValueList/GetString/an_existing_key_for_a_string_value_should_return_its_string_value,_true (0.00s)
            --- PASS: TestOptionValueList/GetString/an_existing_key_for_a_*string_value_that_is_not_nil_should_return_its_string_value,_true (0.00s)
            --- PASS: TestOptionValueList/GetString/an_existing_key_for_a_*string_value_that_is_nil_should_return_"",_true (0.00s)
            --- PASS: TestOptionValueList/GetString/an_existing_key_for_an_int32_value_should_return_its_string_value,_true (0.00s)
            --- PASS: TestOptionValueList/GetString/an_existing_key_for_a_*uint64_value_that_is_not_nil_should_return_its_string_value,_true (0.00s)
            --- PASS: TestOptionValueList/GetString/an_existing_key_for_a_*uint64_value_that_is_nil_should_return_"",_true (0.00s)
            --- PASS: TestOptionValueList/GetString/an_existing_key_for_a_string_value_should_return_its_string_value,_true_when_data_includes_a_nillable_types.BaseOptionValue (0.00s)
        --- PASS: TestOptionValueList/Map (0.00s)
            --- PASS: TestOptionValueList/Map/a_nil_receiver_should_not_panic_and_return_nil (0.00s)
            --- PASS: TestOptionValueList/Map/data_with_homogeneous_values_should_return_a_map (0.00s)
            --- PASS: TestOptionValueList/Map/data_with_heterogeneous_values_should_return_a_map (0.00s)
            --- PASS: TestOptionValueList/Map/data_with_just_a_nillable_types.BaseOptionValue_should_return_nil (0.00s)
        --- PASS: TestOptionValueList/StringMap (0.00s)
            --- PASS: TestOptionValueList/StringMap/a_nil_receiver_should_not_panic_and_return_nil (0.00s)
            --- PASS: TestOptionValueList/StringMap/data_with_homogeneous_values_should_return_a_map (0.00s)
            --- PASS: TestOptionValueList/StringMap/data_with_heterogeneous_values_should_return_a_map (0.00s)
            --- PASS: TestOptionValueList/StringMap/data_with_just_a_nillable_types.BaseOptionValue_should_return_nil (0.00s)
        --- PASS: TestOptionValueList/Additions (0.00s)
            --- PASS: TestOptionValueList/Additions/a_nil_receiver_and_nil_input_should_not_panic_and_return_nil (0.00s)
            --- PASS: TestOptionValueList/Additions/a_nil_receiver_and_non-nil_input_should_not_panic_and_return_the_diff (0.00s)
            --- PASS: TestOptionValueList/Additions/a_non-nil_receiver_and_nil_input_should_return_nil (0.00s)
            --- PASS: TestOptionValueList/Additions/a_non-nil_receiver_and_non-nil_input_should_return_the_diff (0.00s)
        --- PASS: TestOptionValueList/Diff (0.00s)
            --- PASS: TestOptionValueList/Diff/a_nil_receiver_and_nil_input_should_not_panic_and_return_nil (0.00s)
            --- PASS: TestOptionValueList/Diff/a_nil_receiver_and_non-nil_input_should_not_panic_and_return_the_diff (0.00s)
            --- PASS: TestOptionValueList/Diff/a_non-nil_receiver_and_nil_input_should_return_nil (0.00s)
            --- PASS: TestOptionValueList/Diff/a_non-nil_receiver_and_non-nil_input_should_return_the_diff (0.00s)
        --- PASS: TestOptionValueList/Join (0.00s)
            --- PASS: TestOptionValueList/Join/a_nil_receiver_and_nil_input_should_not_panic_and_return_nil (0.00s)
            --- PASS: TestOptionValueList/Join/a_nil_receiver_and_non-nil_input_should_not_panic_and_return_the_joined_data (0.00s)
            --- PASS: TestOptionValueList/Join/a_non-nil_receiver_and_nil_input_should_return_the_joined_data (0.00s)
            --- PASS: TestOptionValueList/Join/a_non-nil_receiver_and_non-nil_input_should_return_the_joined_data (0.00s)
            --- PASS: TestOptionValueList/Join/a_non-nil_receiver_and_non-nil_input,_flipping_left_and_right,_should_return_the_joined_data (0.00s)
    PASS
    ok  	github.com/vmware/govmomi/object	0.306s
  • Demonstrating 100% code-coverage for the new code:

image image image

Checklist:

  • My code follows the CONTRIBUTION guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

@akutz akutz force-pushed the feature/option-values branch 2 times, most recently from 5993955 to 4eed03b Compare June 20, 2024 14:36
Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thank you @akutz
Just a few minor suggestions. Regarding the name, we have some existing wrapper types where the pattern is appending List to the vim25 name:

type AuthorizationRoleList []types.AuthorizationRole
type CustomFieldDefList []types.CustomFieldDef
type HostFirewallRulesetList []types.HostFirewallRuleset
type VirtualDeviceList []types.BaseVirtualDevice
type OptionValueList []types.BaseOptionValue

Prefer that to an s suffix, but am also ok with the OptionValues name as-is. What do you think?

object/option_values.go Outdated Show resolved Hide resolved
object/option_values.go Outdated Show resolved Hide resolved
object/option_values.go Outdated Show resolved Hide resolved
@akutz
Copy link
Member Author

akutz commented Jun 20, 2024

Thanks @dougm , I addressed everything. Please note the one length check was to avoid initializing the map unless required. I updated that. Thanks again!

This patch introduces the type OptionValueList in the object package.
This new type simplifies working with []vimtypes.BaseOptionValue
properties such as ExtraConfig.
@akutz akutz changed the title OptionValues helper api: OptionValueList helper Jun 20, 2024
Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @akutz !

@akutz akutz merged commit 7f49441 into vmware:main Jun 20, 2024
12 checks passed
@akutz akutz deleted the feature/option-values branch June 20, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants