diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..b7c58bff85b --- /dev/null +++ b/.github/workflows/ci.yml @@ -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@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.27.1" + - name: Success + run: go test ./... -cover + style: + name: Style + 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.27.1" + - name: Formating + run: test -z $(go fmt ./...) + - name: Success + run: (exit 0) + - 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 + diff --git a/README.md b/README.md index eb5dca97a5a..c74103f8d53 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ + + +[![CI Status](https://github.com/amilujinovic/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/amilujinovic/learn-cicd-starter/actions) + +[![CI Status](https://github.com///actions/workflows//badge.svg)](https://github.com///actions) + + +[![CI Status](https://github.com/amilujinovic/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/amilujinovic/learn-cicd-starter/actions) + + # 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). @@ -21,3 +31,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! +Amil's version of Boot.dev's Notely app diff --git a/Re b/Re new file mode 100644 index 00000000000..e69de29bb2d diff --git a/go.mod b/go.mod index edca50dbb9b..7380acf8a3a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bootdotdev/learn-cicd-starter -go 1.27.1 +go 1.22.2 require ( github.com/go-chi/chi v1.5.4 diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..41c632eded5 --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,61 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + headers http.Header + expectedKey string + expectError bool + }{ + { + name: "Validni API ključ", + headers: http.Header{ + "Authorization": []string{"ApiKey moj_tajni_kljuc_123"}, + }, + expectedKey: "moj_tajni_kljuc_123", + expectError: false, + }, + { + name: "Nedostaje Authorization zaglavlje", + headers: http.Header{}, + expectedKey: "", + expectError: true, + }, + { + name: "Pogrešan format - nedostaje ApiKey prefiks", + headers: http.Header{ + "Authorization": []string{"samo_kljuc"}, + }, + expectedKey: "", + expectError: true, + }, + { + name: "Pogrešna šema - koristi Bearer umesto ApiKey", + headers: http.Header{ + "Authorization": []string{"Bearer neki_token"}, + }, + expectedKey: "", + expectError: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + key, err := GetAPIKey(tt.headers) + + if (err != nil) != tt.expectError { + t.Errorf("GetAPIKey() greška = %v, očekivana greška %v", err, tt.expectError) + return + } + + if key != tt.expectedKey { + t.Errorf("GetAPIKey() = %v, očekivano %v", key, tt.expectedKey) + } + }) + } +}