Skip to content
Open
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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: Show Go version
run: go version


2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Run the server:
go build -o notely && ./notely
```

"Manasa's version of Boot.dev's Notely app."

*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!
22 changes: 22 additions & 0 deletions ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 Go tests
run: go test ./...
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module github.com/bootdotdev/learn-cicd-starter

module github.com/bootdotdev/learn-cicd-starter

go 1.22

Expand Down
17 changes: 5 additions & 12 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@ package auth
import (
"errors"
"net/http"
"strings"
)

// Error for missing header
var ErrNoAuthHeaderIncluded = errors.New("no authorization header included")

// GetAPIKey -
// Temporarily broken GetAPIKey for CI failure
func GetAPIKey(headers http.Header) (string, error) {
authHeader := headers.Get("Authorization")
if authHeader == "" {
return "", ErrNoAuthHeaderIncluded
}
splitAuth := strings.Split(authHeader, " ")
if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" {
return "", errors.New("malformed authorization header")
}

return splitAuth[1], nil
return "BROKEN_KEY", nil
}
// CI trigger
// CI trigger comment
38 changes: 38 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKeySuccess(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "ApiKey apikey_12345")

key, err := GetAPIKey(headers)

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

if key != "apikey_12345" {
t.Fatalf("expected 'apikey_12345', got '%s'", key)
}
}

func TestGetAPIKeyMissingHeader(t *testing.T) {
headers := http.Header{}

_, err := GetAPIKey(headers)

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


}

if err != ErrNoAuthHeaderIncluded {
t.Fatalf("expected ErrNoAuthHeaderIncluded, got %v", err)
}
}