More test; begin test infra stuff

This commit is contained in:
Philipp Heckel 2021-12-07 12:23:42 -05:00
parent 37fafd09e7
commit fd71589f60
4 changed files with 63 additions and 8 deletions

View file

@ -7,12 +7,18 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: '1.16.x' go-version: '1.17.x'
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install test dependencies - name: Install dependencies
run: sudo apt-get install netcat-openbsd run: sudo apt update && sudo apt install -y python3-pip
- name: Install mkdocs
run: sudo pip3 install mkdocs mkdocs-material mkdocs-minify-plugin
- name: Build docs
run: make docs
- name: Run tests, formatting, vetting and linting - name: Run tests, formatting, vetting and linting
run: make check run: make check
- name: Run and upload coverage to codecov.io - name: Run coverage
run: make coverage coverage-upload run: make coverage
# - name: Upload coverage to codecov.io
# run: make coverage-upload

View file

@ -38,6 +38,10 @@ help:
@echo " make install-lint - Install golint" @echo " make install-lint - Install golint"
# Documentation
docs: .PHONY
mkdocs build
# Test/check targets # Test/check targets
check: test fmt-check vet lint staticcheck check: test fmt-check vet lint staticcheck
@ -88,9 +92,6 @@ staticcheck: .PHONY
# Building targets # Building targets
docs: .PHONY
mkdocs build
build-deps: docs build-deps: docs
which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/v7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; } which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/v7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; } which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }

12
config/config_test.go Normal file
View file

@ -0,0 +1,12 @@
package config_test
import (
"github.com/stretchr/testify/assert"
"heckel.io/ntfy/config"
"testing"
)
func TestConfig_New(t *testing.T) {
c := config.New(":1234")
assert.Equal(t, ":1234", c.ListenHTTP)
}

36
server/server_test.go Normal file
View file

@ -0,0 +1,36 @@
package server
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"heckel.io/ntfy/config"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestServer_Publish(t *testing.T) {
s := newTestServer(t, newTestConfig())
rr := httptest.NewRecorder()
req, _ := http.NewRequest("PUT", "/mytopic", strings.NewReader("my message"))
s.handle(rr, req)
var m message
assert.Nil(t, json.NewDecoder(rr.Body).Decode(&m))
assert.NotEmpty(t, m.ID)
assert.Equal(t, "my message", m.Message)
}
func newTestConfig() *config.Config {
return config.New(":80")
}
func newTestServer(t *testing.T, config *config.Config) *Server {
server, err := New(config)
if err != nil {
t.Fatal(err)
}
return server
}