Skip to content

Commit

Permalink
Merge pull request #321 from cncf/feature/automated_release_manager_306
Browse files Browse the repository at this point in the history
Feature/automated release manager 306
  • Loading branch information
nupejosh authored Jul 29, 2020
2 parents 01f1163 + 1227fb8 commit 3517309
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 131 deletions.
23 changes: 20 additions & 3 deletions spec/utils/release_manager_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ describe "ReleaseManager" do

it "'#ReleaseManager::GithubReleaseManager.upsert_release' should return the upserted release and asset response", tags: "release" do
found_release, asset = ReleaseManager::GithubReleaseManager.upsert_release("test_version")
# (asset["errors"]?==nil || (asset["errors"]? && asset["errors"].find |x| {x["code"] =~ /already_exists/})).should be_truthy
if asset
(asset["errors"]?==nil || (asset["errors"]? && asset["errors"][0]["code"] == "already_exists")).should be_truthy
else
(asset).should_not be_nil
end
# (asset["url"]?).should match("https://api.github.com/repos/cncf/cnf-conformance/releases/assets")

end

it "'#ReleaseManager::GithubReleaseManager.upsert_release' should return nil if not on a valid version", tags: "release" do
Expand All @@ -58,5 +55,25 @@ describe "ReleaseManager" do
resp_code = ReleaseManager::GithubReleaseManager.delete_release("test_version")
(resp_code == 204).should be_truthy
end
it "'#ReleaseManager.detached_head?' should return if the head is detached", tags: "release" do
(ReleaseManager.detached_head?).should_not be_nil
end

it "'#ReleaseManager.commit_message_issues' should list previsions releases", tags: "release" do
hash = ReleaseManager.current_hash
issues = ReleaseManager.commit_message_issues("0.0.5", hash)
(issues[0].match(/#/)).should_not be_nil
end

it "'#ReleaseManager.latest_release' should return latest release", tags: "release" do
issues = ReleaseManager.latest_release
# https://github.com/semver/semver/blob/master/semver.md#is-v123-a-semantic-version
(issues.match(/^(.|)(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/)).should_not be_nil
end

it "'#ReleaseManager.issue_title' should return issue title", tags: "release" do
issues = ReleaseManager.issue_title("#318")
(issues.match(/#206 documentation update/)).should_not be_nil
end

end
140 changes: 71 additions & 69 deletions spec/utils/sample_utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -119,100 +119,102 @@ describe "SampleUtils" do
it "'helm_repo_add' should return false if the helm repo is invalid", tags: "happy-path" do
helm_repo_add("invalid", "invalid").should eq(false)
end
end


it "'validate_cnf_conformance_yml' (function) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
args = Sam::Args.new(["cnf-config=sample-cnfs/sample-coredns-cnf/cnf-conformance.yml"])
it "'validate_cnf_conformance_yml' (function) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
args = Sam::Args.new(["cnf-config=sample-cnfs/sample-coredns-cnf/cnf-conformance.yml"])

yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
LOGGING.info yml.inspect
("#{yml.get("release_name").as_s?}").should eq("coredns")
yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
LOGGING.info yml.inspect
("#{yml.get("release_name").as_s?}").should eq("coredns")

valid, command_output = validate_cnf_conformance_yml(yml)

(valid).should eq(true)
(command_output).should eq (nil)
end
valid, command_output = validate_cnf_conformance_yml(yml)

it "'validate_cnf_conformance_yml' (command) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
response_s = `./cnf-conformance validate_config cnf-config=sample-cnfs/sample-coredns-cnf/cnf-conformance.yml`
$?.success?.should be_true
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end
(valid).should eq(true)
(command_output).should eq (nil)
end

it "'validate_cnf_conformance_yml' (command) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
response_s = `./cnf-conformance validate_config cnf-config=sample-cnfs/sample-coredns-cnf/cnf-conformance.yml`
$?.success?.should be_true
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end

it "'validate_cnf_conformance_yml' (function) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
args = Sam::Args.new(["cnf-config=./spec/fixtures/cnf-conformance-unmapped-keys-and-subkeys.yml"])

yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
LOGGING.info yml.inspect
("#{yml.get("release_name").as_s?}").should eq("coredns")
it "'validate_cnf_conformance_yml' (function) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
args = Sam::Args.new(["cnf-config=./spec/fixtures/cnf-conformance-unmapped-keys-and-subkeys.yml"])

status, warning_output = validate_cnf_conformance_yml(yml)
yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
LOGGING.info yml.inspect
("#{yml.get("release_name").as_s?}").should eq("coredns")

LOGGING.warn "WARNING: #{warning_output}"
status, warning_output = validate_cnf_conformance_yml(yml)

(status).should eq(true)
(warning_output).should_not be_nil
end
LOGGING.warn "WARNING: #{warning_output}"

(status).should eq(true)
(warning_output).should_not be_nil
end

it "'validate_cnf_conformance_yml' (command) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
response_s = `./cnf-conformance validate_config cnf-config=spec/fixtures/cnf-conformance-unmapped-keys-and-subkeys.yml`
$?.success?.should be_true
(/WARNING: Unmapped cnf_conformance.yml keys. Please add them to the validator/ =~ response_s).should_not be_nil
(/WARNING: helm_repository is unset or has unmapped subkeys. Please update your cnf_conformance.yml/ =~ response_s).should_not be_nil
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end

it "'validate_cnf_conformance_yml' (command) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
response_s = `./cnf-conformance validate_config cnf-config=spec/fixtures/cnf-conformance-unmapped-keys-and-subkeys.yml`
$?.success?.should be_true
(/WARNING: Unmapped cnf_conformance.yml keys. Please add them to the validator/ =~ response_s).should_not be_nil
(/WARNING: helm_repository is unset or has unmapped subkeys. Please update your cnf_conformance.yml/ =~ response_s).should_not be_nil
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end

it "'validate_cnf_conformance_yml' (function) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
args = Sam::Args.new(["cnf-config=spec/fixtures/cnf-conformance-invalid-and-unmapped-keys.yml"])

yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
LOGGING.info yml.inspect
("#{yml.get("release_name").as_s?}").should eq("coredns")
it "'validate_cnf_conformance_yml' (function) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
args = Sam::Args.new(["cnf-config=spec/fixtures/cnf-conformance-invalid-and-unmapped-keys.yml"])

status, warning_output = validate_cnf_conformance_yml(yml)
yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
LOGGING.info yml.inspect
("#{yml.get("release_name").as_s?}").should eq("coredns")

(status).should eq(false)
(warning_output).should eq(nil)
end
status, warning_output = validate_cnf_conformance_yml(yml)

it "'validate_cnf_conformance_yml' (command) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
response_s = `./cnf-conformance validate_config cnf-config=spec/fixtures/cnf-conformance-invalid-and-unmapped-keys.yml`
$?.success?.should be_true
(status).should eq(false)
(warning_output).should eq(nil)
end

(/ERROR: cnf_conformance.yml field validation error/ =~ response_s).should_not be_nil
(/FAILURE: Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ response_s).should_not be_nil
end
it "'validate_cnf_conformance_yml' (command) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
response_s = `./cnf-conformance validate_config cnf-config=spec/fixtures/cnf-conformance-invalid-and-unmapped-keys.yml`
$?.success?.should be_true

it "'validate_cnf_conformance_yml' (command) should pass, for all sample-cnfs", tags: ["unhappy-path", "validate_config"] do
(/ERROR: cnf_conformance.yml field validation error/ =~ response_s).should_not be_nil
(/FAILURE: Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ response_s).should_not be_nil
end

get_dirs = Dir.entries("sample-cnfs")
dir_list = get_dirs - [".", ".."]
dir_list.each do |dir|
conformance_yml = "sample-cnfs/#{dir}/cnf-conformance.yml"
response_s = `./cnf-conformance validate_config cnf-config=#{conformance_yml}`
if (/FAILURE: Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ response_s)
LOGGING.info "\n #{conformance_yml}: #{response_s}"
it "'validate_cnf_conformance_yml' (command) should pass, for all sample-cnfs", tags: ["unhappy-path", "validate_config"] do

get_dirs = Dir.entries("sample-cnfs")
dir_list = get_dirs - [".", ".."]
dir_list.each do |dir|
conformance_yml = "sample-cnfs/#{dir}/cnf-conformance.yml"
response_s = `./cnf-conformance validate_config cnf-config=#{conformance_yml}`
if (/FAILURE: Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ response_s)
LOGGING.info "\n #{conformance_yml}: #{response_s}"
end
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end
end

it "'validate_cnf_conformance_yml' (command) should pass, for all example-cnfs", tags: ["unhappy-path", "validate_config"] do

get_dirs = Dir.entries("example-cnfs")
dir_list = get_dirs - [".", ".."]
dir_list.each do |dir|
conformance_yml = "example-cnfs/#{dir}/cnf-conformance.yml"
response_s = `./cnf-conformance validate_config cnf-config=#{conformance_yml}`
if (/FAILURE: Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ response_s)
LOGGING.info "\n #{conformance_yml}: #{response_s}"
it "'validate_cnf_conformance_yml' (command) should pass, for all example-cnfs", tags: ["unhappy-path", "validate_config"] do

get_dirs = Dir.entries("example-cnfs")
dir_list = get_dirs - [".", ".."]
dir_list.each do |dir|
conformance_yml = "example-cnfs/#{dir}/cnf-conformance.yml"
response_s = `./cnf-conformance validate_config cnf-config=#{conformance_yml}`
if (/FAILURE: Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ response_s)
LOGGING.info "\n #{conformance_yml}: #{response_s}"
end
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
end

end



87 changes: 44 additions & 43 deletions spec/utils/utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -252,53 +252,54 @@ describe "Utils" do
it "'generate_version' should return the current version of the cnf_conformance library" do
(generate_version).should_not eq("")
end
end

it "'logger' command line logger level setting via config.yml", tags: ["logger", "happy-path"] do
# NOTE: the config.yml file is in the root of the repo directory.
# as written this test depends on they key loglevel being set to 'info' in that config.yml
response_s = `./cnf-conformance test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should be_nil
(/INFO -- cnf-conformance: info test/ =~ response_s).should_not be_nil
(/WARN -- cnf-conformance: warn test/ =~ response_s).should_not be_nil
(/ERROR -- cnf-conformance: error test/ =~ response_s).should_not be_nil
end
it "'logger' command line logger level setting via config.yml", tags: ["logger", "happy-path"] do
# NOTE: the config.yml file is in the root of the repo directory.
# as written this test depends on they key loglevel being set to 'info' in that config.yml
response_s = `./cnf-conformance test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should be_nil
(/INFO -- cnf-conformance: info test/ =~ response_s).should_not be_nil
(/WARN -- cnf-conformance: warn test/ =~ response_s).should_not be_nil
(/ERROR -- cnf-conformance: error test/ =~ response_s).should_not be_nil
end

it "'logger' command line logger level setting works", tags: ["logger", "happy-path"] do
# Note: implicitly tests the override of config.yml if it exist in repo root
response_s = `./cnf-conformance -l debug test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should_not be_nil
end
it "'logger' command line logger level setting works", tags: ["logger", "happy-path"] do
# Note: implicitly tests the override of config.yml if it exist in repo root
response_s = `./cnf-conformance -l debug test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should_not be_nil
end

it "'logger' environment variable level setting works", tags: ["logger", "happy-path"] do
# Note: implicitly tests the override of config.yml if it exist in repo root
response_s = `LOGLEVEL=DEBUG ./cnf-conformance test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should_not be_nil
end
it "'logger' environment variable level setting works", tags: ["logger", "happy-path"] do
# Note: implicitly tests the override of config.yml if it exist in repo root
response_s = `LOGLEVEL=DEBUG ./cnf-conformance test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should_not be_nil
end

it "'logger' command line level setting overrides environment variable", tags: ["logger", "happy-path"] do
response_s = `LOGLEVEL=DEBUG ./cnf-conformance -l error test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should be_nil
(/INFO -- cnf-conformance: info test/ =~ response_s).should be_nil
(/WARN -- cnf-conformance: warn test/ =~ response_s).should be_nil
(/ERROR -- cnf-conformance: error test/ =~ response_s).should_not be_nil
end
it "'logger' command line level setting overrides environment variable", tags: ["logger", "happy-path"] do
response_s = `LOGLEVEL=DEBUG ./cnf-conformance -l error test`
$?.success?.should be_true
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should be_nil
(/INFO -- cnf-conformance: info test/ =~ response_s).should be_nil
(/WARN -- cnf-conformance: warn test/ =~ response_s).should be_nil
(/ERROR -- cnf-conformance: error test/ =~ response_s).should_not be_nil
end

it "'logger' defaults to error when level set is missplled", tags: ["logger"] do
# Note: implicitly tests the override of config.yml if it exist in repo root
response_s = `LOGLEVEL=DEGUB ./cnf-conformance test`
$?.success?.should be_true
(/ERROR -- cnf-conformance: Invalid logging level set. defaulting to ERROR/ =~ response_s).should_not be_nil
it "'logger' defaults to error when level set is missplled", tags: ["logger"] do
# Note: implicitly tests the override of config.yml if it exist in repo root
response_s = `LOGLEVEL=DEGUB ./cnf-conformance test`
$?.success?.should be_true
(/ERROR -- cnf-conformance: Invalid logging level set. defaulting to ERROR/ =~ response_s).should_not be_nil
end

it "'logger' or verbose output should be shown when verbose flag is set", tags: ["logger"] do
response_s = `./cnf-conformance helm_deploy verbose`
LOGGING.info response_s
puts response_s
$?.success?.should be_true
(/INFO -- cnf-conformance-verbose: helm_deploy/ =~ response_s).should_not be_nil
end
end

it "'logger' or verbose output should be shown when verbose flag is set", tags: ["logger"] do
response_s = `./cnf-conformance helm_deploy verbose`
LOGGING.info response_s
puts response_s
$?.success?.should be_true
(/INFO -- cnf-conformance-verbose: helm_deploy/ =~ response_s).should_not be_nil
end
Loading

0 comments on commit 3517309

Please sign in to comment.