Skip to content

Update README.md with my name #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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.0"

- name: Print version
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.0"

- name: Test for style
run: |
echo "Files needing formatting:"
go fmt ./...
echo "Exit code of formatting test:"
test -z "$(go fmt ./...)" || echo $?
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![statusBadge](https://github.com/IntrepidSpiff/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 +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!

Tyler's version of Boot.dev's Notely app.
54 changes: 54 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package auth

import (
"testing"
"net/http"
)

func TestGetAPIKey (t *testing.T) {
tests := []struct {
name string
headers http.Header
expectedKey string
expectError bool
}{
{
name: "Valid API key in header",
headers: http.Header{"Authorization": []string{"ApiKey valid-key-123"}},
expectedKey: "valid-key-123",
expectError: false,
},
{
name: "Missing Authorization header",
headers: http.Header{},
expectedKey: "",
expectError: true,
},
{
name: "Invalid header",
headers: http.Header{"Authorization": []string{"Api Key valid-key-123"}},
expectedKey: "",
expectError: true,
},
}

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

// Check if error was expected
if tc.expectError && err == nil {
t.Errorf("Expected error but got none")
}
if !tc.expectError && err != nil {
t.Errorf("Did not expect error but got: %v", err)
}

// If no error was expected, check the key
if !tc.expectError && key != tc.expectedKey {
t.Errorf("Expected key %q, got %q", tc.expectedKey, key)
}
})
}
}