-
Notifications
You must be signed in to change notification settings - Fork 153
Add support for conditional prompting in bundle init #971
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
Changes from all commits
d042e57
2454bfb
228554a
dc1d074
b185f28
bf7db07
d691aa1
77bc75d
88ba1dd
31b55cb
13986bf
1fae053
55b5e8b
90c6851
e681a91
348d9ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ func TestSchemaLoadIntegers(t *testing.T) { | |
| assert.NoError(t, err) | ||
| assert.Equal(t, int64(1), schema.Properties["abc"].Default) | ||
| assert.Equal(t, []any{int64(1), int64(2), int64(3)}, schema.Properties["abc"].Enum) | ||
| assert.Equal(t, int64(5), schema.Properties["def"].Const) | ||
| } | ||
|
|
||
| func TestSchemaLoadIntegersWithInvalidDefault(t *testing.T) { | ||
|
|
@@ -60,6 +61,11 @@ func TestSchemaLoadIntegersWithInvalidEnums(t *testing.T) { | |
| assert.EqualError(t, err, "failed to parse enum value 2.4 at index 1 for property abc: expected integer value, got: 2.4") | ||
| } | ||
|
|
||
| func TestSchemaLoadIntergersWithInvalidConst(t *testing.T) { | ||
| _, err := Load("./testdata/schema-load-int/schema-invalid-const.json") | ||
| assert.EqualError(t, err, "failed to parse const value for property def: expected integer value, got: 5.1") | ||
| } | ||
|
|
||
| func TestSchemaValidateDefaultType(t *testing.T) { | ||
| invalidSchema := &Schema{ | ||
| Properties: map[string]*Schema{ | ||
|
|
@@ -250,3 +256,52 @@ func TestValidateSchemaMinimumCliVersion(t *testing.T) { | |
| err = s.validateSchemaMinimumCliVersion("v0.0.0-dev")() | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestValidateSchemaConstTypes(t *testing.T) { | ||
| s := &Schema{ | ||
| Properties: map[string]*Schema{ | ||
| "foo": { | ||
| Type: "string", | ||
| Const: "abc", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are valid types for Const? Only strings and integers?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Const can be any type, including null or objects according to the JSON schema spec: https://json-schema.org/draft/2020-12/json-schema-validation#name-const
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For mlops-stacks, we only the capability to validate const strings right now.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shreyas-goenka what if I define the following const, does it work?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried it out. Does not work for float because of precision issues. (5.1 vs 5.099). Also does not work for integers due to type not being correct (basically const is parsed as a float rather than an int). I can fix it in a followup PR. |
||
| }, | ||
| }, | ||
| } | ||
| err := s.validate() | ||
| assert.NoError(t, err) | ||
|
|
||
| s = &Schema{ | ||
| Properties: map[string]*Schema{ | ||
| "foo": { | ||
| Type: "string", | ||
| Const: 123, | ||
| }, | ||
| }, | ||
| } | ||
| err = s.validate() | ||
| assert.EqualError(t, err, "type validation for const value of property foo failed: expected type string, but value is 123") | ||
| } | ||
|
|
||
| func TestValidateSchemaSkippedPropertiesHaveDefaults(t *testing.T) { | ||
| s := &Schema{ | ||
| Properties: map[string]*Schema{ | ||
| "foo": { | ||
| Type: "string", | ||
| Extension: Extension{SkipPromptIf: &Schema{}}, | ||
| }, | ||
| }, | ||
| } | ||
| err := s.validate() | ||
| assert.EqualError(t, err, "property \"foo\" has a skip_prompt_if clause but no default value") | ||
shreyas-goenka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| s = &Schema{ | ||
| Properties: map[string]*Schema{ | ||
| "foo": { | ||
| Type: "string", | ||
| Default: "abc", | ||
| Extension: Extension{SkipPromptIf: &Schema{}}, | ||
| }, | ||
| }, | ||
| } | ||
| err = s.validate() | ||
| assert.NoError(t, err) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "def": { | ||
| "type": "integer", | ||
| "const": 5.1 | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,10 @@ | |
| "type": "integer", | ||
| "default": 1, | ||
| "enum": [1,2,3] | ||
| }, | ||
| "def": { | ||
| "type": "integer", | ||
| "const": 5 | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.