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
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI

on:
pull_request:
branches: [ main ]

jobs:
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.23.0"

- name: Get dependencies
run: go mod download

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

style:
name: Style
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23.0"

- 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 ./...


lint:
name: Lint
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.23.0"

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

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

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# learn-cicd-starter (Notely)
![Tests](https://github.com/Sashozk/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)

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 +22,5 @@ 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!

Sasho Zikov's version of Boot.dev's Notely app.
5 changes: 5 additions & 0 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"errors"
"fmt"
"net/http"
"strings"
)
Expand All @@ -21,3 +22,7 @@ func GetAPIKey(headers http.Header) (string, error) {

return splitAuth[1], nil
}

func main() {
fmt.Println("hello world!")
}
37 changes: 37 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
t.Run("returns key when header is valid", func(t *testing.T) {
h := http.Header{}
h.Set("Authorization", "ApiKey abc123")
got, err := GetAPIKey(h)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != "abc123" {
t.Fatalf("expected abc123, got %q", got)
}
})

t.Run("returns ErrNoAuthHeaderIncluded when header missing", func(t *testing.T) {
h := http.Header{}
_, err := GetAPIKey(h)
if err != ErrNoAuthHeaderIncluded {
t.Fatalf("expected ErrNoAuthHeaderIncluded, got %v", err)
}
})

t.Run("returns error when header malformed", func(t *testing.T) {
h := http.Header{}
h.Set("Authorization", "Bearer abc123")
_, err := GetAPIKey(h)
if err == nil {
t.Fatalf("expected error for malformed header, got nil")
}
})
}