Skip to content

Commit bd7eb64

Browse files
authored
Merge pull request #2 from sklevenz/dev
Dev
2 parents 55a6687 + d0722e2 commit bd7eb64

File tree

5 files changed

+42
-46
lines changed

5 files changed

+42
-46
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cf-api-server-go
22

3-
[![Test Status](https://github.com/sklevenz/cf-api-server-go/actions/workflows/test.yaml/badge.svg)](https://github.com/sklevenz/cf-api-server/actions)
4-
[![Build Status](https://github.com/sklevenz/cf-api-server-go/actions/workflows/build.yaml/badge.svg)](https://github.com/sklevenz/cf-api-server/actions)
3+
[![Test Status](https://github.com/sklevenz/cf-api-server-go/actions/workflows/test.yaml/badge.svg)](https://github.com/sklevenz/cf-api-server-go/actions)
4+
[![Build Status](https://github.com/sklevenz/cf-api-server-go/actions/workflows/build.yaml/badge.svg)](https://github.com/sklevenz/cf-api-server-go/actions)
55

66
mplementation of the [cf-api-spec](https://github.com/sklevenz/cf-api-spec) in Go. This project provides a Go-based solution adhering to the Cloud Foundry API specifications, enabling seamless integration and usage for Cloud Foundry-related development.
77

@@ -23,6 +23,7 @@ cf-api-server/
2323
│ ├── services/ # Business logic or service layer
2424
│ │ ├── api_service.go
2525
│ │ └── ...
26+
│ ├── server/ # HTTP server implementation
2627
│ ├── middleware/ # Middleware for request processing
2728
│ │ ├── logging.go
2829
│ │ ├── auth.go
@@ -39,8 +40,7 @@ cf-api-server/
3940
│ │ └── ...
4041
│ └── ...
4142
├── test/ # Tests and test utilities
42-
│ ├── integration/
43-
│ ├── unit/
43+
│ ├── integration/ # Integration tests
4444
│ └── ...
4545
├── go.mod # Go module file
4646
├── go.sum # Go module checksum file
@@ -57,6 +57,7 @@ This directory contains core application logic that is not intended to be expose
5757

5858
- **`handlers/`**: Defines HTTP route handlers that process incoming requests and return responses.
5959
- **`services/`**: Implements the business logic and acts as an intermediary between handlers and the data layer.
60+
- **`server/`**: Implements the HTTP server code to offload the main entry point.
6061
- **`middleware/`**: Contains reusable middleware functions for processing HTTP requests, such as logging or authentication.
6162
- **`config/`**: Manages application configurations, such as environment variables and settings.
6263

cmd/server/main_test.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

internal/server/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"net/http"
66
)
77

8+
func handler(w http.ResponseWriter, r *http.Request) {
9+
fmt.Fprintln(w, "Hello, World!")
10+
}
11+
812
func StartServer() {
9-
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
10-
fmt.Fprintln(w, "Hello, World!")
11-
})
13+
http.HandleFunc("/", handler)
1214

1315
fmt.Println("Server is running on http://localhost:8080")
1416
if err := http.ListenAndServe(":8080", nil); err != nil {

internal/server/server_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package server
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"testing"
7+
)
8+
9+
func TestHandler(t *testing.T) {
10+
// Create a request to pass to our handler
11+
req := httptest.NewRequest(http.MethodGet, "/", nil)
12+
13+
// Record the response
14+
rec := httptest.NewRecorder()
15+
16+
// Call the handler directly
17+
handler(rec, req)
18+
19+
// Check the response code
20+
if rec.Code != http.StatusOK {
21+
t.Errorf("expected status OK; got %v", rec.Code)
22+
}
23+
24+
// Check the response body
25+
expectedBody := "Hello, World!\n"
26+
if rec.Body.String() != expectedBody {
27+
t.Errorf("expected body %q; got %q", expectedBody, rec.Body.String())
28+
}
29+
}

test/integration/server_integration_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
)
1111

1212
func TestServerIntegration(t *testing.T) {
13+
// Wait befor starting the server
14+
time.Sleep(1 * time.Second)
15+
1316
// Start the server in a separate goroutine
1417
go func() {
1518
server.StartServer()

0 commit comments

Comments
 (0)