diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..7603b5bfe0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +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.25.1" + + - name: Show Go version + run: go version + + diff --git a/README.md b/README.md index c2bec0368b..ec17e76296 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Run the server: go build -o notely && ./notely ``` +"Manasa's version of Boot.dev's Notely app." + *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! diff --git a/ci.yml b/ci.yml new file mode 100644 index 0000000000..f63e166922 --- /dev/null +++ b/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.25.1" + + - name: Run Go tests + run: go test ./... diff --git a/go.mod b/go.mod index 09e04f9c12..e4d15a2aae 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,5 @@ -module github.com/bootdotdev/learn-cicd-starter + + module github.com/bootdotdev/learn-cicd-starter go 1.22 diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f969aacf63..1ab7c7a835 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -3,21 +3,14 @@ package auth import ( "errors" "net/http" - "strings" ) +// Error for missing header var ErrNoAuthHeaderIncluded = errors.New("no authorization header included") -// GetAPIKey - +// Temporarily broken GetAPIKey for CI failure func GetAPIKey(headers http.Header) (string, error) { - authHeader := headers.Get("Authorization") - if authHeader == "" { - return "", ErrNoAuthHeaderIncluded - } - splitAuth := strings.Split(authHeader, " ") - if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" { - return "", errors.New("malformed authorization header") - } - - return splitAuth[1], nil + return "BROKEN_KEY", nil } +// CI trigger +// CI trigger comment diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 0000000000..4e12524887 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,38 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKeySuccess(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey apikey_12345") + + key, err := GetAPIKey(headers) + + if err != nil { + t.Fatalf("expected no error, got %v", err) + } + + if key != "apikey_12345" { + t.Fatalf("expected 'apikey_12345', got '%s'", key) + } +} + +func TestGetAPIKeyMissingHeader(t *testing.T) { + headers := http.Header{} + + _, err := GetAPIKey(headers) + + if err == nil { + t.Fatal("expected an error, got nil") + } + + +} + + if err != ErrNoAuthHeaderIncluded { + t.Fatalf("expected ErrNoAuthHeaderIncluded, got %v", err) + } +}