Skip to content

Commit

Permalink
Gorelease changes
Browse files Browse the repository at this point in the history
  • Loading branch information
liampulles committed Jun 17, 2020
1 parent 19ddc31 commit cc63744
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
uuid-server

# Coverage
coverage.txt
coverage.txt

# Releases
dist/
6 changes: 6 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ changelog:
exclude:
- '^docs:'
- '^test:'
release:
github:
owner: liampulles
name: uuid-server
prerelease: auto

15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,18 @@ language: go
go:
- master

script:
- make
- curl -sfL https://git.io/goreleaser | sh -s -- check # check goreleaser config for deprecations

after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)

# calls goreleaser
deploy:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
condition: $TRAVIS_OS_NAME = linux
2 changes: 1 addition & 1 deletion cmd/uuid-server/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"github.com/liampulles/go-config"
"github.com/liampulles/uuid-server/cmd/uuid-server/run"
"github.com/liampulles/uuid-server/pkg/run"
)

func main() {
Expand Down
35 changes: 35 additions & 0 deletions pkg/run/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package run

import (
"fmt"
"log"
"net/http"

googleUuid "github.com/google/uuid"
"github.com/liampulles/go-config"

"github.com/liampulles/uuid-server/pkg/api"
uuidConfig "github.com/liampulles/uuid-server/pkg/config"
"github.com/liampulles/uuid-server/pkg/logger"
"github.com/liampulles/uuid-server/pkg/uuid"
)

// Run will run the uuid-server
func Run(source config.Source, listenAndServe func(string, http.Handler) error) int {
cfg, err := uuidConfig.InitUUIDServerConfig(source)
if err != nil {
fmt.Printf("Error parsing config: %v", err)
return 1
}

logSvc := logger.NewServiceImpl(cfg.LogLevel, log.Printf)
uuidSvc := uuid.NewServiceImpl(googleUuid.NewRandom)
handler := api.NewUUIDHandler(logSvc, uuidSvc)

logSvc.Infof("Now serving on port %d!", cfg.Port)
if err := listenAndServe(fmt.Sprintf(":%d", cfg.Port), handler); err != nil {
fmt.Printf("Error during serving: %v", err)
return 2
}
return 0
}
60 changes: 60 additions & 0 deletions test/pkg/run/run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package run_test

import (
"fmt"
"net/http"
"testing"

"github.com/liampulles/go-config"
"github.com/liampulles/uuid-server/pkg/run"
)

func TestRun_WhenConfigFails_ShouldReturnOne(t *testing.T) {
// Setup fixture
source := config.MapSource(map[string]string{
"PORT": "not an int",
})
expected := 1

// Exercise SUT
actual := run.Run(source, nil)

// Verify results
if actual != expected {
t.Errorf("Unexpected response\nActual: %d\nExpected: %d", actual, expected)
}
}

func TestRun_WhenServeFails_ShouldReturnTwo(t *testing.T) {
// Setup fixture
source := config.MapSource(map[string]string{})
serveFunc := func(string, http.Handler) error {
return fmt.Errorf("some error")
}
expected := 2

// Exercise SUT
actual := run.Run(source, serveFunc)

// Verify results
if actual != expected {
t.Errorf("Unexpected response\nActual: %d\nExpected: %d", actual, expected)
}
}

func TestRun_WhenServeSucceeds_ShouldReturnZero(t *testing.T) {
// Setup fixture
source := config.MapSource(map[string]string{})
serveFunc := func(string, http.Handler) error {
return nil
}
expected := 0

// Exercise SUT
actual := run.Run(source, serveFunc)

// Verify results
if actual != expected {
t.Errorf("Unexpected response\nActual: %d\nExpected: %d", actual, expected)
}
}

0 comments on commit cc63744

Please sign in to comment.