From 481895d1e4796611e21926106532a7945f0d8bcf Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 30 Sep 2020 17:47:56 +0800 Subject: [PATCH] add more tests --- core/breaker/breakers.go | 1 + core/codec/dh_test.go | 3 +++ core/conf/config_test.go | 3 +-- core/conf/properties.go | 6 +++--- core/conf/properties_test.go | 5 +++++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/breaker/breakers.go b/core/breaker/breakers.go index e8f2479e..f13b3e76 100644 --- a/core/breaker/breakers.go +++ b/core/breaker/breakers.go @@ -47,6 +47,7 @@ func GetBreaker(name string) Breaker { breakers[name] = b } lock.Unlock() + return b } diff --git a/core/codec/dh_test.go b/core/codec/dh_test.go index 1bb77f8d..951ff486 100644 --- a/core/codec/dh_test.go +++ b/core/codec/dh_test.go @@ -73,6 +73,9 @@ func TestDiffieHellmanMiddleManAttack(t *testing.T) { } func TestKeyBytes(t *testing.T) { + var empty DhKey + assert.Equal(t, 0, len(empty.Bytes())) + key, err := GenerateKey() assert.Nil(t, err) assert.True(t, len(key.Bytes()) > 0) diff --git a/core/conf/config_test.go b/core/conf/config_test.go index 34d1e2a9..128f4b2d 100644 --- a/core/conf/config_test.go +++ b/core/conf/config_test.go @@ -32,8 +32,7 @@ func TestConfigJson(t *testing.T) { A string `json:"a"` B int `json:"b"` } - err = LoadConfig(tmpfile, &val) - assert.Nil(t, err) + MustLoad(tmpfile, &val) assert.Equal(t, "foo", val.A) assert.Equal(t, 1, val.B) }) diff --git a/core/conf/properties.go b/core/conf/properties.go index 1a1d3ff0..79fa1ebf 100644 --- a/core/conf/properties.go +++ b/core/conf/properties.go @@ -30,12 +30,12 @@ type mapBasedProperties struct { lock sync.RWMutex } -// Loads the properties into a properties configuration instance. May return the -// configuration itself along with an error that indicates if there was a problem loading the configuration. +// Loads the properties into a properties configuration instance. +// Returns an error that indicates if there was a problem loading the configuration. func LoadProperties(filename string) (Properties, error) { lines, err := iox.ReadTextLines(filename, iox.WithoutBlank(), iox.OmitWithPrefix("#")) if err != nil { - return nil, nil + return nil, err } raw := make(map[string]string) diff --git a/core/conf/properties_test.go b/core/conf/properties_test.go index b253598a..9cb4e545 100644 --- a/core/conf/properties_test.go +++ b/core/conf/properties_test.go @@ -41,3 +41,8 @@ func TestSetInt(t *testing.T) { props.SetInt(key, value) assert.Equal(t, value, props.GetInt(key)) } + +func TestLoadBadFile(t *testing.T) { + _, err := LoadProperties("nosuchfile") + assert.NotNil(t, err) +}