Search in sources :

Example 1 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-powershell by JetBrains.

the class CommandLineProviderTest method testUseDefaultPowerShellIfVersionAny.

@SuppressWarnings({ "ResultOfMethodCallIgnored" })
@Test
@TestFor(issues = "TW-34557")
public void testUseDefaultPowerShellIfVersionAny() throws Exception {
    final Map<String, String> runnerParams = new HashMap<>();
    final Map<String, String> sharedConfigParams = new HashMap<>();
    m.checking(new Expectations() {

        {
            allowing(myInfo).getExecutablePath();
            will(returnValue("executablePath"));
            never(myInfo).getVersion();
        }
    });
    final List<String> result = myProvider.provideCommandLine(myInfo, runnerParams, myScriptFile, false, sharedConfigParams);
    for (String str : result) {
        if ("-Version".equals(str)) {
            fail("PowerShell version should not be supplied if Any is selected in runner parameters");
        }
    }
}
Also used : Expectations(org.jmock.Expectations) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 2 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-powershell by JetBrains.

the class ScriptGeneratorTest method generateScript_FILE_WorkingDir.

@Test
@TestFor(issues = "TW-66762")
public void generateScript_FILE_WorkingDir() throws Exception {
    final String fileName = "script.ps1";
    final Map<String, String> runnerParams = new HashMap<>();
    runnerParams.put(PowerShellConstants.RUNNER_MIN_VERSION, "1.0");
    runnerParams.put(PowerShellConstants.RUNNER_EXECUTION_MODE, PowerShellExecutionMode.PS1.getValue());
    runnerParams.put(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
    // set working directory
    File scriptFile = new File(myWorkingDir, fileName);
    registerAsTempFile(scriptFile);
    FileUtil.writeFile(scriptFile, "Write-Output \"works\"", "UTF-8");
    runnerParams.put(PowerShellConstants.RUNNER_SCRIPT_FILE, fileName);
    final File resultingScript = myGenerator.generateScript(runnerParams, myCheckoutDir, myTempDir, myWorkingDir);
    assertEquals(scriptFile.getAbsolutePath(), resultingScript.getAbsolutePath());
}
Also used : HashMap(java.util.HashMap) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 3 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-powershell by JetBrains.

the class ScriptGeneratorTest method testGenerateScript_FILE_Exists.

@Test
@TestFor(issues = "TW-49208")
public void testGenerateScript_FILE_Exists() throws Exception {
    final String fileName = "script.ps1";
    final Map<String, String> runnerParams = new HashMap<>();
    runnerParams.put(PowerShellConstants.RUNNER_MIN_VERSION, "1.0");
    runnerParams.put(PowerShellConstants.RUNNER_EXECUTION_MODE, PowerShellExecutionMode.PS1.getValue());
    runnerParams.put(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
    File scriptFile = new File(myCheckoutDir, fileName);
    registerAsTempFile(scriptFile);
    FileUtil.writeFile(scriptFile, "Write-Output \"works\"", "UTF-8");
    runnerParams.put(PowerShellConstants.RUNNER_SCRIPT_FILE, fileName);
    final File resultingScript = myGenerator.generateScript(runnerParams, myCheckoutDir, myTempDir, myWorkingDir);
    assertEquals(scriptFile.getAbsolutePath(), resultingScript.getAbsolutePath());
}
Also used : HashMap(java.util.HashMap) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 4 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-powershell by JetBrains.

the class PowerShellRunTypeTest method testGenerateAnyBitnessRequirement_NoMinVersion.

@Test
@TestFor(issues = "TW-44808")
public void testGenerateAnyBitnessRequirement_NoMinVersion() {
    final Map<String, String> input = createDummyParameters(null);
    final Collection<Requirement> requirements = runType.getRunnerSpecificRequirements(input);
    assertEquals(1, requirements.size());
    final Requirement r = requirements.iterator().next();
    assertEquals("Exists=>(powershell_Core_x86|powershell_Core_x64|powershell_Desktop_x86|powershell_Desktop_x64)", r.getPropertyName());
    assertNull(r.getPropertyValue());
    assertEquals(RequirementType.EXISTS, r.getType());
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 5 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-powershell by JetBrains.

the class PowerShellIntegrationTests method testShouldWriteBOMinExternalFileMode.

@SuppressWarnings("TestMethodWithIncorrectSignature")
@Test(dataProvider = "supportedBitnessProvider")
@TestFor(issues = "TW-44082")
public void testShouldWriteBOMinExternalFileMode(@NotNull final PowerShellBitness bits) throws Throwable {
    setRunnerParameter(PowerShellConstants.RUNNER_EXECUTION_MODE, PowerShellExecutionMode.PS1.getValue());
    setRunnerParameter(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.CODE.getValue());
    setRunnerParameter(PowerShellConstants.RUNNER_SCRIPT_CODE, "$var = \"Value is \u00f8\u00e5\u00e6\"\r\n Write-Output $var\r\n");
    setRunnerParameter(PowerShellConstants.RUNNER_BITNESS, bits.getValue());
    setBuildConfigurationParameter(PowerShellConstants.CONFIG_KEEP_GENERATED, "true");
    final SFinishedBuild build = doTest(null);
    assertEquals(1, getTempFiles().length);
    final File generatedScript = getTempFiles()[0];
    try (InputStreamReader reader = new InputStreamReader(new FileInputStream(generatedScript), FILES_ENCODING)) {
        char[] buf = new char[1];
        assertEquals(1, reader.read(buf));
        assertEquals("BOM is not written to external file", '\ufeff', buf[0]);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    final String fileContents = FileUtil.readText(getTempFiles()[0], FILES_ENCODING);
    assertTrue("Non-ASCII symbols were not written to generated script", fileContents.contains("\u00f8\u00e5\u00e6"));
    dumpBuildLogLocally(build);
    Assert.assertTrue(build.getBuildStatus().isSuccessful());
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

TestFor (jetbrains.buildServer.util.TestFor)129 Test (org.testng.annotations.Test)81 File (java.io.File)65 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)56 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)26 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)21 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)17 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)12 VcsException (jetbrains.buildServer.vcs.VcsException)11 URIish (org.eclipse.jgit.transport.URIish)11 Repository (org.eclipse.jgit.lib.Repository)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)7 AfterMethod (org.testng.annotations.AfterMethod)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GitTestUtil.copyRepository (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository)6 Build (jetbrains.buildServer.server.rest.model.build.Build)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)6