converted to go modules, added gorilla web toolkit, added test, changed yosoy to respond with JSON rather than plain text, added travis support

This commit is contained in:
Łukasz Budnik
2021-02-04 00:29:22 +01:00
parent cd90e887fe
commit 1a1f4cf14d
9 changed files with 207 additions and 154 deletions

View File

@@ -1,16 +1,24 @@
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHandler(t *testing.T) {
req, err := http.NewRequest("GET", "/", nil)
os.Setenv("YOSOY_SHOW_ENVS", "true")
os.Setenv("YOSOY_SHOW_FILES", ".gitignore")
req, err := http.NewRequest("GET", "https://example.org/sample/path", nil)
if err != nil {
t.Fatal(err)
}
req.Header.Set("Accept", "*/*")
rr := httptest.NewRecorder()
handler := http.HandlerFunc(handler)
@@ -20,4 +28,12 @@ func TestHandler(t *testing.T) {
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK)
}
var response response
json.Unmarshal(rr.Body.Bytes(), &response)
assert.Equal(t, 1, response.Counter)
assert.Equal(t, "example.org", response.Host)
assert.NotEmpty(t, response.EnvVariables)
assert.NotEmpty(t, response.Files[".gitignore"])
}