Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1502#discussion_r61792886
  
    --- Diff: 
plugins/outofbandmanagement-drivers/ipmitool/test/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java
 ---
    @@ -0,0 +1,107 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package org.apache.cloudstack.outofbandmanagement.driver.ipmitool;
    +
    +import com.cloud.utils.exception.CloudRuntimeException;
    +import com.google.common.collect.ImmutableMap;
    +import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement;
    +import 
org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse;
    +import org.junit.Assert;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.mockito.runners.MockitoJUnitRunner;
    +
    +import java.util.Arrays;
    +import java.util.List;
    +
    +@RunWith(MockitoJUnitRunner.class)
    +public class IpmitoolWrapperTest {
    +    @Test
    +    public void testParsePowerCommandValid() {
    +        
Assert.assertEquals(IpmitoolWrapper.parsePowerCommand(OutOfBandManagement.PowerOperation.ON),
 "on");
    +        
Assert.assertEquals(IpmitoolWrapper.parsePowerCommand(OutOfBandManagement.PowerOperation.OFF),
 "off");
    +        
Assert.assertEquals(IpmitoolWrapper.parsePowerCommand(OutOfBandManagement.PowerOperation.CYCLE),
 "cycle");
    +        
Assert.assertEquals(IpmitoolWrapper.parsePowerCommand(OutOfBandManagement.PowerOperation.RESET),
 "reset");
    +        
Assert.assertEquals(IpmitoolWrapper.parsePowerCommand(OutOfBandManagement.PowerOperation.SOFT),
 "soft");
    +        
Assert.assertEquals(IpmitoolWrapper.parsePowerCommand(OutOfBandManagement.PowerOperation.STATUS),
 "status");
    +    }
    +
    +    @Test
    +    public void testParsePowerCommandInvalid() {
    +        try {
    +            IpmitoolWrapper.parsePowerCommand(null);
    +            Assert.fail("IpmitoolWrapper.parsePowerCommand failed to throw 
exception on invalid power state");
    +        } catch (IllegalStateException e) {
    +        }
    +    }
    +
    +    @Test
    +    public void testParsePowerState() {
    +        Assert.assertEquals(IpmitoolWrapper.parsePowerState(null), 
OutOfBandManagement.PowerState.Unknown);
    +        Assert.assertEquals(IpmitoolWrapper.parsePowerState(""), 
OutOfBandManagement.PowerState.Unknown);
    +        Assert.assertEquals(IpmitoolWrapper.parsePowerState(" "), 
OutOfBandManagement.PowerState.Unknown);
    +        Assert.assertEquals(IpmitoolWrapper.parsePowerState("invalid 
data"), OutOfBandManagement.PowerState.Unknown);
    +        Assert.assertEquals(IpmitoolWrapper.parsePowerState("Chassis Power 
is on"), OutOfBandManagement.PowerState.On);
    +        Assert.assertEquals(IpmitoolWrapper.parsePowerState("Chassis Power 
is off"), OutOfBandManagement.PowerState.Off);
    +    }
    +
    +    @Test
    +    public void testGetIpmiToolCommandArgs() {
    +        List<String> args = 
IpmitoolWrapper.getIpmiToolCommandArgs("binpath", "intf", "1", null);
    +        assert args != null;
    +        Assert.assertEquals(args.size(), 6);
    +        Assert.assertArrayEquals(args.toArray(), new String[]{"binpath", 
"-I", "intf", "-R", "1", "-v"});
    +
    +        ImmutableMap.Builder<OutOfBandManagement.Option, String> argMap = 
new ImmutableMap.Builder<>();
    +        argMap.put(OutOfBandManagement.Option.DRIVER, "ipmitool");
    +        argMap.put(OutOfBandManagement.Option.ADDRESS, "127.0.0.1");
    +        List<String> argsWithOpts = 
IpmitoolWrapper.getIpmiToolCommandArgs("binpath", "intf", "1", argMap.build(), 
"user", "list");
    +        assert argsWithOpts != null;
    +        Assert.assertEquals(argsWithOpts.size(), 10);
    +        Assert.assertArrayEquals(argsWithOpts.toArray(), new 
String[]{"binpath", "-I", "intf", "-R", "1", "-v", "-H", "127.0.0.1", "user", 
"list"});
    +    }
    +
    +    @Test
    +    public void testFindIpmiUser() {
    +        // Invalid data
    +        try {
    +            IpmitoolWrapper.findIpmiUser("some invalid string\n", "admin");
    +            Assert.fail("IpmitoolWrapper.findIpmiUser failed to throw 
exception on invalid data");
    +        } catch (CloudRuntimeException ignore) {
    +        }
    --- End diff --
    
    Consider splitting the success and failure test cases into separate methods 
with the failure method using the 
``@Test(expected=CloudRuntimeException.class)`` annotation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to