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
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.27.1"

- name: go test
run: |
go test ./... -cover
(exit 0)
- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: gosec
run: gosec ./...
style:
name: Style
runs-on: ubuntu-latest

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

- name:
uses: actions/setup-go@v6
with:
go-version: "1.27.1"

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

- name: install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: staticcheck
run: staticcheck ./...

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![test badge](https://github.com/Eutychus-Kimutai/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 +22,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!
"Netai's version of Boot.dev's Notely app."
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ require (
github.com/go-chi/cors v1.2.1
github.com/google/uuid v1.3.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.12.1
github.com/tursodatabase/libsql-client-go v0.0.0-20240220085343-4ae0eb9d0898
)

require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
nhooyr.io/websocket v1.8.7 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
github.com/tursodatabase/libsql-client-go v0.0.0-20240220085343-4ae0eb9d0898 h1:1MvEhzI5pvP27e9Dzz861mxk9WzXZLSJwzOU67cKTbU=
github.com/tursodatabase/libsql-client-go v0.0.0-20240220085343-4ae0eb9d0898/go.mod h1:9bKuHS7eZh/0mJndbUOrCx8Ej3PlsRDszj4L7oVYMPQ=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
1 change: 0 additions & 1 deletion internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ func GetAPIKey(headers http.Header) (string, error) {
if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" {
return "", errors.New("malformed authorization header")
}

return splitAuth[1], nil
}
51 changes: 51 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package auth

import (
"net/http"
"testing"

"errors"
"github.com/stretchr/testify/require"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
headers http.Header
expectedKey string
expectedError error
}{
{
name: "Valid API Key",
headers: http.Header{
"Authorization": []string{"ApiKey valid_api_key"},
},
expectedKey: "valid_api_key",
expectedError: nil,
},
{
name: "No Authorization Header",
headers: http.Header{
"Content-Type": []string{"application/json"},
},
expectedKey: "",
expectedError: ErrNoAuthHeaderIncluded,
},
{
name: "Malformed Authorization Header",
headers: http.Header{
"Authorization": []string{"Bearer some_token"},
},
expectedKey: "",
expectedError: errors.New("malformed authorization header"),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
apiKey, err := GetAPIKey(tt.headers)
require.Equal(t, tt.expectedKey, apiKey)
require.Equal(t, tt.expectedError, err)
})
}
}
21 changes: 21 additions & 0 deletions vendor/github.com/stretchr/testify/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading