Skip to content

Commit

Permalink
setup coveralls (#8)
Browse files Browse the repository at this point in the history
* setup coveralls

setups coveralls for test pipeline

* codecov

* codecov
  • Loading branch information
mrwormhole authored Jun 14, 2024
1 parent 67ea2c7 commit 05da947
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ jobs:
version: v1.57

- name: Test
run: go test -race -v ./...
run: go test -race -covermode atomic -coverprofile=covprofile -v ./...

- name: Install Goveralls
run: go install github.com/mattn/[email protected]

- name: Upload Coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -ignore=cmd/**/*.go -coverprofile=covprofile -service=github
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
[![CI Build](https://github.com/mrwormhole/emailer/actions/workflows/test.yaml/badge.svg)](https://github.com/mrwormhole/emailer/actions/workflows/test.yaml)
[![GoDoc](https://godoc.org/github.com/mrwormhole/emailer?status.svg)](https://godoc.org/github.com/mrwormhole/emailer)
[![Report Card](https://goreportcard.com/badge/github.com/mrwormhole/emailer)](https://goreportcard.com/report/github.com/mrwormhole/emailer)
[![License](https://img.shields.io/github/license/mrwormhole/emailer)](https://github.com/mrwormhole/emailer/blob/master/LICENSE)

tiny email server for managed email providers
[![License](https://img.shields.io/github/license/mrwormhole/emailer)](https://github.com/mrwormhole/emailer/blob/main/LICENSE)
[![Coverage Status](https://coveralls.io/repos/github/mrwormhole/emailer/badge.svg?branch=main)](https://coveralls.io/github/mrwormhole/emailer?branch=main)

### Purpose

packaging SMTP(send only) APIs to a choosable option is the goal here, then to have a tiny image that picks 1 provider and serves
as HTTP server so other microservices that belong to you can make email sending for multiple clients of yours.
Packaging SMTP(send only) APIs to a choosable option is the goal here, then to have a tiny server that picks 1 provider and serves
as HTTP endpoint so the other microservices that belong to you can make email requests.

### Supported providers

Expand Down
33 changes: 33 additions & 0 deletions brevo/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package brevo

import (
"errors"
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestNew(t *testing.T) {
_, err := New("", nil)
want := errors.New("brevo API key is blank")
if !cmp.Equal(want.Error(), err.Error()) {
t.Errorf("New(): got=%q want=%q", err, want)
}
}

type RoundTripFunc func(req *http.Request) *http.Response

func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req), nil
}

type FaultyRoundTripFunc func(req *http.Request) *http.Response

func (f FaultyRoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req), errors.New("boom baby boom")
}

func NewTestClient[T RoundTripFunc | FaultyRoundTripFunc](tripper T) (*EmailClient, error) {
return New("key", &http.Client{Transport: http.RoundTripper(tripper)})
}
19 changes: 2 additions & 17 deletions brevo/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"log/slog"
"net/http"
Expand Down Expand Up @@ -55,22 +54,6 @@ func TestEmailHandler_FailedValidation(t *testing.T) {
}
}

type RoundTripFunc func(req *http.Request) *http.Response

func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req), nil
}

type FaultyRoundTripFunc func(req *http.Request) *http.Response

func (f FaultyRoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req), errors.New("boom baby boom")
}

func NewTestClient[T RoundTripFunc | FaultyRoundTripFunc](tripper T) (*EmailClient, error) {
return New("key", &http.Client{Transport: http.RoundTripper(tripper)})
}

func TestEmailHandler_Success(t *testing.T) {
tripper := func(req *http.Request) *http.Response {
return &http.Response{
Expand All @@ -85,6 +68,8 @@ func TestEmailHandler_Success(t *testing.T) {
email := emailer.Email{
From: "[email protected]",
To: []string{"[email protected]"},
BCC: []string{"[email protected]"},
CC: []string{"[email protected]"},
Subject: "sub",
HTMLContent: "html",
}
Expand Down

0 comments on commit 05da947

Please sign in to comment.