package core import ( "bytes" "encoding/json" "fmt" "io" "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" ) func TestDSRegister(t *testing.T) { // if tt, err := New(); err != nil { // panic(err) // } else { // err := tt.Start(nil) // if err != nil { // panic(err) // } // time.Sleep(5) // tt.Shutdown(shared.ShutdownFlagTerminating) // } assert := assert.New(t) tt, _ := New() mux := http.NewServeMux() tt.registerHandlers(mux, "") // hello call { helloCall := struct { Method string }{Method: "Hello"} res := httptest.NewRecorder() content, _ := json.Marshal(helloCall) req := httptest.NewRequest("POST", "/", bytes.NewBuffer(content)) mux.ServeHTTP(res, req) assert.Equal(http.StatusOK, res.Code) } // url := "127.0.0.2" // checkin call { // helloCall := struct { // Method string // Args []interface{} // }{Method: "CheckIn", Args: []interface{}{url /*"fuck", struct{ test string }{test: "numb"}*/}} checkInCall := struct { Method string }{Method: "CheckIn"} res := httptest.NewRecorder() content, _ := json.Marshal(checkInCall) req := httptest.NewRequest("POST", "/", bytes.NewBuffer(content)) mux.ServeHTTP(res, req) assert.Equal(http.StatusOK, res.Code) } // is checked in { helloCall := struct { Method string Args []interface{} }{Method: "GetCheckedIn"} res := httptest.NewRecorder() content, _ := json.Marshal(helloCall) req := httptest.NewRequest("POST", "/", bytes.NewBuffer(content)) mux.ServeHTTP(res, req) assert.Equal(http.StatusOK, res.Code) data, _ := io.ReadAll(res.Body) assert.Equal(req.RemoteAddr, string(data)) fmt.Println("return : ", string(data)) } }