1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/com/sap/piper/BashUtilsTest.groovy

48 lines
1.5 KiB
Groovy
Raw Normal View History

package com.sap.piper
import org.junit.Assert
import org.junit.Test
class BashUtilsTest {
@Test
void escapeFilePath() {
// Given: A Windows-style file path C:\some\path
def input = 'C:\\some\\path'
// When we escape the string
def result = BashUtils.quoteAndEscape(input)
// Then the string is surrounded by single quotes 'C:\some\path'
def expected = "'C:\\some\\path'"
Assert.assertEquals(expected, result)
}
@Test
void escapeUri() {
// Given: An URI with single quotes values http://www.sap.com?$filter='234'
def input = "http://www.sap.com?\$filter='234'"
// When we escape the string
def result = BashUtils.quoteAndEscape(input)
// Then the input string is surrounded by single quotes and each original ' is replaced by '"'"'
// 'http://www.sap.com?$filter='"'"'234'"'"''
def expected = "'http://www.sap.com?\$filter='\"'\"'234'\"'\"''"
Assert.assertEquals(expected, result)
}
@Test
void escapePassword() {
// Given: A random generated password VQ5r\%*h"49'Ch>Jj?
def input = "VQ5r\\%*h\"49'Ch>Jj?"
// When we escape the string
def result = BashUtils.quoteAndEscape(input)
// Then the input string is surrounded by single quotes and each original ' is replaced by '"'"'
// 'VQ5r\%*h"49'"'"'Ch>Jj?'
def expected = "'VQ5r\\%*h\"49'\"'\"'Ch>Jj?'"
Assert.assertEquals(expected, result)
}
}