1# frozen_string_literal: true
2
3require 'airborne'
4
5module QA
6  # This test ensures that the version described by the `DEPLOY_VERSION`
7  # environment variable is the version actually running.
8  #
9  # See https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1179
10  RSpec.describe 'Version sanity check', :smoke, only: { pipeline: [:pre, :release] } do
11    let(:api_client) { Runtime::API::Client.new(:gitlab) }
12    let(:request) { Runtime::API::Request.new(api_client, '/version') }
13
14    it 'is the specified version' do
15      # The `DEPLOY_VERSION` variable will only be provided for deploys to the
16      # `pre` and `release` environments, which only receive packaged releases.
17      #
18      # For these releases, `deploy_version` will be a package string (e.g.,
19      # `13.1.3-ee.0`), and the reported version will be something like
20      # `13.1.3-ee`, so we only compare the leading SemVer string.
21      #
22      # | Package          | Version        |
23      # | ---------------- | -------------- |
24      # | 13.3.5-ee.0      | 13.3.5-ee      |
25      # | 13.3.0-rc42.ee.0 | 13.3.0-rc42-ee |
26      deploy = Runtime::Env.deploy_version&.gsub(/\A(\d+\.\d+\.\d+).*\z/, '\1')
27
28      skip('No deploy version provided') if deploy.nil? || deploy.empty?
29
30      get request.url
31
32      expect_status(200)
33      expect(json_body).to have_key(:version)
34      expect(json_body[:version]).to start_with(deploy)
35    end
36  end
37end
38