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 d9dda2b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 7 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ 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'
contents: 'write'
steps:
- name: 'Checkout code'
uses: 'actions/checkout@v4'
Expand All @@ -24,7 +26,13 @@ jobs:
- name: 'Build'
uses: 'docker/build-push-action@v5'
with:
pull: false
push: true
tags: 'jeanberu/mailcatcher:${{ github.ref_name }},jeanberu/mailcatcher:latest'
pull: true
push: false
tags: 'jeanberu/mailcatcher:latest'
platforms: 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8'
- name: 'Start mailcatcher'
run: 'docker run -d jeanberu/mailcatcher:latest'
- name: 'Install test dependencies'
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 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 d9dda2b

Please sign in to comment.