From 7518e87a0d05a3f8c99786c5705952677387f109 Mon Sep 17 00:00:00 2001 From: Aadhitya A Date: Mon, 21 Mar 2022 09:01:51 +0530 Subject: [PATCH] Add sample tests Signed-off-by: Aadhitya A --- cmd/main_test.go | 16 ++++++++++++++++ handlers/middlewares_test.go | 16 ++++++++++++++++ helpers/kubernetes_test.go | 2 +- internal/channels/broker_test.go | 16 ++++++++++++++++ internal/sql/map_test.go | 17 +++++++++++++++++ meshes/client_test.go | 18 ++++++++++++++++++ router/server_test.go | 18 ++++++++++++++++++ 7 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 cmd/main_test.go create mode 100644 handlers/middlewares_test.go create mode 100644 internal/channels/broker_test.go create mode 100644 internal/sql/map_test.go create mode 100644 meshes/client_test.go create mode 100644 router/server_test.go diff --git a/cmd/main_test.go b/cmd/main_test.go new file mode 100644 index 00000000000..1e72eb42375 --- /dev/null +++ b/cmd/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "testing" +) + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test in short mode.") + } + + _, err := main() + if err != nil { + t.Errorf("main() failed with error: %s", err) + } +} diff --git a/handlers/middlewares_test.go b/handlers/middlewares_test.go new file mode 100644 index 00000000000..a0d777b6875 --- /dev/null +++ b/handlers/middlewares_test.go @@ -0,0 +1,16 @@ +package handlers + +import ( + "testing" +) + +func TestAuthMiddleWare(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test in short mode.") + } + + _, err := AuthMiddleWare(nil, nil) + if err != nil { + t.Errorf("AuthMiddleWare() failed with error: %s", err) + } +} diff --git a/helpers/kubernetes_test.go b/helpers/kubernetes_test.go index 52036df811a..b68f54c196e 100644 --- a/helpers/kubernetes_test.go +++ b/helpers/kubernetes_test.go @@ -20,4 +20,4 @@ func TestFetchKubernetesVersion(t *testing.T) { if err != nil { t.Error("FetchKubernetesVersion() failed") } -} \ No newline at end of file +} diff --git a/internal/channels/broker_test.go b/internal/channels/broker_test.go new file mode 100644 index 00000000000..2825d57066d --- /dev/null +++ b/internal/channels/broker_test.go @@ -0,0 +1,16 @@ +package channels + +import ( + "testing" +) + +func TestNewBrokerSubscribeChannel(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test in short mode.") + } + + ch := NewBrokerSubscribeChannel() + if ch == nil { + t.Error("NewBrokerSubscribeChannel() returned nil.") + } +} diff --git a/internal/sql/map_test.go b/internal/sql/map_test.go new file mode 100644 index 00000000000..8bab299f956 --- /dev/null +++ b/internal/sql/map_test.go @@ -0,0 +1,17 @@ +package sql + +import ( + "testing" +) + +var Sample map[string]interface{} + +func TestScan(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test in short mode.") + } + err := Map.Interface(Sample) + if err != nil { + t.Errorf("Scan() failed with error: %s", err) + } +} diff --git a/meshes/client_test.go b/meshes/client_test.go new file mode 100644 index 00000000000..e4707fcd40f --- /dev/null +++ b/meshes/client_test.go @@ -0,0 +1,18 @@ +package meshes + +import ( + "testing" +) + +m := MeshClient("nil", "nil") + +func TestClose(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test in short mode.") + } + + err := m.Close() + if err != nil { + t.Errorf("Close() failed with error: %s", err) + } +} diff --git a/router/server_test.go b/router/server_test.go new file mode 100644 index 00000000000..3613cb31a92 --- /dev/null +++ b/router/server_test.go @@ -0,0 +1,18 @@ +package router + +import ( + "testing" +) + +r := Router("nil", 0) + +func TestClose(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test in short mode.") + } + + err := r.Close() + if err != nil { + t.Errorf("Close() failed with error: %s", err) + } +}