Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tests #15

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ name: 'Continuous Integration'

on:
push:
tags:
- '*.*.*'
branches: ['master']
pull_request:
branches: ['master']
workflow_call:

jobs:
push:
name: 'Push image'
name: 'Run tests'
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
Expand All @@ -24,7 +26,21 @@ jobs:
- name: 'Build'
uses: 'docker/build-push-action@v5'
with:
pull: false
push: true
tags: 'jeanberu/mailcatcher:${{ github.ref_name }},jeanberu/mailcatcher:latest'
tags: 'jeanberu/mailcatcher:latest'
platforms: 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8'
cache-from: 'type=gha'
cache-to: 'type=gha,mode=max'
- name: 'Start mailcatcher'
run: 'docker run --detach --publish 1025:1025 --publish 1080:1080 jeanberu/mailcatcher:latest'
- name: 'Install Ruby dependencies'
uses: 'ruby/setup-ruby@v1'
with:
ruby-version: '3.3'
bundler-cache: true
- name: 'Wait for mailcatcher'
run: |
while ! nc -z 0.0.0.0 1025 </dev/null; do echo Waiting for SMTP to start...; sleep 1; done
while ! nc -z 0.0.0.0 1080 </dev/null; do echo Waiting for API to start...; sleep 1; done
timeout-minutes: 1
- name: 'Run tests'
run: 'bundle exec rspec spec/*'
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Publish image'

on:
push:
tags: ['*.*.*']

jobs:
tests:
name: 'Run tests'
uses: './.github/workflows/ci.yml'
push:
name: 'Push image'
needs: ['tests']
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
steps:
- name: 'Checkout code'
uses: 'actions/checkout@v4'
- name: 'Log in to the Container registry'
uses: 'docker/login-action@v3'
with:
username: '${{ secrets.REGISTRY_USERNAME }}'
password: '${{ secrets.REGISTRY_PASSWORD }}'
- name: 'Set up Docker Buildx'
uses: 'docker/setup-buildx-action@v3'
- name: 'Build'
uses: 'docker/build-push-action@v5'
with:
pull: false
push: true
tags: 'jeanberu/mailcatcher:${{ github.ref_name }},jeanberu/mailcatcher:latest'
platforms: 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8'
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ruby '>= 3.3'
source 'https://rubygems.org'

gem 'rspec', '>= 3.13'
gem 'net-smtp', '>= 0.5'
gem 'net-http', '>= 0.4'
40 changes: 40 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.5.1)
net-http (0.4.1)
uri
net-protocol (0.2.2)
timeout
net-smtp (0.5.0)
net-protocol
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
timeout (0.4.1)
uri (0.13.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
net-http (>= 0.4)
net-smtp (>= 0.5)
rspec (>= 3.13)

RUBY VERSION
ruby 3.3.2p78

BUNDLED WITH
2.5.9
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Mailcatcher

[![Latest Version](https://img.shields.io/github/release/Jean-Beru/docker-mailcatcher.svg?style=flat-square)](https://github.com/Jean-Beru/docker-mailcatcher/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENCE)
[![Tests](https://github.com/Jean-Beru/docker-mailcatcher/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Jean-Beru/docker-mailcatcher/actions/workflows/ci.yml?query=branch%3Amaster)


[Mailcatcher](http://mailcatcher.me) catches mail and serves it through a dream.

Run with : `docker run -d -p 1025:1025 -p 1080:1080 --name mailcatcher jeanberu/mailcatcher`
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/mail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Subject: test message
Date: Sat, 23 Jun 2001 16:26:43 +0900
Message-Id: <unique.message.id.string@example.com>

This is a test message.
28 changes: 28 additions & 0 deletions spec/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'json'
require 'net/http'
require 'net/smtp'

fixtures = File.dirname(__FILE__) + '/fixtures/'
api = Net::HTTP.new('0.0.0.0', 1080)

RSpec.describe 'Mailcatcher' do
before :all do
api.delete('/messages')
end

it "can receive an email" do
content = File.open(fixtures + 'mail.txt').read
Net::SMTP.start('0.0.0.0', 1025) do |smtp|
smtp.send_message content, 'to@example.com', 'cc@example.com'
end

response = JSON.parse(api.get('/messages').body)

expect(response.count).to eq 1
expect(response[0]['id']).to eq 1
expect(response[0]['sender']).to eq '<to@example.com>'
expect(response[0]['recipients']).to eq ['<cc@example.com>']
expect(response[0]['subject']).to eq 'test message'
expect(response[0]['size']).to eq "141"
end
end