Skip to content
Snippets Groups Projects
Commit 6611e6c7 authored by Mario Vazquez's avatar Mario Vazquez
Browse files

Merge branch 'main' of github.com:mvazquezc/reverse-words into main

parents 4f781af6 7bfeae16
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
"os"
)
func TestReturnRelease(t *testing.T) {
......@@ -24,6 +25,27 @@ func TestReturnRelease(t *testing.T) {
}
}
func TestReturnHostname(t *testing.T) {
req, err := http.NewRequest("GET", "/hostname", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(ReturnHostname)
handler.ServeHTTP(rr, req)
if rr.Code != http.StatusOK {
t.Errorf("ReturnHostname returned wrong status code, expected %v, got %v", http.StatusOK, rr.Code)
}
expectedHostname, err := os.Hostname()
if err != nil {
t.Fatal(err)
}
if ! strings.Contains(rr.Body.String(), expectedHostname) {
t.Errorf("ReturnHostname returned wrong hostname, expected %v, got %v", expectedHostname, rr.Body.String())
}
}
func TestReturnHealth(t *testing.T) {
req, err := http.NewRequest("GET", "/health", nil)
if err != nil {
......@@ -61,6 +83,18 @@ func TestReverseWord(t *testing.T) {
}
}
func TestGetEnv(t *testing.T) {
os.Setenv("FOO", "BAR")
result := getEnv("FOO", "DEFAULT_VALUE")
if result != "BAR" {
t.Errorf("TestGetEnv with existing variable failed, expected %v, got %v", "BAR", result)
}
result = getEnv("NOT_EXISTING_VAR", "DEFAULT_VALUE")
if result != "DEFAULT_VALUE" {
t.Errorf("TestGetEnv with default value failed, expected %v, got %v", "DEFAULT_VALUE", result)
}
}
func TestReverse(t *testing.T) {
result := reverse("PALC")
if result != "CLAP" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment