TW-52308 add TeamCity version to ssh client version on server
[teamcity/git-plugin.git] / git-tests / src / jetbrains / buildServer / buildTriggers / vcs / git / tests / GitUtilsTest.java
1 /*
2  * Copyright 2000-2014 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package jetbrains.buildServer.buildTriggers.vcs.git.tests;
18
19 import com.intellij.openapi.util.SystemInfo;
20 import jetbrains.buildServer.BaseTestCase;
21 import jetbrains.buildServer.buildTriggers.vcs.git.GitUtils;
22 import jetbrains.buildServer.util.FileUtil;
23 import org.testng.SkipException;
24 import org.testng.annotations.Test;
25
26 import java.io.File;
27
28 import static org.assertj.core.api.BDDAssertions.then;
29
30 /**
31  * @author dmitry.neverov
32  */
33 public class GitUtilsTest extends BaseTestCase {
34
35   @Test
36   public void test_branchRef() {
37     assertEquals("refs/heads/master", GitUtils.expandRef("master"));
38     assertEquals("refs/heads/master", GitUtils.expandRef("refs/heads/master"));
39     assertEquals("refs/remote-run/tw/12345", GitUtils.expandRef("refs/remote-run/tw/12345"));
40   }
41
42
43   @Test
44   public void test_remotesBranchRef() {
45     assertEquals("refs/remotes/origin/master", GitUtils.createRemoteRef("master"));
46     assertEquals("refs/remotes/origin/master", GitUtils.createRemoteRef("refs/heads/master"));
47     assertEquals("refs/remote-run/tw/12345", GitUtils.createRemoteRef("refs/remote-run/tw/12345"));
48     assertEquals("refs/tags/v1.0", GitUtils.createRemoteRef("refs/tags/v1.0"));
49   }
50
51
52   @Test
53   public void short_file_name_should_not_contain_spaces() throws Exception {
54     if (!SystemInfo.isWindows)
55       throw new SkipException("Windows only test");
56
57     File tmpDir = createTempDir();
58     File dirWithSpaces = new File(tmpDir, "dir with spaces");
59     File fileWithSpaces = new File(dirWithSpaces, "file with spaces");
60     final String content = "content";
61     writeTextToFile(fileWithSpaces, content);
62
63     String shortFileName = GitUtils.getShortFileName(fileWithSpaces);
64     then(shortFileName).doesNotContain(" ");
65     assertTrue("File references by a short name doesn't exist", new File(shortFileName).exists());
66     assertEquals("Short name file content doesn't match", content, FileUtil.readText(new File(shortFileName)));
67   }
68
69
70   @Test
71   public void ssh_client_version() {
72     then(GitUtils.getSshClientVersion("SSH-1.0", "whatever"))
73       .isEqualTo("SSH-1.0");
74     then(GitUtils.getSshClientVersion("SSH-2.0", "TeamCity Server 2017.2.1"))
75       .isEqualTo("SSH-2.0-TeamCity-Server-2017.2.1");
76     then(GitUtils.getSshClientVersion("SSH-2.0-LIB-VERSION", "TeamCity-Server-2017.2.1"))
77       .isEqualTo("SSH-2.0-TeamCity-Server-2017.2.1-LIB-VERSION");
78     then(GitUtils.getSshClientVersion("SSH-2.0-LIB-VERSION", "TeamCity Server 2017.2.1 EAP"))
79       .isEqualTo("SSH-2.0-TeamCity-Server-2017.2.1-EAP-LIB-VERSION");
80   }
81 }