-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9ec226
commit 3519410
Showing
5 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |