From 27a0b2460d8374e0b988c63e439ec1cea0400bf9 Mon Sep 17 00:00:00 2001 From: Ajay Kelkar Date: Mon, 1 Oct 2018 21:26:26 +0530 Subject: [PATCH 1/2] Absolute basic UT --- probe/cri/registry_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 probe/cri/registry_test.go diff --git a/probe/cri/registry_test.go b/probe/cri/registry_test.go new file mode 100644 index 000000000..7b1ba7cbb --- /dev/null +++ b/probe/cri/registry_test.go @@ -0,0 +1,27 @@ +package cri_test + +import ( + "testing" + + "github.com/weaveworks/scope/probe/cri" +) + +func TestParseHttpEndpointUrl(t *testing.T) { + _, err := cri.NewCRIClient("http://xyz.com") + + if err == nil { + t.Fatal("Should not create client with Http protocol") + } +} + +func TestParseTcpEndpointUrl(t *testing.T) { + client, err := cri.NewCRIClient("127.0.0.1") + + if err != nil { + t.Fatal("Should have created service client") + } + + if client == nil { + t.Fatal("Should have created service client") + } +} From 68bce4f57c3e34d091de02c8ed4937900c0a37e6 Mon Sep 17 00:00:00 2001 From: Ajay Kelkar Date: Wed, 3 Oct 2018 14:19:54 +0530 Subject: [PATCH 2/2] Using assert for equality checks --- probe/cri/registry_test.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/probe/cri/registry_test.go b/probe/cri/registry_test.go index 7b1ba7cbb..916f06e4f 100644 --- a/probe/cri/registry_test.go +++ b/probe/cri/registry_test.go @@ -3,25 +3,19 @@ package cri_test import ( "testing" + "github.com/bmizerany/assert" "github.com/weaveworks/scope/probe/cri" ) func TestParseHttpEndpointUrl(t *testing.T) { _, err := cri.NewCRIClient("http://xyz.com") - if err == nil { - t.Fatal("Should not create client with Http protocol") - } + assert.Equal(t, "protocol \"http\" not supported", err.Error()) } func TestParseTcpEndpointUrl(t *testing.T) { client, err := cri.NewCRIClient("127.0.0.1") - if err != nil { - t.Fatal("Should have created service client") - } - - if client == nil { - t.Fatal("Should have created service client") - } + assert.Equal(t, nil, err) + assert.NotEqual(t, nil, client) }