Skip to content

Updated README #1409

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 16 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.23.0"

- name: Run Go Unit Test
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.23.0"

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




3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![my workflow](https://github.com/AchiugoTrust/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!
Trust's version of Boot.dev's Notely app xoxo.
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"
"errors"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
header http.Header
expectedKey string
expectingErr bool
expectedError error
}{
{
name: "valid header",
header: http.Header{"Authorization": []string{"ApiKey abc123"}},
expectedKey: "abc123",
expectingErr: false,
},
{
name: "no header",
header: http.Header{},
expectedKey: "",
expectingErr: true,
expectedError: ErrNoAuthHeaderIncluded,
},
{
name: "malformed header",
header: http.Header{"Authorization": []string{"Bearer abc123"}},
expectedKey: "",
expectingErr: true,
expectedError: errors.New("malformed authorization header"),
},
}

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

if tt.expectingErr {
if err == nil {
t.Errorf("expected error but got nil")
} else if err.Error() != tt.expectedError.Error() {
t.Errorf("expected error '%v', got '%v'", tt.expectedError, err)
}
} else {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if key != tt.expectedKey {
t.Errorf("expected key '%s', got '%s'", tt.expectedKey, key)
}
}
})
}
}

5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type apiConfig struct {
//go:embed static/*
var staticFiles embed.FS


func main() {
err := godotenv.Load(".env")
if err != nil {
Expand All @@ -37,6 +38,8 @@ func main() {

apiCfg := apiConfig{}



// https://github.com/libsql/libsql-client-go/#open-a-connection-to-sqld
// libsql://[your-database].turso.io?authToken=[your-auth-token]
dbURL := os.Getenv("DATABASE_URL")
Expand Down Expand Up @@ -93,6 +96,8 @@ func main() {
Handler: router,
}



log.Printf("Serving on port: %s\n", port)
log.Fatal(srv.ListenAndServe())
}