View Source Uploadex.Testing (Uploadex v3.1.0)

This module simplifies testing and assertions involving Uploadex.

Usage in Tests

The most convenient way to use Uploadex.Testing is to use the module:

use Uploadex.Testing

That will define all the helper functions you'll need to make assertions.

Some examples of how to use the functions

# Asserting that 2 files were stored
assert_stored_files_count(2)

# Asserting the filenames of the stored files
assert_stored_files(["file1.pdf", "file2.pdf"])

# Asserting the filenames of the stored files ignoring the order
assert_stored_files(["file2.pdf", "file1.pdf"], ignore_order: true)

# Asserting that no file was stored
refute_stored_files()

# Getting all stored files
["file1.pdf", "file2.pdf"] == get_stored_files()

# Asserting that 1 files was deleted
assert_deleted_files_count(1)

# Asserting the filenames of the deleted files
assert_deleted(["file3.pdf", "file4.pdf", "file5.pdf"])

# Asserting the filenames of the deleted files ignoring the order
assert_deleted_files(["file4.pdf", "file5.pdf", "file3.pdf"], ignore_order: true)

# Asserting that no file was deleted
refute_deleted_files()

# Getting all deleted files
["file3.pdf", "file4.pdf", "file5.pdf"] == get_deleted_files()

If you need a more low level API, you can directly use the Uploadex.TestStorage functions.

Summary

Functions

Imports all functions from Uploadex.Testing and defines a setup callback to start the Uploadex.TestStorage.

Asserts that all the files in expected_files were deleted in the exact order that they are passed in the list.

Asserts that the given expected_count number of files was deleted.

Asserts that all the files in expected_files were stored in the exact order that they are passed in the list.

Asserts that the given expected_count number of files was stored.

Returns all the deleted files.

Returns the options used in the Uploadex.TestStorage.

Returns all the stored files.

Asserts that no file was deleted.

Asserts that no file was stored.

Functions

Link to this macro

__using__(opts)

View Source (macro)

Imports all functions from Uploadex.Testing and defines a setup callback to start the Uploadex.TestStorage.

Link to this function

assert_deleted_files(expected_files, opts \\ [])

View Source
@spec assert_deleted_files(
  expected_files :: list(),
  opts :: [{:ignoring_order, boolean()}]
) :: true

Asserts that all the files in expected_files were deleted in the exact order that they are passed in the list.

Options

  • ignoring_order: if true, ignores the order of the files when asserting (defaults to false)
Link to this function

assert_deleted_files_count(expected_count)

View Source
@spec assert_deleted_files_count(expected_count :: integer()) :: true

Asserts that the given expected_count number of files was deleted.

Link to this function

assert_stored_files(expected_files, opts \\ [])

View Source
@spec assert_stored_files(
  expected_files :: list(),
  opts :: [{:ignoring_order, boolean()}]
) :: true

Asserts that all the files in expected_files were stored in the exact order that they are passed in the list.

Options

  • ignoring_order: if true, ignores the order of the files when asserting (defaults to false)
Link to this function

assert_stored_files_count(expected_count)

View Source
@spec assert_stored_files_count(expected_count :: integer()) :: true

Asserts that the given expected_count number of files was stored.

@spec get_deleted_files() :: list()

Returns all the deleted files.

It's the same as calling Uploadex.TestStorage.get_deleted/0.

@spec get_storage_opts() :: keyword()

Returns the options used in the Uploadex.TestStorage.

It's the same as calling Uploadex.TestStorage.get_opts/0.

@spec get_stored_files() :: list()

Returns all the stored files.

It's the same as calling Uploadex.TestStorage.get_stored/0.

@spec refute_deleted_files() :: true

Asserts that no file was deleted.

@spec refute_stored_files() :: true

Asserts that no file was stored.

Link to this function

start_test_storage(ctx \\ %{})

View Source
@spec start_test_storage(context :: map()) :: :ok

Starts the Uploadex.TestStorage.

After importing it, you can use as a ExUnit setup callback:

import Uploadex.Testing

setup :start_test_storage