mirror of
https://gitlab.com/nullmax17/personal-website.git
synced 2025-03-14 21:21:11 +03:00
Comments update
This commit is contained in:
parent
0c6e10d946
commit
2683304e8c
@ -1,3 +1,7 @@
|
|||||||
|
// Controller for minecraft mod CC:Tweaked
|
||||||
|
// I decided to make it so I and my friend can create some bizzare stuff in minectaft :D
|
||||||
|
// It turned out pretty well and was the first controller which I tested.
|
||||||
|
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -10,6 +14,7 @@ import (
|
|||||||
"github.com/kaptinlin/jsonrepair"
|
"github.com/kaptinlin/jsonrepair"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Json unmarshalled object from website.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Msg_type int `json:"msg_type"`
|
Msg_type int `json:"msg_type"`
|
||||||
@ -43,6 +48,7 @@ func decodeMessage(r *http.Request) (Message, error) {
|
|||||||
return messageRC, nil
|
return messageRC, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Garbage collection for messages.
|
||||||
func clearQueue() {
|
func clearQueue() {
|
||||||
if len(message_queue) <= 1 {
|
if len(message_queue) <= 1 {
|
||||||
return
|
return
|
||||||
|
@ -15,19 +15,26 @@ func TestPostMessage(t *testing.T) {
|
|||||||
|
|
||||||
test_value := `{"content":"banan","msg_type":10}`
|
test_value := `{"content":"banan","msg_type":10}`
|
||||||
|
|
||||||
|
// Creating a body for testing.
|
||||||
body := strings.NewReader(test_value)
|
body := strings.NewReader(test_value)
|
||||||
|
// Creating request for controler.
|
||||||
req, err := http.NewRequest("POST", "/cctweaked", body)
|
req, err := http.NewRequest("POST", "/cctweaked", body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
// Creating recored to read output from controller.
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
|
// Pushing test data to controller
|
||||||
http.HandlerFunc(controllers.PostSendMessage).ServeHTTP(rr, req)
|
http.HandlerFunc(controllers.PostSendMessage).ServeHTTP(rr, req)
|
||||||
|
|
||||||
|
// Creating a pull request for controller
|
||||||
req, err = http.NewRequest("GET", "/cctweaked", nil)
|
req, err = http.NewRequest("GET", "/cctweaked", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pulling processed data from controller
|
||||||
http.HandlerFunc(controllers.GetMessage).ServeHTTP(rr, req)
|
http.HandlerFunc(controllers.GetMessage).ServeHTTP(rr, req)
|
||||||
|
|
||||||
expected := `{banan 10}`
|
expected := `{banan 10}`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user