diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..8cf4bcaf1b9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +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: Run tests + run: go test -cover ./... diff --git a/README.md b/README.md index c2bec0368b7..bff3a28b841 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,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! +Manjunath R appu diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..289979edff7 --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,57 @@ +package auth + +import ( + "errors" + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + headers http.Header + want string + wantErr error + }{ + { + name: "no authorization header", + headers: http.Header{}, + want: "", + wantErr: ErrNoAuthHeaderIncluded, + }, + { + name: "valid api key", + headers: http.Header{ + "Authorization": []string{"ApiKey test-api-key"}, + }, + want: "test-api-key", + wantErr: nil, + }, + { + name: "malformed authorization header", + headers: http.Header{ + "Authorization": []string{"Bearer test-token"}, + }, + want: "", + wantErr: errors.New("malformed authorization header"), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetAPIKey(tt.headers) + + if got != tt.want { + t.Errorf("GetAPIKey() got = %v, want %v", got, tt.want) + } + + if tt.wantErr != nil { + if err == nil || err.Error() != tt.wantErr.Error() { + t.Errorf("GetAPIKey() error = %v, want %v", err, tt.wantErr) + } + } else if err != nil { + t.Errorf("GetAPIKey() unexpected error = %v", err) + } + }) + } +}