Azure-Storage-Blob-Client

 view release on metacpan or  search on metacpan

t/Azure/Storage/Blob/Client/Caller.t  view on Meta::CPAN

      $error = $trap->die;
    };

    Then 'it should throw an InvalidAuthenticationInfo exception' => sub {
      like($error->code, qr/InvalidAuthenticationInfo/);
    };
  };

  Scenario 'BlobAlreadyExists' => sub {
    my $call_object;

    Given 'a GetBlobProperties call object' => sub {
      $call_object = Azure::Storage::Blob::Client::Call::GetBlobProperties->new(
        container => 'mycontainer',
        account_name => $account_name,
        api_version => $api_version,
        account_key => $account_key,
        blob_name => 'myblob',
      );
    };

    When 'the caller receives a BlobAlreadyExists error from the API' => sub {
      $signer_mock
        ->expects('calculate_signature');
      $ua_mock
        ->expects('request')
        ->returns(HTTP::Response->new(
            409,
            'The specified blob already exists.',
            HTTP::Headers->new('x-ms-error-code' => 'BlobAlreadyExists'),
          )
        );
      trap { $caller->request($account_name, $account_key, $call_object) };
      $error = $trap->die;
    };

    Then 'it should throw a BlobAlreadyExists exception' => sub {
      like($error->code, qr/BlobAlreadyExists/);
    };
  };

  Scenario 'BlobNotFound' => sub {
    my $call_object;

    Given 'a GetBlobProperties call object' => sub {
      $call_object = Azure::Storage::Blob::Client::Call::GetBlobProperties->new(
        container => 'mycontainer',
        account_name => $account_name,
        account_key => $account_key,
        api_version => $api_version,
        blob_name => 'myblob',
      );
    };

    When 'the caller receives a BlobNotFound error from the API' => sub {
      $signer_mock
        ->expects('calculate_signature');
      $ua_mock
        ->expects('request')
        ->returns(HTTP::Response->new(
            404,
            'The specified blob does not exist.',
            HTTP::Headers->new('x-ms-error-code' => 'BlobNotFound'),
          )
        );
      trap { $caller->request($account_name, $account_key, $call_object) };
      $error = $trap->die;
    };

    Then 'it should throw a BlobNotFound exception' => sub {
      like($error->code, qr/BlobNotFound/);
    };
  };

  Scenario 'ContainerNotFound' => sub {
    my $call_object;

    Given 'a GetBlobProperties call object' => sub {
      $call_object = Azure::Storage::Blob::Client::Call::GetBlobProperties->new(
        container => 'mycontainer',
        account_name => $account_name,
        account_key => $account_key,
        api_version => $api_version,
        blob_name => 'myblob',
      );
    };

    When 'the caller receives a ContainerNotFound error from the API' => sub {
      $signer_mock
        ->expects('calculate_signature');
      $ua_mock
        ->expects('request')
        ->returns(HTTP::Response->new(
            404,
            'The specified container does not exist.',
            HTTP::Headers->new('x-ms-error-code' => 'ContainerNotFound'),
          )
        );
      trap { $caller->request($account_name, $account_key, $call_object) };
      $error = $trap->die;
    };

    Then 'it should throw a ContainerNotFound exception' => sub {
      like($error->code, qr/ContainerNotFound/);
    };
  };

  Scenario 'InvalidBlobType' => sub {
    my $call_object;

    Given 'a GetBlobProperties call object' => sub {
      $call_object = Azure::Storage::Blob::Client::Call::GetBlobProperties->new(
        container => 'mycontainer',
        account_name => $account_name,
        account_key => $account_key,
        api_version => $api_version,
        blob_name => 'myblob',
      );
    };

    When 'the caller receives a InvalidBlobType error from the API' => sub {
      $signer_mock
        ->expects('calculate_signature');
      $ua_mock
        ->expects('request')
        ->returns(HTTP::Response->new(
            404,
            'The specified container does not exist.',
            HTTP::Headers->new('x-ms-error-code' => 'InvalidBlobType'),
          )
        );
      trap { $caller->request($account_name, $account_key, $call_object) };
      $error = $trap->die;
    };

    Then 'it should throw a InvalidBlobType exception' => sub {
      like($error->code, qr/InvalidBlobType/);
    };
  };

  Scenario 'UnknownAzureStorageAPIError' => sub {
    my $call_object;

    Given 'a GetBlobProperties call object' => sub {
      $call_object = Azure::Storage::Blob::Client::Call::GetBlobProperties->new(
        container => 'mycontainer',
        account_name => $account_name,
        account_key => $account_key,
        api_version => $api_version,
        blob_name => 'myblob',
      );
    };

    When 'the caller receives an unknown error from the Azure Storage API' => sub {
      $signer_mock
        ->expects('calculate_signature');
      $ua_mock
        ->expects('request')
        ->returns(HTTP::Response->new(
            404,
            'The specified blob does not exist.',
            HTTP::Headers->new('x-ms-error-code' => undef),
          )
        );
      trap { $caller->request($account_name, $account_key, $call_object) };
      $error = $trap->die;
    };

    Then 'it should throw an UknownAzureStorageAPIError exception' => sub {
      like($error->code, qr/UnknownAzureStorageAPIError/);
    };
  };
};

runtests unless caller;



( run in 1.893 second using v1.01-cache-2.11-cpan-788537b7465 )