From ac2408ddddee9bc521a6eba32ce6a55ea22dfd34 Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Wed, 8 May 2019 11:10:06 -0700 Subject: [PATCH] Allow 0 instances in cf manifest --- .../vscode/manifest/yaml/ManifestYmlSchema.java | 3 +-- .../manifest/yaml/ManifestYamlEditorTest.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java index b46df0a74..eaf9a9a0b 100644 --- a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java +++ b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java @@ -34,7 +34,6 @@ import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YTypedPro import org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil; import org.springframework.ide.vscode.commons.yaml.schema.YValueHint; import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema; -import org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraints; import org.yaml.snakeyaml.nodes.Node; import com.google.common.collect.ImmutableList; @@ -202,7 +201,7 @@ public final class ManifestYmlSchema implements YamlSchema { f.yprop("env", t_env), f.yprop("host", t_ne_string), f.yprop("hosts", f.yseq(t_host)), - f.yprop("instances", t_strictly_pos_integer), + f.yprop("instances", t_pos_integer), f.yprop("memory", t_memory), f.yprop("name", t_application_name).isRequired(true), f.yprop("no-hostname", t_boolean), diff --git a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java index c568c508a..a620e9598 100644 --- a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java +++ b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java @@ -134,6 +134,18 @@ public class ManifestYamlEditorTest { "applications|Unknown property" ); } + + @Test public void zeroInstancesIsFine() throws Exception { + //See: https://www.pivotaltracker.com/story/show/165839251 + Editor editor = harness.newEditor( + "applications:\n" + + "- name: some-name\n" + + " instances: -1\n" + + "- name: some-other-name\n" + + " instances: 0" + ); + editor.assertProblems("-1|Value must be positive"); + } @Test public void reconcileStructuralProblems() throws Exception { @@ -167,7 +179,7 @@ public class ManifestYamlEditorTest { ); editor.assertProblems( "- bad sequence|Expecting a 'Memory' but found a 'Sequence'", - "bad: map|Expecting a 'Strictly Positive Integer' but found a 'Map'" + "bad: map|Expecting a 'Positive Integer' but found a 'Map'" ); // Add a structural case for `buildpacks` (old `buildpack` was scalar, but `buildpacks` is sequence) @@ -212,7 +224,7 @@ public class ManifestYamlEditorTest { " disk_quota: -2048M\n" ); editor.assertProblems( - "-3|Value must be at least 1", + "-3|Value must be positive", "-1024M|Negative value is not allowed", "-2048M|Negative value is not allowed" );