You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2018/03/07 04:02:21 UTC

[incubator-trafficcontrol] 02/03: add api test and client entry for ping endpoint

This is an automated email from the ASF dual-hosted git repository.

dewrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 28c6e383dbebadad3e7a1fe0cec8f294d477eeab
Author: Dan Kirkwood <da...@apache.org>
AuthorDate: Tue Mar 6 13:46:55 2018 -0700

    add api test and client entry for ping endpoint
---
 traffic_ops/client/v13/ping.go           | 39 ++++++++++++++++++++++++++++++++
 traffic_ops/testing/api/v13/ping_test.go | 24 ++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/traffic_ops/client/v13/ping.go b/traffic_ops/client/v13/ping.go
new file mode 100644
index 0000000..b718d00
--- /dev/null
+++ b/traffic_ops/client/v13/ping.go
@@ -0,0 +1,39 @@
+/*
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+package v13
+
+import (
+	"encoding/json"
+	"net/http"
+)
+
+const (
+	API_v13_PING = "/api/1.3/ping"
+)
+
+// Ping returns a static json object to show that traffic_ops is responsive
+func (to *Session) Ping() (map[string]string, ReqInf, error) {
+	resp, remoteAddr, err := to.request(http.MethodGet, API_v13_PING, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return nil, reqInf, err
+	}
+	defer resp.Body.Close()
+
+	var data map[string]string
+	err = json.NewDecoder(resp.Body).Decode(&data)
+	return data, reqInf, nil
+}
diff --git a/traffic_ops/testing/api/v13/ping_test.go b/traffic_ops/testing/api/v13/ping_test.go
new file mode 100644
index 0000000..9091223
--- /dev/null
+++ b/traffic_ops/testing/api/v13/ping_test.go
@@ -0,0 +1,24 @@
+package v13
+
+/*
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+import (
+	"testing"
+)
+
+func TestPing(t *testing.T) {
+	TOSession.Ping()
+}

-- 
To stop receiving notification emails like this one, please contact
dewrich@apache.org.