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
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@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.26.0"

- name: Run tests
run: go test ./... -cover
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ 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!

Obi's version of Boot.dev's Notely app.


![test passing badge](https://github.com/uobinnao/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)
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 @@
package auth

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

func TestGetAPIKey(t *testing.T) {
tests := map[string]struct {
headers http.Header
want string
wantErr bool
}{
"valid_api_key": {
headers: http.Header{"Authorization": []string{"ApiKey some-secret-key-123"}},
want: "some-secret-key-123",
wantErr: false,
},
"missing_auth_header": {
headers: http.Header{},
want: "",
wantErr: true,
},
"malformed_header_missing_apikey_prefix": {
headers: http.Header{"Authorization": []string{"Bearer some-token"}},
want: "",
wantErr: true,
},
"malformed_header_too_short": {
headers: http.Header{"Authorization": []string{"ApiKey"}},
want: "",
wantErr: true,
},
}

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

// Check if we expected an error
if (err != nil) != tc.wantErr {
t.Fatalf("GetAPIKey() error = %v, wantErr %v", err, tc.wantErr)
}

// Check if the result matches our expectation
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("GetAPIKey() got = %v, want %v", got, tc.want)
}
})
}
}