From 52657f39bf4f45cf0cfc14254d5a77abfe176533 Mon Sep 17 00:00:00 2001 From: Sathwik Bhandarkar Date: Mon, 2 Mar 2026 09:46:15 +0530 Subject: [PATCH 1/3] add: configured CI pipelines --- .gitignore | 2 ++ main.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41f6461 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/Ocp +*.env* \ No newline at end of file diff --git a/main.go b/main.go index 834cac5..4a29a8d 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ func main() { func whoAmI(response http.ResponseWriter, r *http.Request) { who := []whoami{ - whoami{Name: "Michael Levan", + {Name: "Intern at IBM", Title: "Kubernetes Engineer", State: "NJ", }, @@ -31,14 +31,14 @@ func whoAmI(response http.ResponseWriter, r *http.Request) { } func homePage(response http.ResponseWriter, r *http.Request) { - fmt.Fprintf(response, "Welcome to the Go Web API!") + fmt.Fprintf(response, "Welcome to the Go Web API!\n\nOther endpoints\n- /whoami\n- /aboutme") fmt.Println("Endpoint Hit: homePage") } func aboutMe(response http.ResponseWriter, r *http.Request) { - who := "MichaelLevan" + who := "Intern at IBM" - fmt.Fprintf(response, "A little bit about Michael Levan...") + fmt.Fprintf(response, "A little bit about Intern at IBM...") fmt.Println("Endpoint Hit: ", who) } From d0df26d89823b50503f8e32ccf5748e4f0476d23 Mon Sep 17 00:00:00 2001 From: Sathwik Bhandarkar Date: Wed, 4 Mar 2026 14:32:34 +0530 Subject: [PATCH 2/3] add: test case for /ping endpoint --- go.mod | 2 +- main.go | 8 +++++++- main_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 main_test.go diff --git a/go.mod b/go.mod index b48dafc..d8b2b88 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module main +module github.com/Sathwik004/GoWebAPI go 1.16 diff --git a/main.go b/main.go index 4a29a8d..27848f2 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func whoAmI(response http.ResponseWriter, r *http.Request) { } func homePage(response http.ResponseWriter, r *http.Request) { - fmt.Fprintf(response, "Welcome to the Go Web API!\n\nOther endpoints\n- /whoami\n- /aboutme") + fmt.Fprintf(response, "Welcome to the Go Web API!\n\nOther endpoints\n- /whoami\n- /aboutme\n- /ping") fmt.Println("Endpoint Hit: homePage") } @@ -42,10 +42,16 @@ func aboutMe(response http.ResponseWriter, r *http.Request) { fmt.Println("Endpoint Hit: ", who) } +func ping(response http.ResponseWriter, r *http.Request) { + fmt.Fprintf(response, "pong") + fmt.Println("Endpoint Hit: ping") +} + func request1() { http.HandleFunc("/", homePage) http.HandleFunc("/aboutme", aboutMe) http.HandleFunc("/whoami", whoAmI) + http.HandleFunc("/ping", ping) log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..c9e752e --- /dev/null +++ b/main_test.go @@ -0,0 +1,38 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +// TestPingEndpoint tests that the /ping endpoint returns "pong" +func TestPingEndpoint(t *testing.T) { + // Create a request to the /ping endpoint + req, err := http.NewRequest("GET", "/ping", nil) + if err != nil { + t.Fatal(err) + } + + // Create a ResponseRecorder to record the response + rr := httptest.NewRecorder() + + // Create a handler and serve the request + handler := http.HandlerFunc(ping) + handler.ServeHTTP(rr, req) + + // Check the status code + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusOK) + } + + // Check the response body + expected := "pong" + if rr.Body.String() != expected { + t.Errorf("handler returned unexpected body: got %v want %v", + rr.Body.String(), expected) + } +} + +// Made with Bob From 0bac958b498f47a5e1a13af881039b02f06129a3 Mon Sep 17 00:00:00 2001 From: Sathwik Bhandarkar Date: Thu, 5 Mar 2026 12:37:48 +0530 Subject: [PATCH 3/3] test: webhook trigger --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d0aee10..6c16014 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # GoWebAPI Example Go web API + +Hello