Implementation of route add

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-10-03 20:56:40 +02:00
parent 9f7fc8ce62
commit 4357b1ad20
2 changed files with 37 additions and 29 deletions
+27 -6
View File
@@ -1,11 +1,32 @@
package client
import "testing"
import (
"net/http"
"testing"
func TestInvalidURL(t *testing.T) {
err := AddRoute("http://localhost;8080", "/hi", "GET", "bash -c", "echo 'Hi' | kapow set /response/body")
if err == nil {
t.Error("expect to fail due invalid url")
t.Fail()
gock "gopkg.in/h2non/gock.v1"
)
func TestSuccessOnCorrectRoute(t *testing.T) {
defer gock.Off()
gock.New("http://localhost").
Put("/routes").
MatchType("json").
JSON(map[string]string{
"method": "GET",
"url_pattern": "/hello",
"entrypoint": "",
"command": "echo Hello World | kapow set /response/body",
}).
Reply(http.StatusCreated).
JSON(map[string]string{})
err := AddRoute("http://localhost", "/hello", "GET", "", "echo Hello World | kapow set /response/body")
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if gock.IsDone() == false {
t.Error("Expected endpoint call not made")
}
}