Skip to content
Open

astlyll #2724

Show file tree
Hide file tree
Changes from 8 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
22 changes: 22 additions & 0 deletions .github/workflows/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@v6



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

- name: Force Failure
run: (exit 0)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,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!
![alt text goes here](https://github.com/habtse/learn-cicd-starter/actions/workflows/ci/badge.svg)
Habtamu's version of Boot.dev's Notely app
52 changes: 52 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// unit test for getAPIKey function
package auth

import (
"testing"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
headers map[string][]string
want string
wantErr bool
}{
{
name: "valid API key",
headers: map[string][]string{
"Authorization": {"ApiKey my-api-key"},
},
want: "my-api-key",
wantErr: false,
},
{
name: "missing Authorization header",
headers: map[string][]string{},
want: "",
wantErr: true,
},
{
name: "malformed Authorization header",
headers: map[string][]string{
"Authorization": {"Bearer my-api-key"},
},
want: "",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetAPIKey(tt.headers)
if (err != nil) != tt.wantErr {
t.Errorf("GetAPIKey() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("GetAPIKey() = %v, want %v", got, tt.want)
}
})
}
}