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
21 changes: 21 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: cd
on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Build
run: ./scripts/buildprod.sh
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.25.1"

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

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[![ci](https://github.com/itselcid/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/itselcid/learn-cicd-starter/actions/workflows/ci.yml)

# learn-cicd-starter (Notely)

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

## Local Development
Expand All @@ -18,6 +21,6 @@ Run the server:
go build -o notely && ./notely
```

*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`.
_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!
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!
67 changes: 67 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
headers http.Header
expectedKey string
expectedError error
}{
{
name: "Valid API Key",
headers: http.Header{
"Authorization": []string{"ApiKey test-api-key-123"},
},
expectedKey: "test-api-key-123",
expectedError: nil,
},
{
name: "No Authorization Header",
headers: http.Header{},
expectedKey: "",
expectedError: ErrNoAuthHeaderIncluded,
},
{
name: "Malformed Authorization Header - Missing ApiKey prefix",
headers: http.Header{
"Authorization": []string{"Bearer test-token"},
},
expectedKey: "",
expectedError: nil, // Will check error message instead
},
{
name: "Malformed Authorization Header - No space",
headers: http.Header{
"Authorization": []string{"ApiKeytest-api-key"},
},
expectedKey: "",
expectedError: nil, // Will check error message instead
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
key, err := GetAPIKey(tt.headers)

if key != tt.expectedKey {
t.Errorf("Expected key %q, got %q", tt.expectedKey, key)
}

if tt.expectedError != nil {
if err != tt.expectedError {
t.Errorf("Expected error %v, got %v", tt.expectedError, err)
}
} else if tt.name != "Valid API Key" {
// For malformed header tests, just check that an error occurred
if err == nil {
t.Errorf("Expected an error for malformed header, got nil")
}
}
})
}
}