public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Dominik Csapak <d.csapak@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] [PATCH common 4/4] section config: add tests for separated property lists
Date: Wed, 15 Nov 2023 10:44:23 +0100	[thread overview]
Message-ID: <nf3m5ibul3l3dafe36fquv36n24u7anmbs65qhkicjey4dm3y4@jfbgc43iwrm3> (raw)
In-Reply-To: <20231114103340.2850162-5-d.csapak@proxmox.com>

On Tue, Nov 14, 2023 at 11:33:39AM +0100, Dominik Csapak wrote:
> more or less a copy from the normal section config test, but now with
> properties defined multiple times as well as conflicting options
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  test/Makefile                         |   1 +
>  test/section_config_separated_test.pl | 486 ++++++++++++++++++++++++++
>  2 files changed, 487 insertions(+)
>  create mode 100755 test/section_config_separated_test.pl
> 
> diff --git a/test/Makefile b/test/Makefile
> index 82f40ab..3e9fef2 100644
> --- a/test/Makefile
> +++ b/test/Makefile
> @@ -6,6 +6,7 @@ TESTS = lock_file.test			\
>  	format_test.test		\
>  	section_config_test.test	\
>  	api_parameter_test.test		\
> +	section_config_separated_test.test\
>  
>  all:
>  
> diff --git a/test/section_config_separated_test.pl b/test/section_config_separated_test.pl
> new file mode 100755
> index 0000000..234f444
> --- /dev/null
> +++ b/test/section_config_separated_test.pl
> @@ -0,0 +1,486 @@
> +#!/usr/bin/perl
> +
> +use lib '../src';
> +
> +package Conf;
> +use strict;
> +use warnings;
> +
> +use Test::More;
> +
> +use base qw(PVE::SectionConfig);
> +
> +my $defaultData = {
> +    propertyList => {
> +	type => { description => "Section type." },
> +	id => {
> +	    description => "ID",
> +	    type => 'string',
> +	    format => 'pve-configid',
> +	    maxLength => 64,
> +	},
> +	common => {
> +	    type => 'string',
> +	    description => 'common value',
> +	    maxLength => 512,
> +	},
> +    },
> +    options => {
> +	id => {},
> +	type => {},
> +    },
> +};
> +
> +sub private {
> +    return $defaultData;
> +}
> +
> +sub expect_success {
> +    my ($class, $filename, $expected, $raw, $allow_unknown) = @_;
> +
> +    my $res = $class->parse_config($filename, $raw, $allow_unknown);
> +    delete $res->{digest};
> +
> +    is_deeply($res, $expected, $filename);
> +
> +    my $written = $class->write_config($filename, $res, $allow_unknown);
> +    my $res2 = $class->parse_config($filename, $written, $allow_unknown);
> +    delete $res2->{digest};
> +
> +    is_deeply($res, $res2, "$filename - verify rewritten data");
> +}
> +
> +sub expect_fail {
> +    my ($class, $filename, $expected, $raw) = @_;
> +
> +    eval { $class->parse_config($filename, $raw) };
> +    die "test '$filename' succeeded unexpectedly\n" if !$@;
> +    ok(1, "$filename should fail to parse");
> +}
> +
> +package Conf::One;
> +use strict;
> +use warnings;
> +
> +use base 'Conf';
> +
> +sub type {
> +    return 'one';
> +}
> +
> +sub properties {
> +    return {
> +	field1 => {
> +	    description => 'Field One',
> +	    type => 'integer',
> +	    minimum => 3,
> +	    maximum => 9,
> +	},
> +	another => {
> +	    description => 'Another field',
> +	    type => 'string',
> +	},
> +	field2 => {
> +	    description => 'Field Two',
> +	    type => 'integer',
> +	    minimum => 10,
> +	    maximum => 19,
> +	}
> +    };
> +}
> +
> +sub options {
> +    return {
> +	common => { optional => 1 },
> +	field1 => {},
> +	field2 => {},
> +	another => { optional => 1 },
> +	arrayfield => { optional => 1, type => 'two' },

Oh...
*That's* how you use `type` here...
Can we not?
I'd *really* prefer to just have `arrayfield` copied into the properties
right here.

Changing an existing property currently requires us to consider all the
types it appears in.
I thought we could now have *distinct* schemas for them without *also*
having to worry about potential reuse from somewhere else :S




  reply	other threads:[~2023-11-15  9:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 10:33 [pve-devel] [PATCH common/widget-toolkit] implement oneOf schema Dominik Csapak
2023-11-14 10:33 ` [pve-devel] [PATCH common 1/4] section config: add test for the schemas Dominik Csapak
2023-11-14 10:33 ` [pve-devel] [PATCH common 2/4] json schema: implement 'oneOf' schema Dominik Csapak
2023-11-14 13:44   ` Wolfgang Bumiller
2023-11-14 10:33 ` [pve-devel] [PATCH common 3/4] section config: allow separated property lists for plugins Dominik Csapak
2023-11-15  9:36   ` Wolfgang Bumiller
2023-11-14 10:33 ` [pve-devel] [PATCH common 4/4] section config: add tests for separated property lists Dominik Csapak
2023-11-15  9:44   ` Wolfgang Bumiller [this message]
2023-11-14 10:33 ` [pve-devel] [PATCH widget-toolkit 1/1] api-viewer: implement basic oneOf support Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nf3m5ibul3l3dafe36fquv36n24u7anmbs65qhkicjey4dm3y4@jfbgc43iwrm3 \
    --to=w.bumiller@proxmox.com \
    --cc=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal