Skip to content

Commit

Permalink
Исправление замечаний к PR в upstream (firstBitMarksistskaya#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Mar 18, 2024
1 parent a06a5e4 commit 8dc051b
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 44 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ pipeline1C()
* BDD:
* Если в конфигурационном файле проекта не заполнена настройка `bdd` -> `vrunnerSteps`, то автоматически выполняется запуск `vrunner vanessa --settings tools/vrunner.json`.
* YAXUnit:
* Если ваши тесты находятся в расширении YAXUnit, то необходимо указать к путь к этому расширению в формате cfe в `yaxunit` -> `cfe`
* Если ваши тесты находятся в отдельных расширениях, то необходимо (1) скопировать конфиг из текущей библиотеки (`./resources/yaxunit.json`) в свой репозиторий в `./tools/yaxunit.json` и перечислить в нем имена своих расширений. Имена образуются по правилу: `./src/cfe/unit_tests` -> `unit_tests`. И (2) - перечислить эти же имена в `jobConfiguration.json` -> `yaxunit` -> `extensionNames`. Пока что поддерживаются только расширения, выгруженные в формате конфигуратора.
* Необходимо перечислить расширения в `jobConfiguration.json` -> `yaxunit` -> `extensions`. Путь к расширению можно указать либо в виде ссылки на файл cfe, либо в виде пути к исходникам. Пока что поддерживаются только расширения, выгруженные в формате конфигуратора. При переопределении настроек по умолчанию расширение YAXUnit тоже должно быть в этом списке.
* Если ваши тесты находятся в отдельных расширениях, то необходимо скопировать конфиг из текущей библиотеки (`./resources/yaxunit.json`) в свой репозиторий в `./tools/yaxunit.json` и перечислить в нем имена расширений.
* Дымовые тесты:
* Если в репозитории существует файл `tools/vrunner.json`, то запуск дымовых тестов будет выполняться с передачей файла в параметры запуска `vrunner xunit --settings tools/vrunner.json` (`smoke` -> `vrunnerSettings`).
* Если установка локальных зависимостей `opm` установит пакет `add`, то будет использоваться обработка `xddTestRunner.epf` из локальных зависимостей.
Expand Down
8 changes: 6 additions & 2 deletions resources/globalConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@
},
"yaxunit": {
"vrunnerSettings": "./tools/vrunner.json",
"cfe": "https://github.com/bia-technologies/yaxunit/releases/download/23.05/YAXUNIT-23.05.cfe",
"extensionNames": ["YAXUNIT"],
"extensions": [
{
"name":"YAXUNIT",
"src": "https://github.com/bia-technologies/yaxunit/releases/download/23.05/YAXUNIT-23.05.cfe"
}
],
"configPath": "./tools/yaxunit.json",
"publishToAllureReport": false,
"publishToJUnitReport": true
Expand Down
6 changes: 3 additions & 3 deletions resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"yaxunit": {
"type": "boolean",
"description": "Юнит тесты"
"description" : "Запуск YAXUnit тестов включен"
},
"initSteps": {
"type": "boolean",
Expand Down Expand Up @@ -144,7 +144,7 @@
},
"yaxunit": {
"type": "integer",
"description": "Таймаут шага Юнит тестов, в минутах.\n По умолчанию содержит значение 240.\n "
"description" : "Таймаут шага YAXUnit тестов, в минутах.\n По умолчанию содержит значение 240.\n "
},
"sonarqube": {
"type": "integer",
Expand Down Expand Up @@ -301,7 +301,7 @@
"yaxunit": {
"type": "object",
"id": "urn:jsonschema:ru:pulsar:jenkins:library:configuration:YaxunitOptions",
"description": "Настройки юнит тестирования",
"description" : "Настройки YAXUnit",
"properties": {
"vrunnerSettings": {
"type": "string",
Expand Down
2 changes: 2 additions & 0 deletions src/ru/pulsar/jenkins/library/IStepExecutor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface IStepExecutor {

String readFile(String file, String encoding)

void writeFile(String file, String text, String encoding)

boolean fileExists(String file)

void echo(message)
Expand Down
5 changes: 5 additions & 0 deletions src/ru/pulsar/jenkins/library/StepExecutor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class StepExecutor implements IStepExecutor {
steps.readFile encoding: encoding, file: file
}

@Override
void writeFile(String file, String text, String encoding = 'UTF-8') {
steps.writeFile encoding: encoding, file: file, text: text
}

@Override
boolean fileExists(String file) {
steps.fileExists file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ConfigurationReader implements Serializable {
"sonarQubeOptions",
"smokeTestOptions",
"yaxunitOptions",
"extensions",
"syntaxCheckOptions",
"resultsTransformOptions",
"notificationsOptions",
Expand Down Expand Up @@ -150,10 +151,10 @@ class ConfigurationReader implements Serializable {

@NonCPS
private static void mergeYaxunitOptions(YaxunitOptions baseObject, YaxunitOptions objectToMerge) {
if (objectToMerge == null || objectToMerge.extensionNames == null) {
if (objectToMerge == null || objectToMerge.extensions == null) {
return
}
baseObject.extensionNames = objectToMerge.extensionNames.clone()
baseObject.extensions = objectToMerge.extensions.clone()
}

@NonCPS
Expand Down
17 changes: 17 additions & 0 deletions src/ru/pulsar/jenkins/library/configuration/Extension.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.pulsar.jenkins.library.configuration

import com.cloudbees.groovy.cps.NonCPS
import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
class Extension implements Serializable {
String name
String src

@Override
@NonCPS
String toString() {
return name
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class JobConfiguration implements Serializable {
SmokeTestOptions smokeTestOptions;

@JsonProperty("yaxunit")
@JsonPropertyDescription("Настройки юнит тестирования")
@JsonPropertyDescription("Настройки YAXUnit")
YaxunitOptions yaxunitOptions;

@JsonProperty("resultsTransform")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StageFlags implements Serializable {
@JsonPropertyDescription("Дымовые тесты включены")
Boolean smoke

@JsonPropertyDescription("Юнит тесты")
@JsonPropertyDescription("Запуск YAXUnit тестов включен")
Boolean yaxunit

@JsonPropertyDescription("Предварительные шаги инициализации включены")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class TimeoutOptions implements Serializable {
''')
Integer smoke

@JsonPropertyDescription('''Таймаут шага Юнит тестов, в минутах.
@JsonPropertyDescription('''Таймаут шага YAXUnit тестов, в минутах.
По умолчанию содержит значение 240.
''')
Integer yaxunit
Expand Down
19 changes: 9 additions & 10 deletions src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.pulsar.jenkins.library.configuration

import com.cloudbees.groovy.cps.NonCPS
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonPropertyDescription

@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -12,15 +13,14 @@ class YaxunitOptions implements Serializable {
""")
String vrunnerSettings = "./tools/vrunner.json"

@JsonPropertyDescription("""Ссылка на скачивание YAXUnit.
По умолчанию содержит ссылку на официальный релиз версии 23.05.
@JsonProperty("extensions")
@JsonPropertyDescription("""Расширения с тестами.
Массив объектов с полями name и src, где
name - имя расширения
src - путь к расширению (к cfe или к исходникам)
По умолчанию содержит один элемент - YAXUNIT версии 23.05.
""")
String cfe = "https://github.com/bia-technologies/yaxunit/releases/download/23.05/YAXUNIT-23.05.cfe"

@JsonPropertyDescription("""Имена расширений с тестами.
По умолчанию содержит один элемент - YAXUNIT.
""")
String[] extensionNames = ['YAXUNIT']
Extension[] extensions

@JsonPropertyDescription("""Путь к конфигурационному файлу YAXUnit.
По умолчанию содержит значение "./tools/yaxunit.json".
Expand All @@ -42,8 +42,7 @@ class YaxunitOptions implements Serializable {
String toString() {
return "YaxunitTestOptions{" +
"vrunnerSettings='" + vrunnerSettings + '\'' +
", cfe='" + cfe +
", extensionNames='" + extensionNames.toString() +
", extensions='" + extensions +
", configPath='" + configPath +
'}'
}
Expand Down
37 changes: 16 additions & 21 deletions src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.pulsar.jenkins.library.steps

import hudson.FilePath
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.configuration.Extension
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.utils.FileUtils
Expand All @@ -12,8 +13,6 @@ class Yaxunit implements Serializable {

private final JobConfiguration config

private final String yaxunitPath = 'build/out/yaxunit.cfe'

private final String DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE = 'yaxunit.json'

public static final String YAXUNIT_ALLURE_STASH = 'yaxunit-allure'
Expand Down Expand Up @@ -43,45 +42,41 @@ class Yaxunit implements Serializable {
String vrunnerPath = VRunner.getVRunnerPath()
String ibConnection = ' --ibconnection "/F./build/ib"'

// Скачиваем YAXUnit
String pathToYaxunit = "$env.WORKSPACE/$yaxunitPath"
FilePath localPathToYaxunit = FileUtils.getFilePath(pathToYaxunit)
Logger.println("Скачивание YAXUnit в $localPathToYaxunit из ${options.cfe}")
localPathToYaxunit.copyFrom(new URL(options.cfe))

def extCommands = []

// Команда загрузки YAXUnit
def loadYaxunitCommand = VRunner.loadExtCommand("yaxunit")
extCommands << loadYaxunitCommand


// Команды сборки расширений с тестами и их загрузки в ИБ
for (String extension in options.extensionNames) {
if (extension.toUpperCase() == "YAXUNIT") {
continue
for (Extension extension in options.extensions) {
if (extension.src.endsWith('cfe')) {
// Скачиваем расширение
String pathToExtension = "$env.WORKSPACE/build/out/${extension.name}.cfe"
FilePath localPathToExtension = FileUtils.getFilePath(pathToExtension)
Logger.println("Скачивание расширения $extension.name в $localPathToExtension из ${extension.src}")
localPathToExtension.copyFrom(new URL(extension.src))
} else {
// Команда компиляции в cfe
def compileExtCommand = "$vrunnerPath compileexttocfe --src $extension.src --out build/out/${extension.name}.cfe"
extCommands << compileExtCommand
Logger.println("Команда сборки расширения: $compileExtCommand")
}

// Команда компиляции в cfe
def compileExtCommand = "$vrunnerPath compileexttocfe --src ./src/cfe/$extension --out build/out/${extension}.cfe"
extCommands << compileExtCommand
Logger.println("Команда сборки расширения: $compileExtCommand")

// Команда загрузки расширения в ИБ
def loadTestExtCommand = VRunner.loadExtCommand(extension)
def loadTestExtCommand = VRunner.loadExtCommand(extension.name)
extCommands << loadTestExtCommand
Logger.println("Команда загрузки расширения: $loadTestExtCommand")

}

// Готовим конфиг для yaxunit
String yaxunitConfigPath = options.configPath
File yaxunitConfigFile = new File("$env.WORKSPACE/$yaxunitConfigPath")
if (!steps.fileExists(yaxunitConfigPath)) {
def defaultYaxunitConfig = steps.libraryResource DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE
yaxunitConfigFile.write defaultYaxunitConfig
steps.writeFile(options.configPath, defaultYaxunitConfig, 'UTF-8')
}
def yaxunitConfig = yaxunitConfigFile.getCanonicalPath()
def yaxunitConfig = FileUtils.getFilePath(yaxunitConfigPath)

// Команда запуска тестов
String runTestsCommand = "$vrunnerPath run --command RunUnitTests=$yaxunitConfig $ibConnection"
Expand Down
1 change: 1 addition & 0 deletions test/integration/groovy/jobConfigurationTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ class jobConfigurationTest {
rule.assertLogContains("v8version='8.3.12.1500'", run)
rule.assertLogContains("sonarScannerToolName='sonar-scanner'", run)
rule.assertLogContains("initMethod=FROM_SOURCE", run)
rule.assertLogContains("custom_units", run)
}
}
2 changes: 2 additions & 0 deletions test/integration/resources/jobConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"initMethod": "fromSource",
"path": "/src/cfe/тест"
}]
},
"yaxunit": {
}
}
2 changes: 1 addition & 1 deletion vars/pipeline1C.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void call() {
}
}

stage('Юнит тесты') {
stage('YAXUnit тесты') {
agent {
label agent1C
}
Expand Down

0 comments on commit 8dc051b

Please sign in to comment.