示例#1
0
        public void AbortTaskCheckTestParsArg()
        {
            string taskUuid = "TaskUUID";
            string name     = "NAME";
            string tags     = "TAG1,TAG2";

            string[]          argv = null;
            var               commandLineParser = new CommandLine.Parser();
            CommandLineParser parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration    iConfSet          = null;

            argv     = new string[] { "task", "abort", "--name", name, "--id", taskUuid, "--tags", tags };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is DefaultRunConfiguration))
            {
                throw new Exception("return value is not DefaultRunConfiguration ");
            }

            DefaultRunConfiguration confset = (DefaultRunConfiguration)iConfSet;

            Assert.AreEqual(confset.Type, ConfigType.Task);
            Assert.AreEqual(confset.Command, CommandApi.Abort);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Id, taskUuid);

            argv     = new string[] { "task", "abort", "-n", name, "-i", taskUuid, "-t", tags };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is DefaultRunConfiguration))
            {
                throw new Exception("return value is not DefaultRunConfiguration ");
            }

            confset = (DefaultRunConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Task);
            Assert.AreEqual(confset.Command, CommandApi.Abort);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Id, taskUuid);
            commandLineParser.Dispose();
        }
示例#2
0
        public void CreatePoolFullTestParsArg()
        {
            string[]          argv              = new string[] { "pool", "create", "-n", "name", "-s", "shortname", "-f", string.Empty, "-t", "tag1,tag2", "-c", "constants", "-p", "profile", "-i", "5" };
            string[]          argvFull          = new string[] { "pool", "create", "--name", "name", "--shortname", "shortname", "--file", string.Empty, "--tags", "tag1,tag2", "--constants", "constants", "--profile", "profile", "--instanceNodes", "5" };
            var               commandLineParser = new CommandLine.Parser();
            CommandLineParser parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration    iConfSet          = parser.Parse(argv);
            IConfiguration    iConfSetFull      = parser.Parse(argvFull);

            if (!(iConfSet is CreateConfiguration) || !(iConfSetFull is CreateConfiguration))
            {
                throw new Exception("return value is not CreateConfiguration ");
            }

            CreateConfiguration confset = (CreateConfiguration)iConfSet;

            Assert.AreEqual(confset.Type, ConfigType.Pool);
            confset = (CreateConfiguration)iConfSetFull;
            Assert.AreEqual(confset.Type, ConfigType.Pool);
            commandLineParser.Dispose();
        }
示例#3
0
        public void TestPrintHelpThrowParsVersionException()
        {
            // https://github.com/commandlineparser/commandline/blob/master/src/CommandLine/Error.cs
            var commandLineParser           = new CommandLine.Parser();
            CommandLineParser     parserObj = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            ParseVersionException ex        = null;
            ParserUsage           helpUsage = new ParserUsage();

            string[] argv = new string[] { "--version" };

            var parser = commandLineParser.ParseArguments <Options.DefaultJob>(argv);

            List <CommandLine.Error> errs = new List <CommandLine.Error>();

            CommandLine.Error err = new CommandLineWrapError(CommandLine.ErrorType.VersionRequestedError);
            errs.Add(err);

            ex = Assert.Throws <ParseVersionException>(() => helpUsage.PrintHelp(parser, errs, argv));
            Assert.IsNotNull(ex);
            commandLineParser.Dispose();
        }
示例#4
0
        public void RemoveBucketFileOptionsCheckTestParsArg()
        {
            string name = "NAME";
            string path = "path";

            string[]            argv = null;
            var                 commandLineParser = new CommandLine.Parser();
            CommandLineParser   parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration      iConfSet          = null;
            BucketConfiguration confset           = null;

            argv     = new string[] { "bucket", "delete", "--name", name, path };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = iConfSet as BucketConfiguration;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.Remove);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.RemoteRelativePaths[0], path);

            argv     = new string[] { "bucket", "delete", "-n", name, path };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.Remove);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.RemoteRelativePaths[0], path);
            commandLineParser.Dispose();
        }
示例#5
0
        public void SyncToBucketOptionsCheckTestParsArg()
        {
            string name  = "NAME";
            string local = "Local-path";

            string[]            argv = null;
            var                 commandLineParser = new CommandLine.Parser();
            CommandLineParser   parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration      iConfSet          = null;
            BucketConfiguration confset           = null;

            argv     = new string[] { "bucket", "sync-to", "--name", name, "--local-path", local };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.SyncTo);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.LocalPathGet, local);

            argv     = new string[] { "bucket", "sync-to", "-n", name, "-l", local };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.SyncTo);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.LocalPathGet, local);
            commandLineParser.Dispose();
        }
示例#6
0
        public void DeleteJobCheckTestParsArg()
        {
            string jobUuid = "JobUUID";
            string name    = "NAME";

            string[]          argv = null;
            var               commandLineParser = new CommandLine.Parser();
            CommandLineParser parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration    iConfSet          = null;

            argv     = new string[] { "job", "delete", "--name", name, "--id", jobUuid };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is DefaultRunConfiguration))
            {
                throw new Exception("return value is not DefaultRunConfiguration ");
            }

            DefaultRunConfiguration confset = (DefaultRunConfiguration)iConfSet;

            Assert.AreEqual(confset.Type, ConfigType.Job);
            Assert.AreEqual(confset.Command, CommandApi.Delete);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Id, jobUuid);

            argv     = new string[] { "job", "delete", "-n", name, "-i", jobUuid };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is DefaultRunConfiguration))
            {
                throw new Exception("return value is not DefaultRunConfiguration ");
            }

            confset = (DefaultRunConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Job);
            Assert.AreEqual(confset.Command, CommandApi.Delete);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Id, jobUuid);
            commandLineParser.Dispose();
        }
示例#7
0
        public void GetBucketOptionsCheckTestParsArg()
        {
            string name   = "NAME";
            string folder = "/my/folder/";

            string[]            argv = null;
            var                 commandLineParser = new CommandLine.Parser();
            CommandLineParser   parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration      iConfSet          = null;
            BucketConfiguration confset           = null;

            argv     = new string[] { "bucket", "get", "--name", name, "--bucket-folder", folder };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.Download);
            Assert.AreEqual(confset.Name, name);

            argv     = new string[] { "bucket", "get", "-n", name, "--bucket-folder", folder };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.Download);
            Assert.AreEqual(confset.Name, name);
            commandLineParser.Dispose();
        }
示例#8
0
        public void CreateBucketOptionsCheckTestParsArg()
        {
            string name = "NAME";
            uint   ttl  = 36000;

            string[]            argv = null;
            var                 commandLineParser = new CommandLine.Parser();
            CommandLineParser   parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration      iConfSet          = null;
            BucketConfiguration confset           = null;

            argv     = new string[] { "bucket", "create", "--name", name, "--ttl", ttl.ToString() };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(ttl, confset.CacheTTL);

            argv     = new string[] { "bucket", "create", "-n", name };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Name, name);
            Assert.IsNull(confset.CacheTTL);
            commandLineParser.Dispose();
        }
示例#9
0
        public void CreateTaskCheckTestParsArg()
        {
            string name      = "NAME";
            string shortname = "SHORT";
            string range     = "1-5";
            string instance  = "42";
            string profile   = "PROFILE";

            string[] tags        = new[] { "TAG1", "TAG2", "TAG3" };
            string[] constants   = new[] { "CONSTANT" };
            string[] constraints = new[] { "CONSTRAINTS" };
            string   periodic    = "5";
            string   whitelist   = "white*";
            string   blacklist   = "black*";

            string[]          argv = null;
            var               commandLineParser = new CommandLine.Parser();
            CommandLineParser parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration    iConfSet          = null;

            argv     = new string[] { "task", "create", "--name", name, "--shortname", shortname, "--instance", instance, "--profile", profile, "--tags", tags[0], tags[1], tags[2], "--constants", constants[0], "--constraints", constraints[0], "--wait-for-resources-synchronization", "true", "--periodic", periodic, "--whitelist", whitelist, "--blacklist", blacklist };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is CreateConfiguration))
            {
                throw new Exception("return value is not CreateConfiguration ");
            }

            CreateConfiguration confset = (CreateConfiguration)iConfSet;

            Assert.AreEqual(confset.Type, ConfigType.Task);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Shortname, shortname);
            Assert.AreEqual(confset.Profile, profile);
            CollectionAssert.AreEqual(confset.Tags, tags);
            CollectionAssert.AreEqual(confset.Constants, constants);
            CollectionAssert.AreEqual(confset.Constraints, constraints);
            Assert.AreEqual(confset.InstanceCount, int.Parse(instance));
            Assert.AreEqual(confset.WaitForPoolResourcesSynchronization, true);
            Assert.AreEqual(confset.SnapshotPeriodicSec.ToString(), periodic);
            Assert.AreEqual(confset.Whitelist, whitelist);
            Assert.AreEqual(confset.Blacklist, blacklist);

            argv     = new string[] { "task", "create", "--name", name, "--shortname", shortname, "--range", range, "--profile", profile, "--tags", tags[0], tags[1], tags[2], "--constants", constants[0], "--wait-for-resources-synchronization", "false", "--periodic", periodic, "--whitelist", whitelist, "--blacklist", blacklist };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is CreateConfiguration))
            {
                throw new Exception("return value is not CreateConfiguration ");
            }

            confset = (CreateConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Task);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Shortname, shortname);
            Assert.AreEqual(confset.Profile, profile);
            CollectionAssert.AreEqual(confset.Tags, tags);
            CollectionAssert.AreEqual(confset.Constants, constants);
            Assert.AreEqual(confset.Range, range);
            Assert.AreEqual(confset.WaitForPoolResourcesSynchronization, false);
            Assert.AreEqual(confset.SnapshotPeriodicSec.ToString(), periodic);
            Assert.AreEqual(confset.Whitelist, whitelist);
            Assert.AreEqual(confset.Blacklist, blacklist);

            argv     = new string[] { "task", "create", "-n", name, "-s", shortname, "-i", instance, "-p", profile, "-t", tags[0], tags[1], tags[2], "-c", constants[0], "--periodic", periodic, "--whitelist", whitelist, "--blacklist", blacklist };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is CreateConfiguration))
            {
                throw new Exception("return value is not CreateConfiguration ");
            }

            confset = (CreateConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Task);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Shortname, shortname);
            Assert.AreEqual(confset.Profile, profile);
            CollectionAssert.AreEqual(confset.Tags, tags);
            CollectionAssert.AreEqual(confset.Constants, constants);
            Assert.AreEqual(confset.InstanceCount, int.Parse(instance));
            Assert.AreEqual(confset.WaitForPoolResourcesSynchronization, null);
            Assert.AreEqual(confset.SnapshotPeriodicSec.ToString(), periodic);
            Assert.AreEqual(confset.Whitelist, whitelist);
            Assert.AreEqual(confset.Blacklist, blacklist);
            commandLineParser.Dispose();
        }
示例#10
0
        public void CreatePoolCheckTestParsArg()
        {
            string name      = "NAME";
            string shortname = "SHORT";
            string instance  = "42";
            string profile   = "PROFILE";

            string[] tags        = new[] { "TAG1", "TAG2", "TAG3" };
            string[] constants   = new[] { "CONSTANT" };
            string[] constraints = new[] { "CONSTRAINTS" };
            uint     defaultTTL  = 36000;

            string[]          argv = null;
            var               commandLineParser = new CommandLine.Parser();
            CommandLineParser parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration    iConfSet          = null;

            argv     = new string[] { "pool", "create", "--name", name, "--shortname", shortname, "--instanceNodes", instance, "--profile", profile, "--tags", tags[0], tags[1], tags[2], "--constants", constants[0], "--constraints", constraints[0], "--tasks-wait-for-synchronization", "false" };
            argv     = new string[] { "pool", "create", "--name=" + name, "--shortname=" + shortname, "--instanceNodes=" + instance, "--profile=" + profile, "--tags=" + tags[0], tags[1], tags[2], "--constants=" + constants[0], "--constraints=" + constraints[0], "--tasks-wait-for-synchronization", "true", "--export-credentials-to-env", "true", "--ttl", defaultTTL.ToString() };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is CreateConfiguration))
            {
                throw new Exception("return value is not CreateConfiguration ");
            }

            CreateConfiguration confset = (CreateConfiguration)iConfSet;

            Assert.AreEqual(confset.Type, ConfigType.Pool);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Shortname, shortname);
            Assert.AreEqual(confset.Profile, profile);
            CollectionAssert.AreEqual(confset.Tags, tags);
            CollectionAssert.AreEqual(confset.Constants, constants);
            CollectionAssert.AreEqual(confset.Constraints, constraints);
            Assert.AreEqual(confset.InstanceCount, 42);
            Assert.AreEqual(confset.TasksDefaultWaitForPoolResourcesSynchronization, true);
            Assert.AreEqual(true, confset.ExportApiAndStorageCredentialsInEnvironment);
            Assert.AreEqual(defaultTTL, confset.DefaultResourcesCacheTTLSec);

            argv     = new string[] { "pool", "create", "-n", name, "-s", shortname, "-i", instance, "-p", profile, "-t", tags[0], tags[1], tags[2], "-c", constants[0] };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is CreateConfiguration))
            {
                throw new Exception("return value is not CreateConfiguration ");
            }

            confset = (CreateConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Pool);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Shortname, shortname);
            Assert.AreEqual(confset.Profile, profile);
            CollectionAssert.AreEqual(confset.Tags, tags);
            CollectionAssert.AreEqual(confset.Constants, constants);
            Assert.AreEqual(confset.InstanceCount, 42);
            Assert.AreEqual(confset.TasksDefaultWaitForPoolResourcesSynchronization, false);
            Assert.IsNull(confset.ExportApiAndStorageCredentialsInEnvironment);
            Assert.IsNull(confset.DefaultResourcesCacheTTLSec);
            commandLineParser.Dispose();
        }