From d2c04c206be42412b2c8ffd6bd61b191c14774a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Bach=C3=A9?= Date: Sun, 17 Mar 2019 14:36:14 -0700 Subject: [PATCH] Removed http stuff Since it's not used anymore --- internal/utils/http.go | 35 ------------------- internal/utils/http_test.go | 68 ------------------------------------- 2 files changed, 103 deletions(-) delete mode 100644 internal/utils/http.go delete mode 100644 internal/utils/http_test.go diff --git a/internal/utils/http.go b/internal/utils/http.go deleted file mode 100644 index 8aa7e18..0000000 --- a/internal/utils/http.go +++ /dev/null @@ -1,35 +0,0 @@ -package utils - -import ( - "flag" - "fmt" - "io/ioutil" - "net/http" - "strconv" -) - -func handleSDP(sdpChan chan string) func(w http.ResponseWriter, r *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - body, _ := ioutil.ReadAll(r.Body) - fmt.Fprintf(w, "done") - sdpChan <- string(body) - } -} - -// HTTPSDPServer starts a HTTP Server that consumes SDPs -func HTTPSDPServer() chan string { - port := flag.Int("port", 8080, "http server port") - flag.Parse() - - sdpChan := make(chan string) - http.HandleFunc("/sdp", handleSDP(sdpChan)) - - go func() { - err := http.ListenAndServe(":"+strconv.Itoa(*port), nil) - if err != nil { - panic(err) - } - }() - - return sdpChan -} diff --git a/internal/utils/http_test.go b/internal/utils/http_test.go deleted file mode 100644 index 92cd328..0000000 --- a/internal/utils/http_test.go +++ /dev/null @@ -1,68 +0,0 @@ -package utils - -import ( - "bytes" - "io/ioutil" - "net/http" - "net/http/httptest" - "testing" - - "github.com/stretchr/testify/assert" -) - -func Test_HTTPHandler(t *testing.T) { - assert := assert.New(t) - - stream := &bytes.Buffer{} - - sdpChan := make(chan string) - handler := handleSDP(sdpChan) - - done := make(chan struct{}) - msg := "Hello\n" - _, err := stream.WriteString(msg) - go func() { - assert.Nil(err) - res := <-sdpChan - assert.Equal(msg, res) - close(done) - }() - - req := httptest.NewRequest("POST", "http://localhost:8080/sdp", stream) - w := httptest.NewRecorder() - handler(w, req) - resp := w.Result() - body, _ := ioutil.ReadAll(resp.Body) - - assert.Equal(200, resp.StatusCode) - assert.Equal("done", string(body)) - - <-done -} - -func Test_HTTP(t *testing.T) { - assert := assert.New(t) - - sdpChan := HTTPSDPServer() - - msg := "Hello\n" - go func() { - stream := &bytes.Buffer{} - _, err := stream.WriteString(msg) - assert.Nil(err) - - client := &http.Client{} - - req, err := http.NewRequest("POST", "http://localhost:8080/sdp", stream) - assert.Nil(err) - resp, err := client.Do(req) - assert.Nil(err) - defer resp.Body.Close() - body, _ := ioutil.ReadAll(resp.Body) - assert.Equal(200, resp.StatusCode) - assert.Equal("done", string(body)) - }() - - sdp := <-sdpChan - assert.Equal(msg, sdp) -}