|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Copyright (c) 2024 SolarWinds, LLC. |
| 4 | +# All rights reserved. |
| 5 | + |
| 6 | +require 'minitest' |
| 7 | +require 'minitest/autorun' |
| 8 | +require 'minitest/spec' |
| 9 | +require 'minitest/reporters' |
| 10 | +require './lib/solarwinds_apm/logger' |
| 11 | + |
| 12 | +ENV['SW_APM_SERVICE_KEY'] = 'this-is-a-dummy-api-token-for-testing-111111111111111111111111111111111:test-service' |
| 13 | + |
| 14 | +# write to a file as well as STDOUT (comes in handy with docker runs) |
| 15 | +# This approach preserves the coloring of pass fail, which the cli |
| 16 | +# `./run_tests.sh 2>&1 | tee -a test/docker_test.log` does not |
| 17 | +if ENV['TEST_RUNS_TO_FILE'] |
| 18 | + FileUtils.mkdir_p('log') # create if it doesn't exist |
| 19 | + $out_file = if ENV['TEST_RUNS_FILE_NAME'] |
| 20 | + File.new(ENV['TEST_RUNS_FILE_NAME'], 'a') |
| 21 | + else |
| 22 | + File.new("log/test_direct_runs_#{Time.now.strftime('%Y%m%d_%H_%M')}.log", 'a') |
| 23 | + end |
| 24 | + $out_file.sync = true |
| 25 | + $stdout.sync = true |
| 26 | + |
| 27 | + def $stdout.write(string) |
| 28 | + $out_file.write(string) |
| 29 | + super |
| 30 | + end |
| 31 | +end |
| 32 | + |
| 33 | +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new |
| 34 | + |
| 35 | +$LOAD_PATH.unshift("#{Dir.pwd}/lib/") |
| 36 | + |
| 37 | +def noop_shared_test |
| 38 | + _(defined?(SolarWindsAPM::API)).must_equal 'constant' |
| 39 | + _(SolarWindsAPM::API.solarwinds_ready?(300)).must_equal false |
| 40 | + assert_nil SolarWindsAPM::API.in_span('params') |
| 41 | + _(SolarWindsAPM::API.set_transaction_name).must_equal true |
| 42 | + _(SolarWindsAPM::API.current_trace_info.hash_for_log.to_s).must_equal '{}' |
| 43 | + _(SolarWindsAPM::API.current_trace_info.for_log).must_equal '' |
| 44 | + _(SolarWindsAPM::API.current_trace_info.tracestring).must_equal '00-00000000000000000000000000000000-0000000000000000-00' |
| 45 | + _(SolarWindsAPM::API.current_trace_info.trace_flags).must_equal '00' |
| 46 | + _(SolarWindsAPM::API.current_trace_info.span_id).must_equal '0000000000000000' |
| 47 | + _(SolarWindsAPM::API.current_trace_info.trace_id).must_equal '00000000000000000000000000000000' |
| 48 | + _(SolarWindsAPM::API.current_trace_info.do_log).must_equal :never |
| 49 | + |
| 50 | + in_span_result = SolarWindsAPM::API.in_span('params') do |_span| |
| 51 | + value = 1 + 1 |
| 52 | + value |
| 53 | + end |
| 54 | + |
| 55 | + _(in_span_result).must_equal 2 |
| 56 | +end |
0 commit comments