Skip to content

Commit

Permalink
spec for Utils::Git, frozen string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 6, 2023
1 parent 7066de3 commit b600726
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 41 deletions.
2 changes: 2 additions & 0 deletions lib/datadog/ci/configuration/components.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../flush"

module Datadog
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../ext/settings"

module Datadog
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/cucumber/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../ext"

require "datadog/tracing/contrib/configuration/settings"
Expand Down
18 changes: 10 additions & 8 deletions lib/datadog/ci/contrib/cucumber/ext.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# frozen_string_literal: true

module Datadog
module CI
module Contrib
module Cucumber
# Cucumber integration constants
# TODO: mark as `@public_api` when GA, to protect from resource and tag name changes.
module Ext
APP = "cucumber".freeze
ENV_ENABLED = "DD_TRACE_CUCUMBER_ENABLED".freeze
ENV_OPERATION_NAME = "DD_TRACE_CUCUMBER_OPERATION_NAME".freeze
FRAMEWORK = "cucumber".freeze
OPERATION_NAME = "cucumber.test".freeze
SERVICE_NAME = "cucumber".freeze
STEP_SPAN_TYPE = "step".freeze
TEST_TYPE = "test".freeze
APP = "cucumber"
ENV_ENABLED = "DD_TRACE_CUCUMBER_ENABLED"
ENV_OPERATION_NAME = "DD_TRACE_CUCUMBER_OPERATION_NAME"
FRAMEWORK = "cucumber"
OPERATION_NAME = "cucumber.test"
SERVICE_NAME = "cucumber"
STEP_SPAN_TYPE = "step"
TEST_TYPE = "test"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../../test"
require_relative "../../ext/app_types"
require_relative "../../ext/environment"
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/cucumber/instrumentation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "formatter"

module Datadog
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/cucumber/integration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "configuration/settings"
require_relative "patcher"

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/cucumber/patcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "datadog/tracing/contrib/patcher"
require_relative "instrumentation"

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/minitest/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../ext"

require "datadog/tracing/contrib/configuration/settings"
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/minitest/ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Datadog
module CI
module Contrib
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/minitest/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Datadog
module CI
module Contrib
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/minitest/integration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "configuration/settings"
require_relative "patcher"

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/rspec/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../ext"

require "datadog/tracing/contrib/configuration/settings"
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../../test"

require_relative "../../ext/app_types"
Expand Down
16 changes: 9 additions & 7 deletions lib/datadog/ci/contrib/rspec/ext.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# frozen_string_literal: true

module Datadog
module CI
module Contrib
module RSpec
# RSpec integration constants
# TODO: mark as `@public_api` when GA, to protect from resource and tag name changes.
module Ext
APP = "rspec".freeze
ENV_ENABLED = "DD_TRACE_RSPEC_ENABLED".freeze
ENV_OPERATION_NAME = "DD_TRACE_RSPEC_OPERATION_NAME".freeze
FRAMEWORK = "rspec".freeze
OPERATION_NAME = "rspec.example".freeze
SERVICE_NAME = "rspec".freeze
TEST_TYPE = "test".freeze
APP = "rspec"
ENV_ENABLED = "DD_TRACE_RSPEC_ENABLED"
ENV_OPERATION_NAME = "DD_TRACE_RSPEC_OPERATION_NAME"
FRAMEWORK = "rspec"
OPERATION_NAME = "rspec.example"
SERVICE_NAME = "rspec"
TEST_TYPE = "test"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/rspec/integration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "datadog/tracing/contrib/integration"

require_relative "configuration/settings"
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/contrib/rspec/patcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "datadog/tracing/contrib/patcher"
require_relative "example"

Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/ci/ext/app_types.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

module Datadog
module CI
module Ext
module AppTypes
TYPE_TEST = "test".freeze
TYPE_TEST = "test"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/ext/environment/providers/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Datadog
module CI
module Ext
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/ci/ext/settings.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

module Datadog
module CI
module Ext
# Defines constants for test tags
module Settings
ENV_MODE_ENABLED = "DD_TRACE_CI_ENABLED".freeze
ENV_MODE_ENABLED = "DD_TRACE_CI_ENABLED"
end
end
end
Expand Down
38 changes: 20 additions & 18 deletions lib/datadog/ci/ext/test.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
# frozen_string_literal: true

module Datadog
module CI
module Ext
# Defines constants for test tags
module Test
CONTEXT_ORIGIN = "ciapp-test".freeze
CONTEXT_ORIGIN = "ciapp-test"

TAG_ARGUMENTS = "test.arguments".freeze
TAG_FRAMEWORK = "test.framework".freeze
TAG_FRAMEWORK_VERSION = "test.framework_version".freeze
TAG_NAME = "test.name".freeze
TAG_SKIP_REASON = "test.skip_reason".freeze # DEV: Not populated yet
TAG_STATUS = "test.status".freeze
TAG_SUITE = "test.suite".freeze
TAG_TRAITS = "test.traits".freeze
TAG_TYPE = "test.type".freeze
TAG_ARGUMENTS = "test.arguments"
TAG_FRAMEWORK = "test.framework"
TAG_FRAMEWORK_VERSION = "test.framework_version"
TAG_NAME = "test.name"
TAG_SKIP_REASON = "test.skip_reason" # DEV: Not populated yet
TAG_STATUS = "test.status"
TAG_SUITE = "test.suite"
TAG_TRAITS = "test.traits"
TAG_TYPE = "test.type"

# Environment runtime tags
TAG_OS_ARCHITECTURE = "os.architecture".freeze
TAG_OS_PLATFORM = "os.platform".freeze
TAG_RUNTIME_NAME = "runtime.name".freeze
TAG_RUNTIME_VERSION = "runtime.version".freeze
TAG_OS_ARCHITECTURE = "os.architecture"
TAG_OS_PLATFORM = "os.platform"
TAG_RUNTIME_NAME = "runtime.name"
TAG_RUNTIME_VERSION = "runtime.version"

# TODO: is there a better place for SPAN_KIND?
TAG_SPAN_KIND = "span.kind".freeze
TAG_SPAN_KIND = "span.kind"

module Status
PASS = "pass".freeze
FAIL = "fail".freeze
SKIP = "skip".freeze
PASS = "pass"
FAIL = "fail"
SKIP = "skip"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "datadog/core/configuration/settings"
require "datadog/core/configuration/components"

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/flush.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "datadog/tracing/metadata/ext"
require "datadog/tracing/flush"

Expand Down
12 changes: 6 additions & 6 deletions lib/datadog/ci/utils/git.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# frozen_string_literal: true

module Datadog
module CI
module Utils
module Git
module_function

def normalize_ref(name)
return nil if name.nil?
def self.normalize_ref(ref)
return nil if ref.nil?

refs = %r{^refs/(heads/)?}
origin = %r{^origin/}
tags = %r{^tags/}
name.gsub(refs, "").gsub(origin, "").gsub(tags, "")
ref.gsub(refs, "").gsub(origin, "").gsub(tags, "")
end

def is_git_tag?(ref)
def self.is_git_tag?(ref)
!ref.nil? && ref.include?("tags/")
end
end
Expand Down
49 changes: 49 additions & 0 deletions spec/datadog/ci/utils/git_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
RSpec.describe ::Datadog::CI::Utils::Git do
describe ".normalize_ref" do
subject { described_class.normalize_ref(ref) }

context "when input is nil" do
let(:ref) { nil }

it { is_expected.to be_nil }
end

context "when input is github ref" do
let(:ref) { "refs/heads/master" }

it "strips everything out except ref name" do
is_expected.to eq("master")
end
end

context "when input includes tags" do
let(:ref) { "refs/heads/tags/0.1.0" }

it "strips everything out except ref name" do
is_expected.to eq("0.1.0")
end
end
end

describe ".is_git_tag?" do
subject { described_class.is_git_tag?(ref) }

context "when input is nil" do
let(:ref) { nil }

it { is_expected.to be_falsey }
end

context "when input is a branch" do
let(:ref) { "refs/heads/master" }

it { is_expected.to be_falsey }
end

context "when input includes tags" do
let(:ref) { "refs/heads/tags/0.1.0" }

it { is_expected.to be_truthy }
end
end
end

0 comments on commit b600726

Please sign in to comment.