From ee0d7193ac81ba8ef29714028711d2720b3a588d Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Mon, 21 Mar 2022 16:40:45 -0400 Subject: [PATCH] comment out un-enabled parent options --- .../configuration/consumers/example.py | 6 +- .../templates/configuration/init_config.yaml | 1 + .../templates/configuration/instances.yaml | 1 + .../configuration/consumers/test_example.py | 130 ++++++++++++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/configuration/consumers/example.py b/datadog_checks_dev/datadog_checks/dev/tooling/configuration/consumers/example.py index b33888dd50fd8..cf11327980224 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/configuration/consumers/example.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/configuration/consumers/example.py @@ -183,7 +183,11 @@ def write_option(option, writer, indent='', start_list=False): multiple = option['multiple'] multiple_instances_defined = option.get('multiple_instances_defined') - writer.write(indent, option_name, ':', '\n') + if not option_enabled(option): + writer.write(indent, '# ', option_name, ':', '\n') + else: + writer.write(indent, option_name, ':', '\n') + if multiple and multiple_instances_defined: for instance in option['options']: write_sub_option(instance, writer, indent, multiple, include_top_description=True) diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/init_config.yaml b/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/init_config.yaml index ab022b35bf8b4..935923de9e84f 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/init_config.yaml +++ b/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/init_config.yaml @@ -1,3 +1,4 @@ name: init_config +enabled: true description: | All options defined here are available to all instances. diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/instances.yaml b/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/instances.yaml index 0244d7381051e..b3451d75fcf2b 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/instances.yaml +++ b/datadog_checks_dev/datadog_checks/dev/tooling/templates/configuration/instances.yaml @@ -1,4 +1,5 @@ name: instances multiple: true +enabled: true description: | Every instance is scheduled independent of the others. diff --git a/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py b/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py index 4d3f58469899e..162518a519b61 100644 --- a/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py +++ b/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py @@ -1584,3 +1584,133 @@ def test_option_multiple_instances_defined(): # bar: """ ) + + +def test_parent_option_disabled(): + consumer = get_example_consumer( + """ + name: foo + version: 0.0.0 + files: + - name: test.yaml + example_name: test.yaml.example + options: + - template: instances + options: + - name: enabled_option + required: true + description: Description of enabled option + value: + type: boolean + example: true + - name: parent_option + description: Description of parent option + options: + - name: sub_option_1 + description: words + value: + type: boolean + example: true + - name: sub_option_2 + description: words + value: + type: string + example: foo.bar_none + """ + ) + + files = consumer.render() + contents, errors = files['test.yaml.example'] + assert not errors + assert contents == normalize_yaml( + """ + ## Every instance is scheduled independent of the others. + # + instances: + + ## @param enabled_option - boolean - required + ## Description of enabled option + # + - enabled_option: true + + ## Description of parent option + # + # parent_option: + + ## @param sub_option_1 - boolean - optional - default: true + ## words + # + # sub_option_1: true + + ## @param sub_option_2 - string - optional - default: foo.bar_none + ## words + # + # sub_option_2: foo.bar_none + """ + ) + + +def test_parent_option_enabled(): + consumer = get_example_consumer( + """ + name: foo + version: 0.0.0 + files: + - name: test.yaml + example_name: test.yaml.example + options: + - template: instances + options: + - name: enabled_option + required: true + description: Description of enabled option + value: + type: boolean + example: true + - name: parent_option + enabled: true + description: Description of parent option + options: + - name: enabled_sub_option + enabled: true + description: words + value: + type: boolean + example: true + - name: disabled_sub_option + description: words + value: + type: string + example: foo.bar_none + """ + ) + + files = consumer.render() + contents, errors = files['test.yaml.example'] + assert not errors + assert contents == normalize_yaml( + """ + ## Every instance is scheduled independent of the others. + # + instances: + + ## @param enabled_option - boolean - required + ## Description of enabled option + # + - enabled_option: true + + ## Description of parent option + # + parent_option: + + ## @param enabled_sub_option - boolean - optional - default: true + ## words + # + enabled_sub_option: true + + ## @param disabled_sub_option - string - optional - default: foo.bar_none + ## words + # + # disabled_sub_option: foo.bar_none + """ + )