class Gitlab::QA::Scenario::Test::Sanity::Version

This test checks that the sha_version of a GitLab was authored in the window defined by the `weekday_hours` method. We perform a single API call to get the commit

Public Instance Methods

perform(release = 'ce') click to toggle source
# File lib/gitlab/qa/scenario/test/sanity/version.rb, line 15
def perform(release = 'ce')
  version = Component::Gitlab.perform do |gitlab|
    gitlab.release = release
    gitlab.act do
      pull
      sha_version
    end
  end

  project = "gitlab-org/#{QA::Release.new(release).api_project_name}"
  commit = api_commit_detail(project, version)

  if commit_within_hours?(commit['created_at'], weekday_hours(commit['created_at']))
    puts "Found commit #{version} in recent history of #{project}"
  else
    puts "Did not find #{version} in recent history of #{project}"
    exit 1
  end
end

Private Instance Methods

api_commit_detail(project, commit_id) click to toggle source
# File lib/gitlab/qa/scenario/test/sanity/version.rb, line 54
def api_commit_detail(project, commit_id)
  api = 'https://gitlab.com/api/v4'
  url = "#{api}/projects/#{CGI.escape(project)}/repository/commits/#{commit_id}"

  JSON.parse(Net::HTTP.get(URI(url)))
end
commit_within_hours?(commit_time_string, hours) click to toggle source
# File lib/gitlab/qa/scenario/test/sanity/version.rb, line 50
def commit_within_hours?(commit_time_string, hours)
  Time.at(Time.parse(commit_time_string).utc).to_datetime > Time.at((Time.now - hours * 60 * 60).utc).to_datetime
end
weekday_hours(date_string) click to toggle source
# File lib/gitlab/qa/scenario/test/sanity/version.rb, line 37
def weekday_hours(date_string)
  case Date.parse(date_string).wday
    # Sunday
  when 0
    48
    # Monday
  when 1
    72
  else
    24
  end
end