Skip to content
Permalink
Browse files

Fix env tests

  • Loading branch information...
Raggaer committed Jun 10, 2019
1 parent 09fd4ee commit b336e5cd9bddf5bb540a6750339f2b98de4c3c93
Showing with 16 additions and 4 deletions.
  1. +16 −4 test/env_test.go
@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"testing"
)

@@ -27,16 +28,27 @@ func TestEnvironmentGet(t *testing.T) {
port := make(chan int, 1)
defer createTestServer(port, t).Close()
addr := <-port
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/env/get", addr))
// First set the env variable
respSet, err := http.Get(fmt.Sprintf("http://localhost:%d/env/set", addr))
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
bodyContent, err := ioutil.ReadAll(resp.Body)
defer respSet.Body.Close()
if respSet.StatusCode != 200 {
t.Fatalf("Wrong env.set status code. Expected '200' but got '%d'", respSet.StatusCode)
}

// Get the env variable
respGet, err := http.Get(fmt.Sprintf("http://localhost:%d/env/get", addr))
if err != nil {
t.Fatal(err)
}
defer respGet.Body.Close()
bodyContent, err := ioutil.ReadAll(respGet.Body)
if err != nil {
t.Fatal(err)
}
if string(bodyContent) != "Testing env.set function" {
if strings.TrimSpace(string(bodyContent)) != "Testing env.set function" {
t.Fatalf("Wrong env.get value. Expected 'Testing env.set function' but got '%s'", string(bodyContent))
}
}

0 comments on commit b336e5c

Please sign in to comment.
You can’t perform that action at this time.