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

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

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

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

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

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

- name: run gosec
run: gosec ./...
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

![alt text goes here](https://github.com/Yashwarhade8010/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,6 @@ 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!

Yash's version of Boot.dev's Notely app.
Yash's version of Boot.dev's Notely app.
1 change: 1 addition & 0 deletions handler_ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package main
import "net/http"

func handlerReadiness(w http.ResponseWriter, r *http.Request) {

respondWithJSON(w, http.StatusOK, map[string]string{"status": "ok"})
}
70 changes: 70 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
header string
wantKey string
wantErr string
}{
{
name: "valid api key",
header: "ApiKey my-secret-key",
wantKey: "my-secret-key",
},
{
name: "missing authorization header",
wantErr: ErrNoAuthHeaderIncluded.Error(),
},
{
name: "wrong auth scheme",
header: "Bearer token",
wantErr: "malformed authorization header",
},
{
name: "missing api key",
header: "ApiKey",
wantErr: "malformed authorization header",
},
{
name: "empty api key",
header: "ApiKey ",
wantErr: "malformed authorization header",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
headers := http.Header{}
if tt.header != "" {
headers.Set("Authorization", tt.header)
}

gotKey, err := GetAPIKey(headers)

if gotKey != tt.wantKey {
t.Fatalf("expected key %q, got %q", tt.wantKey, gotKey)
}

if tt.wantErr == "" {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
return
}

if err == nil {
t.Fatal("expected an error but got nil")
}

if err.Error() != tt.wantErr {
t.Fatalf("expected error %q, got %q", tt.wantErr, err.Error())
}
})
}
}
Binary file added vendor/.DS_Store
Binary file not shown.
Binary file added vendor/github.com/.DS_Store
Binary file not shown.