Commit 2b5b0ea9 authored by Janos Guljas's avatar Janos Guljas

test exported functionality explicitly in api and debugapi packages

parent 1b8135c0
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package api package api_test
import ( import (
"io/ioutil" "io/ioutil"
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"net/url" "net/url"
"testing" "testing"
"github.com/ethersphere/bee/pkg/api"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/pingpong" "github.com/ethersphere/bee/pkg/pingpong"
"resenje.org/web" "resenje.org/web"
...@@ -21,7 +22,7 @@ type testServerOptions struct { ...@@ -21,7 +22,7 @@ type testServerOptions struct {
} }
func newTestServer(t *testing.T, o testServerOptions) (client *http.Client, cleanup func()) { func newTestServer(t *testing.T, o testServerOptions) (client *http.Client, cleanup func()) {
s := New(Options{ s := api.New(api.Options{
Pingpong: o.Pingpong, Pingpong: o.Pingpong,
Logger: logging.New(ioutil.Discard), Logger: logging.New(ioutil.Discard),
}) })
......
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package api
type PingpongResponse = pingpongResponse
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package api package api_test
import ( import (
"context" "context"
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/ethersphere/bee/pkg/api"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
...@@ -40,7 +41,7 @@ func TestPingpong(t *testing.T) { ...@@ -40,7 +41,7 @@ func TestPingpong(t *testing.T) {
defer cleanup() defer cleanup()
t.Run("ok", func(t *testing.T) { t.Run("ok", func(t *testing.T) {
jsonhttptest.ResponseDirect(t, client, http.MethodPost, "/pingpong/"+peerID, nil, http.StatusOK, pingpongResponse{ jsonhttptest.ResponseDirect(t, client, http.MethodPost, "/pingpong/"+peerID, nil, http.StatusOK, api.PingpongResponse{
RTT: rtt, RTT: rtt,
}) })
}) })
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package debugapi package debugapi_test
import ( import (
"io/ioutil" "io/ioutil"
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"net/url" "net/url"
"testing" "testing"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
"resenje.org/web" "resenje.org/web"
...@@ -21,7 +22,7 @@ type testServerOptions struct { ...@@ -21,7 +22,7 @@ type testServerOptions struct {
} }
func newTestServer(t *testing.T, o testServerOptions) (client *http.Client, cleanup func()) { func newTestServer(t *testing.T, o testServerOptions) (client *http.Client, cleanup func()) {
s := New(Options{ s := debugapi.New(debugapi.Options{
P2P: o.P2P, P2P: o.P2P,
Logger: logging.New(ioutil.Discard), Logger: logging.New(ioutil.Discard),
}) })
......
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package debugapi
type (
StatusResponse = statusResponse
PeerConnectResponse = peerConnectResponse
)
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package debugapi package debugapi_test
import ( import (
"context" "context"
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/p2p/mock" "github.com/ethersphere/bee/pkg/p2p/mock"
...@@ -33,7 +34,7 @@ func TestConnect(t *testing.T) { ...@@ -33,7 +34,7 @@ func TestConnect(t *testing.T) {
defer cleanup() defer cleanup()
t.Run("ok", func(t *testing.T) { t.Run("ok", func(t *testing.T) {
jsonhttptest.ResponseDirect(t, client, http.MethodPost, "/connect"+underlay, nil, http.StatusOK, peerConnectResponse{ jsonhttptest.ResponseDirect(t, client, http.MethodPost, "/connect"+underlay, nil, http.StatusOK, debugapi.PeerConnectResponse{
Address: overlay, Address: overlay,
}) })
}) })
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package debugapi package debugapi_test
import ( import (
"net/http" "net/http"
"testing" "testing"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
) )
...@@ -15,7 +16,7 @@ func TestHealth(t *testing.T) { ...@@ -15,7 +16,7 @@ func TestHealth(t *testing.T) {
client, cleanup := newTestServer(t, testServerOptions{}) client, cleanup := newTestServer(t, testServerOptions{})
defer cleanup() defer cleanup()
jsonhttptest.ResponseDirect(t, client, http.MethodGet, "/health", nil, http.StatusOK, statusResponse{ jsonhttptest.ResponseDirect(t, client, http.MethodGet, "/health", nil, http.StatusOK, debugapi.StatusResponse{
Status: "ok", Status: "ok",
}) })
} }
...@@ -24,7 +25,7 @@ func TestReadiness(t *testing.T) { ...@@ -24,7 +25,7 @@ func TestReadiness(t *testing.T) {
client, cleanup := newTestServer(t, testServerOptions{}) client, cleanup := newTestServer(t, testServerOptions{})
defer cleanup() defer cleanup()
jsonhttptest.ResponseDirect(t, client, http.MethodGet, "/readiness", nil, http.StatusOK, statusResponse{ jsonhttptest.ResponseDirect(t, client, http.MethodGet, "/readiness", nil, http.StatusOK, debugapi.StatusResponse{
Status: "ok", Status: "ok",
}) })
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment