Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Beru committed Jun 4, 2024
1 parent 0072d20 commit c1ac0c1
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
23 changes: 17 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,16 @@ 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 -d jeanberu/mailcatcher:latest'
- name: 'Install test dependencies'
env:
GEM_HOME: '${{ env.HOME }}/gems'
PATH: '${{ env.HOME }}/gems/bin:${{ env.PATH }}'
run: 'gem install rspec net-smtp net-http'
- name: 'Run tests'
run: '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'
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: <[email protected]>

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, '[email protected]', '[email protected]'
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 '<[email protected]>'
expect(response[0]['recipients']).to eq ['<[email protected]>']
expect(response[0]['subject']).to eq 'test message'
expect(response[0]['size']).to eq "141"
end
end

0 comments on commit c1ac0c1

Please sign in to comment.