Ejemplo n.º 1
0
        public void LogModeRollBySizeTime()
        {
            const string yaml = @"
id: service.exe
name: Service
description: The Service.
executable: node.exe
log:
    logpath: c:\\
    mode: roll-by-size-time
    sizeThreshold: 10240
    pattern: yyyy-MM-dd
    autoRollAtTime: 00:00:00";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            serviceDescriptor.BaseName = "service";

            var logHandler = serviceDescriptor.Log.CreateLogHandler() as RollingSizeTimeLogAppender;

            Assert.That(logHandler, Is.Not.Null);
            Assert.That(logHandler.SizeTheshold, Is.EqualTo(10240 * 1024));
            Assert.That(logHandler.FilePattern, Is.EqualTo("yyyy-MM-dd"));
            Assert.That(logHandler.AutoRollAtTime, Is.EqualTo((TimeSpan?)new TimeSpan(0, 0, 0)));
        }
Ejemplo n.º 2
0
        public void Priority()
        {
            var sd = ServiceDescriptorYaml.FromYaml(@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
priority: normal").Configurations;

            Assert.That(sd.Priority, Is.EqualTo(ProcessPriorityClass.Normal));

            sd = ServiceDescriptorYaml.FromYaml(@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
priority: idle").Configurations;
            Assert.That(sd.Priority, Is.EqualTo(ProcessPriorityClass.Idle));

            sd = ServiceDescriptorYaml.FromYaml(@"
id: service.exe
name: Service
description: The Service.
executable: node.exe").Configurations;
            Assert.That(sd.Priority, Is.EqualTo(ProcessPriorityClass.Normal));
        }
Ejemplo n.º 3
0
        public void Default_value_map_test()
        {
            var configs = ServiceDescriptorYaml.FromYaml(MinimalYaml).Configurations;

            Assert.IsNotNull(configs.ExecutablePath);
            Assert.IsNotNull(configs.BaseName);
            Assert.IsNotNull(configs.BasePath);
        }
Ejemplo n.º 4
0
        public void Simple_yaml_parsing_test()
        {
            var configs = ServiceDescriptorYaml.FromYaml(MinimalYaml).Configurations;

            Assert.AreEqual("myapp", configs.Id);
            Assert.AreEqual("This is a test", configs.Caption);
            Assert.AreEqual("C:\\Program Files\\Java\\jdk1.8.0_241\\bin\\java.exe", configs.Executable);
            Assert.AreEqual("This is test winsw", configs.Description);
        }
Ejemplo n.º 5
0
        public void Parse_must_implemented_value_test()
        {
            var yml = @"name: This is a test
executable: 'C:\Program Files\Java\jdk1.8.0_241\bin\java.exe'
description: This is test winsw";

            Assert.That(() =>
            {
                _ = ServiceDescriptorYaml.FromYaml(yml).Configurations.Id;
            }, Throws.TypeOf <InvalidOperationException>());
        }
Ejemplo n.º 6
0
        public void Must_Specify_Values_Test()
        {
            string yml = @"
name: This is a test
executable: 'C:\Program Files\Java\jdk1.8.0_241\bin\java.exe'
description: This is test winsw";

            Assert.That(() =>
            {
                _ = ServiceDescriptorYaml.FromYaml(yml).Configurations.Id;
            }, Throws.TypeOf <InvalidOperationException>());
        }
Ejemplo n.º 7
0
        public void CanParseStopTimeout()
        {
            const string yaml = @"id: service.exe
name: Service
description: The Service.
executable: node.exe
stopTimeout: 60sec";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.StopTimeout, Is.EqualTo(TimeSpan.FromSeconds(60)));
        }
Ejemplo n.º 8
0
        public void CanParseStopParentProcessFirst()
        {
            const string yaml = @"
id: service.exe
name: Service
description: The Service.
executable: node.exe
stopParentProcessFirst: false";
            var          serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.StopParentProcessFirst, Is.False);
        }
Ejemplo n.º 9
0
        public void IncorrectStartMode()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
arguments: My Arguments
startMode: roll";

            this._extendedServiceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;
            Assert.That(() => this._extendedServiceDescriptor.StartMode, Throws.ArgumentException);
        }
Ejemplo n.º 10
0
        public void DelayedStart_RoundTrip(bool enabled)
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
delayedAutoStart: true";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.DelayedAutoStart, Is.EqualTo(true));
        }
Ejemplo n.º 11
0
        public void Arguments_LegacyParam()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
arguments: arg";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.Arguments, Is.EqualTo("arg"));
        }
Ejemplo n.º 12
0
        public void VerifyResetFailureAfter()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
resetFailureAfter: 75 sec";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.ResetFailureAfter, Is.EqualTo(TimeSpan.FromSeconds(75)));
        }
Ejemplo n.º 13
0
        public void VerifySleepTime()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
sleepTime: 3 hrs";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.SleepTime, Is.EqualTo(TimeSpan.FromHours(3)));
        }
Ejemplo n.º 14
0
        public void VerifyWaitHint()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
waitHint: 20 min";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.WaitHint, Is.EqualTo(TimeSpan.FromMinutes(20)));
        }
Ejemplo n.º 15
0
        public void Service_account_not_specified_test()
        {
            var yml = @"id: jenkins
name: No Service Account
";

            var configs = ServiceDescriptorYaml.FromYaml(yml).Configurations;

            Assert.DoesNotThrow(() =>
            {
                var serviceAccount = configs.ServiceAccount.AllowServiceAcountLogonRight;
            });
        }
Ejemplo n.º 16
0
        public void ChangedStartMode()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
arguments: My Arguments
startMode: manual";

            this._extendedServiceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;
            Assert.That(this._extendedServiceDescriptor.StartMode, Is.EqualTo(StartMode.Manual));
        }
Ejemplo n.º 17
0
        public void Download_not_specified_test()
        {
            var yml = @"id: jenkins
name: No Service Account
";

            var configs = ServiceDescriptorYaml.FromYaml(yml).Configurations;

            Assert.DoesNotThrow(() =>
            {
                var dowloads = configs.Downloads;
            });
        }
Ejemplo n.º 18
0
        public void Must_implemented_value_test()
        {
            string yml = @"caption: This is a test
executable: 'C:\Program Files\Java\jdk1.8.0_241\bin\java.exe'
description: This is test winsw";

            void getId()
            {
                var id = ServiceDescriptorYaml.FromYaml(yml).Configurations.Id;
            }

            Assert.That(() => getId(), Throws.TypeOf <InvalidOperationException>());
        }
Ejemplo n.º 19
0
        public void CanParseErrfilePattern()
        {
            const string yaml = @"
id: service.exe
name: Service
description: The Service.
executable: node.exe
log:
    errFilePattern: .err.test.log";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.Log.ErrFilePattern, Is.EqualTo(".err.test.log"));
        }
Ejemplo n.º 20
0
        public void CanParseErrfileDisabled()
        {
            const string yaml = @"
id: service.exe
name: Service
description: The Service.
executable: node.exe
log:
    errFileDisabled: true";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.Log.ErrFileDisabled, Is.True);
        }
Ejemplo n.º 21
0
        public void CanParseLogname()
        {
            const string yaml = @"
id: service.exe
name: Service
description: The Service.
executable: node.exe
log:
    name: MyTestApp";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.Log.Name, Is.EqualTo("MyTestApp"));
        }
Ejemplo n.º 22
0
        public void Parse_log()
        {
            var yml = @"id: myapp
name: winsw
description: yaml test
executable: java
log:
    mode: roll
    logpath: 'D://winsw/logs'";

            var config = ServiceDescriptorYaml.FromYaml(yml).Configurations;

            Assert.AreEqual("roll", config.LogMode);
            Assert.AreEqual("D://winsw/logs", config.LogDirectory);
        }
Ejemplo n.º 23
0
        public void VerifyServiceLogonRightOmitted()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
serviceaccount:
    domain: {Domain}
    user: {Username}
    password: {Password}";

            var serviceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;

            Assert.That(serviceDescriptor.ServiceAccount.AllowServiceAcountLogonRight, Is.False);
        }
Ejemplo n.º 24
0
        public void Simple_download_parsing_test()
        {
            var yml = @"download:
    -
        from: www.sample.com
        to: c://tmp
    -
        from: www.sample2.com
        to: d://tmp
    -
        from: www.sample3.com
        to: d://temp";

            var configs = ServiceDescriptorYaml.FromYaml(yml).Configurations;

            Assert.AreEqual(3, configs.Downloads.Count);
        }
Ejemplo n.º 25
0
        public void Service_account_specified_but_fields_not_specified()
        {
            var yml = @"id: jenkins
name: No Service Account
serviceaccount:
  user: testuser
";

            var configs = ServiceDescriptorYaml.FromYaml(yml).Configurations;

            Assert.DoesNotThrow(() =>
            {
                var user       = configs.ServiceAccount.ServiceAccountUser;
                var password   = configs.ServiceAccount.ServiceAccountPassword;
                var allowLogon = configs.ServiceAccount.AllowServiceAcountLogonRight;
                var hasAccount = configs.ServiceAccount.HasServiceAccount();
            });
        }
Ejemplo n.º 26
0
        public void SetUp()
        {
            string seedXml =
                $@"<service>
  <id>SERVICE_NAME</id>
  <name>Jenkins Slave</name>
  <description>This service runs a slave for Jenkins continuous integration system.</description>
  <executable>C:\Program Files\Java\jre7\bin\java.exe</executable>
  <arguments>-Xrs  -jar \""%BASE%\slave.jar\"" -jnlpUrl ...</arguments>
  <log mode=""roll""></log>
  <extensions>
    <extension enabled=""true"" className=""{this.testExtension}"" id=""killRunawayProcess"">
      <pidfile>foo/bar/pid.txt</pidfile>
      <stopTimeout>5000</stopTimeout>
      <stopParentFirst>true</stopParentFirst>
    </extension>
  </extensions>
</service>";

            this._testServiceDescriptor = ServiceDescriptor.FromXML(seedXml);

            string seedYaml = $@"---
id: jenkins
name: Jenkins
description: This service runs Jenkins automation server.
env:
    -
        name: JENKINS_HOME
        value: '%LocalAppData%\Jenkins.jenkins'
executable: java
arguments: >-
    -Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle
    -jar E:\Winsw Test\yml6\jenkins.war --httpPort=8081
extensions:
    - id: killRunawayProcess
      enabled: yes
      className: ""{this.testExtension}""
      settings:
            pidfile: 'foo/bar/pid.txt'
            stopTimeOut: 5000
            StopParentFirst: true";

            this._testServiceDescriptorYaml = ServiceDescriptorYaml.FromYaml(seedYaml).Configurations;
        }
Ejemplo n.º 27
0
        public void Parse_downloads()
        {
            var yml = @"download:
    -
        from: www.sample.com
        to: c://tmp
    -
        from: www.sample2.com
        to: d://tmp
    -
        from: www.sample3.com
        to: d://temp";

            var configs = ServiceDescriptorYaml.FromYaml(yml).Configurations;

            Assert.AreEqual(3, configs.Downloads.Count);
            Assert.AreEqual("www.sample.com", configs.Downloads[0].From);
            Assert.AreEqual("c://tmp", configs.Downloads[0].To);
        }
Ejemplo n.º 28
0
        public void Parse_serviceaccount()
        {
            var yml = @"id: myapp
name: winsw
description: yaml test
executable: java
serviceaccount:
    user: testuser
    domain: mydomain
    password: pa55w0rd
    allowservicelogon: yes";

            var serviceAccount = ServiceDescriptorYaml.FromYaml(yml).Configurations.ServiceAccount;

            Assert.AreEqual("mydomain\\testuser", serviceAccount.ServiceAccountUser);
            Assert.AreEqual(true, serviceAccount.AllowServiceAcountLogonRight);
            Assert.AreEqual("pa55w0rd", serviceAccount.ServiceAccountPassword);
            Assert.AreEqual(true, serviceAccount.HasServiceAccount());
        }
Ejemplo n.º 29
0
        public void Parse_environment_variables()
        {
            var yml = @"id: myapp
name: WinSW
executable: java
description: env test
env:
    -
        name: MY_TOOL_HOME
        value: 'C:\etc\tools\myTool'
    -
        name: LM_LICENSE_FILE
        value: host1;host2";

            var envs = ServiceDescriptorYaml.FromYaml(yml).Configurations.EnvironmentVariables;

            Assert.That(@"C:\etc\tools\myTool", Is.EqualTo(envs["MY_TOOL_HOME"]));
            Assert.That("host1;host2", Is.EqualTo(envs["LM_LICENSE_FILE"]));
        }
Ejemplo n.º 30
0
        public void SetUp()
        {
            string yaml = $@"
id: service.exe
name: Service
description: The Service.
executable: node.exe
arguments: My Arguments
log:
    mode: roll
    logpath: c:\logs
serviceaccount:
    domain: {Domain}
    user: {Username}
    password: {Password}
    allowservicelogon: {AllowServiceAccountLogonRight}
workingdirectory: {ExpectedWorkingDirectory}";

            this._extendedServiceDescriptor = ServiceDescriptorYaml.FromYaml(yaml).Configurations;
        }