diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..380df81a7a4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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: Running Unit tests + run: go test -cover ./... \ No newline at end of file diff --git a/README.md b/README.md index c2bec0368b7..a9fb8fc1d14 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,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! +Lokesh's version of Boot.dev's Notely app. + +![CI Status](https://github.com/lokeshjatoth/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) diff --git a/go1.22.5.linux-amd64.tar.gz b/go1.22.5.linux-amd64.tar.gz new file mode 100644 index 00000000000..633e9df90a3 Binary files /dev/null and b/go1.22.5.linux-amd64.tar.gz differ diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..4d794a868fb --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,42 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey_Valid(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey my-secret-key") + + key, err := GetAPIKey(headers) + + if err != nil { + t.Fatalf("expected no error, got %v", err) + } + + if key != "my-secret-key" { + t.Errorf("expected 'my-secret-key', got '%s'", key) + } +} + +func TestGetAPIKey_MissingHeader(t *testing.T) { + headers := http.Header{} + + _, err := GetAPIKey(headers) + + if err == nil { + t.Fatal("expected error, got nil") + } +} + +func TestGetAPIKey_InvalidFormat(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "Bearer token123") + + _, err := GetAPIKey(headers) + + if err == nil { + t.Fatal("expected error for invalid format") + } +} \ No newline at end of file