Skip to content
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
pull_request:
branches: [ "main" ]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Run unit tests
run: go test ./...

style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Check formatting
run: test -z $(go fmt ./...)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![CI](https://github.com/Saharyasa/learn-cicd-starter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Saharyasa/learn-cicd-starter/actions/workflows/ci.yml)
# 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!
Sahar Yasa's version of Boot.dev's Notely app
48 changes: 48 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package auth

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

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
header string
want string
wantErr bool
}{
{name: "no header", header: "", wantErr: true},
{name: "wrong scheme", header: "Bearer abc123", wantErr: true},
// Function currently returns "" and NO error for an empty ApiKey value
{name: "empty key", header: "ApiKey ", want: "", wantErr: false},
{name: "valid", header: "ApiKey abc123", want: "abc123", wantErr: false},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
if tc.header != "" {
req.Header.Set("Authorization", tc.header)
}

// GetAPIKey takes http.Header
got, err := GetAPIKey(req.Header)

if tc.wantErr {
if err == nil {
t.Fatalf("expected an error, got key=%q", got)
}
return
}

if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != tc.want {
t.Fatalf("want %q, got %q", tc.want, got)
}
})
}
}
1 change: 1 addition & 0 deletions trigger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# trigger ci