Commit 3d522fc2 authored by Grant Young's avatar Grant Young

Update to guard against git_push missing data

Prevents failure when no git_push data is defined in envs
parent f8b29731
......@@ -46,14 +46,17 @@ export function adjustStageVUs(modifier=1.0) {
return stages;
}
export function checkProjectKeys(project, keys) {
return keys.every(key => Object.prototype.hasOwnProperty.call(project, key));
}
// Returns projects that contain all keys (if passed) or exits if none found
export function getProjects(keys=[]) {
let projects = JSON.parse(__ENV.ENVIRONMENT_PROJECTS);
let check_project_key = (project, keys) => keys.every(key => Object.prototype.hasOwnProperty.call(project, key));
let projects_with_keys = {};
if (Array.isArray(keys) && keys.length > 0) {
projects_with_keys = projects.filter(project => check_project_key(project, keys));
projects_with_keys = projects.filter(project => checkProjectKeys(project, keys));
}
if (projects_with_keys.length == 0) fail('No projects found with required keys for test. Exiting...');
......
......@@ -7,7 +7,7 @@
import http from "k6/http";
import { group, fail } from "k6";
import { Rate } from "k6/metrics";
import { logError, getRpsThresholds, getTtfbThreshold, getProjects, selectProject, adjustRps, adjustStageVUs } from "../../lib/gpt_k6_modules.js";
import { logError, getRpsThresholds, getTtfbThreshold, getProjects, selectProject, checkProjectKeys, adjustRps, adjustStageVUs } from "../../lib/gpt_k6_modules.js";
import { getRefsListGitPush, pushRefsData, checkCommitExists, prepareGitPushData, updateProjectPipelinesSetting } from "../../lib/gpt_git_functions.js";
if (!__ENV.ACCESS_TOKEN) fail('ACCESS_TOKEN has not been set. Skipping...')
......@@ -42,6 +42,7 @@ export function setup() {
// Test should only run if specified commits exist in the project
// Also disable Pipelines for the project during the test to prevent them being triggered en masse.
projects.forEach(project => {
checkProjectKeys(project['git_push_data'], ["branch_current_head_sha","branch_new_head_sha","branch_name"]);
checkCommitExists(project, project['git_push_data']['branch_current_head_sha']);
checkCommitExists(project, project['git_push_data']['branch_new_head_sha']);
updateProjectPipelinesSetting(project, "disabled");
......
......@@ -12,6 +12,8 @@ module GitTest
def prepare_git_push_data(env_vars:)
projects = JSON.parse(env_vars["ENVIRONMENT_PROJECTS"])
projects.each do |project|
return false if project.dig(:git_push_data).nil? || %w[branch_current_head_sha","branch_new_head_sha","branch_name"].all? { |subkey| project["git_push_data"].key?(subkey) }
branch_current_head = project["git_push_data"]["branch_current_head_sha"]
branch_new_head = project["git_push_data"]["branch_new_head_sha"]
branch_name = project["git_push_data"]["branch_name"]
......
......@@ -78,6 +78,14 @@ module RunK6
res.status.success? ? JSON.parse(res.body.to_s) : { "version" => "-", "revision" => "-" }
end
def prepare_tests(tests:, env_vars:)
# Prepare specific test data
git_push_prepare = GitTest.prepare_git_push_data(env_vars: env_vars) unless tests.grep(/git_push/).empty? || env_vars.empty?
tests.reject! { |test| test.include? 'git_push' } unless git_push_prepare
tests
end
def get_tests(k6_dir:, test_paths:, test_excludes: [], quarantined:, scenarios:, read_only:, env_version: '-', env_vars: {})
tests = []
test_paths.each do |test_path|
......@@ -104,9 +112,7 @@ module RunK6
tests.select! { |test| TestInfo.test_is_read_only?(test) } if read_only
tests.select! { |test| TestInfo.test_supported_by_version?(test, env_version) } unless env_version == '-'
GitTest.prepare_git_push_data(env_vars: env_vars) unless tests.grep(/git_push/).empty? || env_vars.empty?
tests
prepare_tests(tests: tests, env_vars: env_vars)
end
def run_k6(k6_path:, env_vars:, options_file:, test_file:, gpt_version:)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment