Skip to content

Commit

Permalink
Merge pull request #13 from hanzei/http
Browse files Browse the repository at this point in the history
Add hello world http method
  • Loading branch information
lieut-data committed Oct 10, 2018
2 parents fa21513 + c1397f4 commit b9e17a1
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 45 deletions.
110 changes: 65 additions & 45 deletions server/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/Gopkg.toml
Expand Up @@ -6,3 +6,7 @@
[[constraint]]
name = "github.com/mattermost/mattermost-server"
version = "~5.3.0"

[[constraint]]
name = "github.com/stretchr/testify"
version = "~1.2.0"
6 changes: 6 additions & 0 deletions server/plugin.go
@@ -1,6 +1,8 @@
package main

import (
"fmt"
"net/http"
"sync"

"github.com/mattermost/mattermost-server/plugin"
Expand All @@ -17,4 +19,8 @@ type Plugin struct {
configuration *configuration
}

func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, world!")
}

// See https://developers.mattermost.com/extend/plugins/server/reference/
26 changes: 26 additions & 0 deletions server/plugin_test.go
@@ -0,0 +1,26 @@
package main

import (
"io/ioutil"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestServeHTTP(t *testing.T) {
assert := assert.New(t)
plugin := Plugin{}
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/", nil)

plugin.ServeHTTP(nil, w, r)

result := w.Result()
assert.NotNil(result)
bodyBytes, err := ioutil.ReadAll(result.Body)
assert.Nil(err)
bodyString := string(bodyBytes)

assert.Equal("Hello, world!", bodyString)
}

0 comments on commit b9e17a1

Please sign in to comment.