Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
69bcba6
Add my name to README
Oct 28, 2025
ef3590a
add ci.yml file
ivanbonifazi-cpu Oct 30, 2025
ddd0017
change ci.yml file to print go version
ivanbonifazi-cpu Oct 30, 2025
cfa0a01
Replace go version with go test
ivanbonifazi-cpu Oct 30, 2025
7b91ba1
Break test to verify CI catches failures
ivanbonifazi-cpu Oct 30, 2025
d699bce
Fix test - CI should pass now
ivanbonifazi-cpu Oct 30, 2025
e9cee41
Break test to verify CI catches failures
ivanbonifazi-cpu Oct 30, 2025
d91474e
Fix test - CI should pass
ivanbonifazi-cpu Oct 30, 2025
7de2d87
Fix test - should pass on CI
ivanbonifazi-cpu Oct 30, 2025
12d7c12
--- test
ivanbonifazi-cpu Oct 30, 2025
999d692
Fix test - should pass on CI
ivanbonifazi-cpu Oct 30, 2025
d0a6193
Update CI workflow
ivanbonifazi-cpu Oct 30, 2025
d10797f
Fix CI workflow - correct checkout and go version
ivanbonifazi-cpu Oct 30, 2025
2d71716
add code coverage to CI tests
ivanbonifazi-cpu Oct 30, 2025
9a21236
Add CI badge to README
ivanbonifazi-cpu Oct 30, 2025
39a81ec
Fix badge syntax - remove extra space
ivanbonifazi-cpu Oct 30, 2025
4a765e3
Add style check to CI workflow
ivanbonifazi-cpu Oct 31, 2025
4ef2889
Add style check to CI workflow
ivanbonifazi-cpu Oct 31, 2025
ce3f39b
Trigger CI - code is formatted
ivanbonifazi-cpu Oct 31, 2025
13cebb9
Fix YAML syntax in CI workflow
ivanbonifazi-cpu Oct 31, 2025
97cf01d
Add staticcheck to CI style job
ivanbonifazi-cpu Oct 31, 2025
4c806c0
Add unused function to test staticcheck
ivanbonifazi-cpu Oct 31, 2025
fecc86c
Removed unused Function
ivanbonifazi-cpu Oct 31, 2025
02c7aaa
Removed unused Function
ivanbonifazi-cpu Oct 31, 2025
3285c68
Removed unused Function
ivanbonifazi-cpu Oct 31, 2025
2f68bc0
Removed unused Function
ivanbonifazi-cpu Oct 31, 2025
410a464
Install staticcheck in CI workflow
ivanbonifazi-cpu Oct 31, 2025
ae321e4
Add go sec install
ivanbonifazi-cpu Oct 31, 2025
8fb3ced
Fix gosec security issues
ivanbonifazi-cpu Oct 31, 2025
82a61ed
Fix missing closing brace in json.go
ivanbonifazi-cpu Nov 3, 2025
87afe25
Add time import to main.go
ivanbonifazi-cpu Nov 3, 2025
0d5e306
Format code with go fmt
ivanbonifazi-cpu Nov 3, 2025
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
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: ci

on:
pull_request:
branches: [main]

jobs:
tests:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Run tests
run: go test ./... --cover

style:
name: Style
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Check formatting
run: test -z $(go fmt ./...)

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# learn-cicd-starter (Notely)
![CI](https://github.com/ivanbonifazi-cpu/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)

# learn-cicd-starter (Notely)

This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).

Expand All @@ -21,3 +23,4 @@ go build -o notely && ./notely
*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`.

You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course!
IVAN
60 changes: 60 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
// Test case 1: Valid API key in header
t.Run("Valid API key", func(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "ApiKey my-secret-key-123")

apiKey, err := GetAPIKey(headers)

if err != nil {
t.Fatalf("Expected no error, got %v", err)
}

expected := "my-secret-key-123"
if apiKey != expected {
t.Errorf("Expected %s, got %s", expected, apiKey)
}
})

// Test case 2: No Authorization header
t.Run("No Authorization header", func(t *testing.T) {
headers := http.Header{}

_, err := GetAPIKey(headers)

if err == nil {
t.Fatal("Expected an error, got nil")
}
})

// Test case 3: Malformed Authorization header (missing "ApiKey")
t.Run("Malformed header - no ApiKey prefix", func(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "Bearer my-token")

_, err := GetAPIKey(headers)

if err == nil {
t.Fatal("Expected an error, got nil")
}
})

// Test case 4: Malformed Authorization header (only "ApiKey", no key)
t.Run("Malformed header - no key value", func(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "ApiKey")

_, err := GetAPIKey(headers)

if err == nil {
t.Fatal("Expected an error, got nil")
}
})
}
4 changes: 3 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
return
}
w.WriteHeader(code)
w.Write(dat)
if _, err := w.Write(dat); err != nil {
log.Printf("Error writing response: %v", err)
}
}
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -89,8 +90,9 @@ func main() {

router.Mount("/v1", v1Router)
srv := &http.Server{
Addr: ":" + port,
Handler: router,
Addr: ":" + port,
Handler: router,
ReadHeaderTimeout: 10 * time.Second,
}

log.Printf("Serving on port: %s\n", port)
Expand Down