Sentry-SDK

 view release on metacpan or  search on metacpan

t/sdk.t  view on Meta::CPAN

use Mojo::Base -strict, -signatures;

use Mojo::File;
# curfile missing in Mojolicious@^8. The dependency shall not be updated for
# the time being. For this reason `curfile` is duplicated for now.
# use lib curfile->sibling('lib')->to_string;
# See https://github.com/mojolicious/mojo/blob/4093223cae00eb516e38f2226749d2963597cca3/lib/Mojo/File.pm#L36
use lib Mojo::File->new(Cwd::realpath((caller)[1]))->sibling('lib')->to_string;

use Mock::Sentry::Client;
use Mojo::Exception;
use Mojo::Util 'dumper';
use Sentry::Hub;
use Sentry::Logger 'logger';
use Sentry::SDK;
use Sentry::Severity;
use Test::Snapshot;
use Test::Spec;
use UUID::Tiny 'is_UUID_string';
use version;

describe 'Sentry::SDK' => sub {
  my $hub;

  before each => sub {
    $hub = Sentry::Hub->get_current_hub();
    $hub->reset();
  };

  it 'has a $VERSION' => sub {
    isa_ok $Sentry::SDK::VERSION => 'version';
  };

  describe 'init()' => sub {
    before each => sub {
      $Sentry::SDK::VERSION = version->declare('v1.1.1');

      Sentry::SDK->init({
        release            => 'my release',
        dsn                => 'abc',
        traces_sample_rate => 0.5,
        environment        => 'my env',
        debug              => 1,
      });
    };

    it 'creates a client' => sub {
      isa_ok $hub->client, 'Sentry::Client';
    };

    it 'passes options to the client' => sub {
      is_deeply_snapshot($hub->client->get_options, 'client options');
    };

    it 'sets the logger context' => sub {
      is_deeply(logger->active_contexts, ['.*']);
    };

    it 'reads options from ENV' => sub {
      local $ENV{SENTRY_DSN}                = 'DSN from env';
      local $ENV{SENTRY_RELEASE}            = 'release from env';
      local $ENV{SENTRY_TRACES_SAMPLE_RATE} = '0.123';
      local $ENV{SENTRY_ENVIRONMENT}        = 'environment from env';

      Sentry::SDK->init();

      is_deeply_snapshot($hub->client->get_options, 'client options (env)');
    };



( run in 1.501 second using v1.01-cache-2.11-cpan-8dfa8b56332 )