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

on:
pull_request:
branches: [main]

jobs:
tests:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v6

- name: Run tests
run: go test -cover ./...
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,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!
Manjunath R appu
57 changes: 57 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package auth

import (
"errors"
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
headers http.Header
want string
wantErr error
}{
{
name: "no authorization header",
headers: http.Header{},
want: "",
wantErr: ErrNoAuthHeaderIncluded,
},
{
name: "valid api key",
headers: http.Header{
"Authorization": []string{"ApiKey test-api-key"},
},
want: "test-api-key",
wantErr: nil,
},
{
name: "malformed authorization header",
headers: http.Header{
"Authorization": []string{"Bearer test-token"},
},
want: "",
wantErr: errors.New("malformed authorization header"),
},
}

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

if got != tt.want {
t.Errorf("GetAPIKey() got = %v, want %v", got, tt.want)
}

if tt.wantErr != nil {
if err == nil || err.Error() != tt.wantErr.Error() {
t.Errorf("GetAPIKey() error = %v, want %v", err, tt.wantErr)
}
} else if err != nil {
t.Errorf("GetAPIKey() unexpected error = %v", err)
}
})
}
}