Skip to content
Open
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
9 changes: 8 additions & 1 deletion .github/workflows/go-lint.yml → .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Golang Linting
name: Golang Validation

on:
push:
Expand Down Expand Up @@ -29,3 +29,10 @@ jobs:
- name: Check Format
run: |
gofmt -s -l database logging sse *.go
- name: Run Tests
run: |
go test ./database
- name: Run vet
run: |
go vet ./database/ ./logging/ ./sse/
go vet *.go
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM docker.io/golang:1.24-alpine AS build

WORKDIR /src/
RUN apk add git
COPY go.* .
RUN go mod download # do this before build for caching
COPY database database
COPY logging logging
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ go mod tidy

# format all code according to go standards
gofmt -w -s *.go logging sse database

# run tests (database is the first place we've defined tests)
go test ./database

# run heuristic validation
go vet ./database/ ./logging/ ./sse/
go vet *.go
```

## To-Dos
Expand Down
9 changes: 8 additions & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"strings"
"testing"
"time"

"github.com/computersciencehouse/vote/logging"
Expand All @@ -20,10 +21,16 @@ const (
Updated UpsertResult = 1
)

var Client = Connect()
var Client *mongo.Client = Connect()
var db = ""

func Connect() *mongo.Client {
// This always gets invoked on initialisation. bad! it'd be nice if we only did this setup in main rather than components under test. for now we just skip if testing
if testing.Testing() {
logging.Logger.WithFields(logrus.Fields{"module": "database", "method": "Connect"}).Info("testing, not doing db connection, someone should mock this someday")
return nil
}

logging.Logger.WithFields(logrus.Fields{"module": "database", "method": "Connect"}).Info("beginning database connection")

ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
Expand Down
Loading