Skip to content

Commit

Permalink
Test app initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gmontalvoy committed Dec 5, 2023
1 parent f9ec226 commit 3519410
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 46 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name: Building the application
name: Build and Test
on:
push:
branches:
- main
jobs:
Build:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4

# - name: Build
# uses: docker/build-push-action@v4
# with:
# context: .
# push: true
# tags: user/app:latest
- name: Build
run: |
go build -v ./...
- name: Test
run: go test
17 changes: 0 additions & 17 deletions .github/workflows/Compliance.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/Meta.yml

This file was deleted.

34 changes: 34 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"net/http"
"net/http/httptest"
"testing"
)

func TestHandler(t *testing.T) {
// Crear un request para pasar al handler.
req, err := http.NewRequest("GET", "/", nil)
if err != nil {
t.Fatal(err)
}

// Crear un ResponseRecorder (httptest.ResponseWriter) para grabar las respuestas.
rr := httptest.NewRecorder()
handler := http.HandlerFunc(handler)

// El handler satisface http.Handler, así que podemos llamar a su método ServeHTTP directamente
// y pasarle nuestro Request y ResponseRecorder.
handler.ServeHTTP(rr, req)

// Comprobar el código de estado de la respuesta.
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler devolvió un código incorrecto: obtuvo %v, esperaba %v", status, http.StatusOK)
}

// Comprobar el cuerpo de la respuesta.
expected := `Hola, este es un servidor web básico en Go!`
if rr.Body.String() != expected {
t.Errorf("handler devolvió un cuerpo inesperado: obtuvo %v, esperaba %v", rr.Body.String(), expected)
}
}
16 changes: 16 additions & 0 deletions sampleGoApp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
"log"
"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hola, este es un servidor web básico en Go!")
}

func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}

0 comments on commit 3519410

Please sign in to comment.