Search in sources :

Example 11 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSCommandInterpreterTest method test_inject_path_variable.

@Issue("JENKINS-41947")
@Test
public void test_inject_path_variable() throws Exception {
    NodeJSInstallation installation = mockInstaller();
    NodeJSCommandInterpreter builder = CIBuilderHelper.createMock("test_executable_value", installation, null, new CIBuilderHelper.Verifier() {

        @Override
        public void verify(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws Exception {
            assertFalse("No Environments", build.getEnvironments().isEmpty());
            EnvVars env = build.getEnvironment(listener);
            Assertions.assertThat(env.keySet()).contains(NodeJSConstants.ENVVAR_NODEJS_PATH, NodeJSConstants.ENVVAR_NODEJS_HOME);
            assertEquals(getTestHome(), env.get(NodeJSConstants.ENVVAR_NODEJS_HOME));
            assertEquals(getTestHome(), env.get(NodeJSConstants.ENVVAR_NODE_HOME));
            assertEquals(getTestBin(), env.get(NodeJSConstants.ENVVAR_NODEJS_PATH));
        }
    });
    FreeStyleProject job = j.createFreeStyleProject();
    job.getBuildersList().add(builder);
    j.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) Verifier(jenkins.plugins.nodejs.CIBuilderHelper.Verifier) EnvVars(hudson.EnvVars) TaskListener(hudson.model.TaskListener) Launcher(hudson.Launcher) FreeStyleProject(hudson.model.FreeStyleProject) IOException(java.io.IOException) DetectionFailedException(jenkins.plugins.nodejs.tools.DetectionFailedException) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 12 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSCommandInterpreterTest method mockInstaller.

private NodeJSInstallation mockInstaller() throws IOException, InterruptedException {
    NodeJSInstallation mock = mock(NodeJSInstallation.class);
    when(mock.forNode(any(Node.class), any(TaskListener.class))).then(RETURNS_SELF);
    when(mock.forEnvironment(any(EnvVars.class))).then(RETURNS_SELF);
    when(mock.getName()).thenReturn("mockNode");
    when(mock.getHome()).thenReturn(getTestHome());
    when(mock.getExecutable(any(Launcher.class))).thenReturn(getTestExecutable());
    doCallRealMethod().when(mock).buildEnvVars(any(EnvVars.class));
    return mock;
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) EnvVars(hudson.EnvVars) Node(hudson.model.Node) TaskListener(hudson.model.TaskListener) Launcher(hudson.Launcher)

Example 13 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSBuildWrapperTest method test_inject_path_variable.

@Test
public void test_inject_path_variable() throws Exception {
    FreeStyleProject job = j.createFreeStyleProject("free");
    final Config config = createSetting("my-config-id", "", null);
    NodeJSInstallation installation = spy(new NodeJSInstallation("test", getTestHome(), null));
    doReturn(getTestExecutable()).when(installation).getExecutable(any(Launcher.class));
    doReturn(installation).when(installation).forNode(any(Node.class), any(TaskListener.class));
    doReturn(installation).when(installation).forEnvironment(any(EnvVars.class));
    NodeJSBuildWrapper spy = mockWrapper(installation, config);
    job.getBuildWrappersList().add(spy);
    job.getBuildersList().add(new PathVerifier(installation));
    j.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) EnvVars(hudson.EnvVars) Config(org.jenkinsci.lib.configprovider.model.Config) NPMConfig(jenkins.plugins.nodejs.configfiles.NPMConfig) Node(hudson.model.Node) TaskListener(hudson.model.TaskListener) Launcher(hudson.Launcher) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 14 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSBuildWrapperTest method test_creation_of_config.

@Test
public void test_creation_of_config() throws Exception {
    FreeStyleProject job = j.createFreeStyleProject("free");
    final Config config = createSetting("my-config-id", "email=foo@acme.com", null);
    NodeJSInstallation installation = mockInstaller();
    NodeJSBuildWrapper bw = mockWrapper(installation, config);
    job.getBuildWrappersList().add(bw);
    job.getBuildersList().add(new FileVerifier());
    j.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) FileVerifier(jenkins.plugins.nodejs.VerifyEnvVariableBuilder.FileVerifier) Config(org.jenkinsci.lib.configprovider.model.Config) NPMConfig(jenkins.plugins.nodejs.configfiles.NPMConfig) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 15 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSBuildWrapperTest method mockInstaller.

private NodeJSInstallation mockInstaller() throws Exception {
    NodeJSInstallation mock = mock(NodeJSInstallation.class);
    when(mock.forNode(any(Node.class), any(TaskListener.class))).then(RETURNS_SELF);
    when(mock.forEnvironment(any(EnvVars.class))).then(RETURNS_SELF);
    when(mock.getName()).thenReturn("mockNode");
    when(mock.getHome()).thenReturn(getTestHome());
    when(mock.getExecutable(any(Launcher.class))).thenReturn(getTestExecutable());
    return mock;
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) EnvVars(hudson.EnvVars) Node(hudson.model.Node) TaskListener(hudson.model.TaskListener) Launcher(hudson.Launcher)

Aggregations

NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)17 Test (org.junit.Test)11 FreeStyleProject (hudson.model.FreeStyleProject)10 EnvVars (hudson.EnvVars)9 Launcher (hudson.Launcher)7 Node (hudson.model.Node)7 TaskListener (hudson.model.TaskListener)7 NPMConfig (jenkins.plugins.nodejs.configfiles.NPMConfig)5 IOException (java.io.IOException)4 FilePath (hudson.FilePath)3 Config (org.jenkinsci.lib.configprovider.model.Config)3 Issue (org.jvnet.hudson.test.Issue)3 AbortException (hudson.AbortException)2 File (java.io.File)2 Verifier (jenkins.plugins.nodejs.CIBuilderHelper.Verifier)2 EnvVarVerifier (jenkins.plugins.nodejs.VerifyEnvVariableBuilder.EnvVarVerifier)2 DetectionFailedException (jenkins.plugins.nodejs.tools.DetectionFailedException)2 ConfigFile (org.jenkinsci.lib.configprovider.model.ConfigFile)2 Computer (hudson.model.Computer)1 InstallSourceProperty (hudson.tools.InstallSourceProperty)1