Skip to content

Commit

Permalink
generate reports coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
djengua committed Dec 18, 2023
1 parent 258dac1 commit 1023f0d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ on:
- main

jobs:
test:
name: Test Application
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1^1.18
- name: Check out code into hte Go module directory
uses: actions/checkout@v2
- name: Run Test
run: make test
- name: Coverage Check
run: make coverage
- name: Generate Report
run: make report
- name: Copy Files
run: |
mkdir reports
cp cover.html reports/.
- name: Archive
uses: actions/upload-artifact@v2
with:
name: reports
path: reports
build:
name: Build App
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
api
api

coverage.out
cover.html
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ build:
go build -o api main.go
server:
go run main.go
test:
go test ./... -coverprofile=coverage.out
coverage:
go tool cover -func coverage.out | grep "total:" | awk '{print ((int($$3) > 80) != 1 )}'
report:
go tool cover -html=coverage.out -o cover.html

.PHONY: build server
.PHONY: build server test coverage report
2 changes: 1 addition & 1 deletion handlers/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TranslateHandler(w http.ResponseWriter, r *http.Request) {
language = defaultLanguage
}
word := strings.ReplaceAll(r.URL.Path, "/", "")
translation := translation.Translate(language, word)
translation := translation.Translate(word, language)
response := Resp{
Language: language,
Translation: translation,
Expand Down
16 changes: 3 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
package main

import (
"encoding/json"
"log"
"net/http"

"github.com/djengua/rifa-api/handlers"
)

func main() {
addr := ":8080"
mux := http.NewServeMux()

mux.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w)
w.Header().
Set("Content-Type", "application/json; charset=utf-8")
resp := Resp{
Language: "English",
Translation: "Hello",
}
if err := enc.Encode(resp); err != nil {
panic("unable to encode response")
}
})
mux.HandleFunc("/hello", handlers.TranslateHandler)
log.Printf("listening on %s\n", addr)
log.Fatal(http.ListenAndServe(addr, mux))
}
Expand Down

0 comments on commit 1023f0d

Please sign in to comment.