diff --git a/core/conf/config_test.go b/core/conf/config_test.go index 356db8bf..8f114e4a 100644 --- a/core/conf/config_test.go +++ b/core/conf/config_test.go @@ -6,9 +6,21 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/tal-tech/go-zero/core/fs" "github.com/tal-tech/go-zero/core/hash" ) +func TestLoadConfig_notExists(t *testing.T) { + assert.NotNil(t, LoadConfig("not_a_file", nil)) +} + +func TestLoadConfig_notRecogFile(t *testing.T) { + filename, err := fs.TempFilenameWithText("hello") + assert.Nil(t, err) + defer os.Remove(filename) + assert.NotNil(t, LoadConfig(filename, nil)) +} + func TestConfigJson(t *testing.T) { tests := []string{ ".json", diff --git a/core/conf/properties_test.go b/core/conf/properties_test.go index 9cb4e545..a83a8447 100644 --- a/core/conf/properties_test.go +++ b/core/conf/properties_test.go @@ -24,6 +24,20 @@ func TestProperties(t *testing.T) { assert.Equal(t, "test", props.GetString("app.name")) assert.Equal(t, "app", props.GetString("app.program")) assert.Equal(t, 5, props.GetInt("app.threads")) + + val := props.ToString() + assert.Contains(t, val, "app.name") + assert.Contains(t, val, "app.program") + assert.Contains(t, val, "app.threads") +} + +func TestLoadProperties_badContent(t *testing.T) { + filename, err := fs.TempFilenameWithText("hello") + assert.Nil(t, err) + defer os.Remove(filename) + _, err = LoadProperties(filename) + assert.NotNil(t, err) + assert.True(t, len(err.Error()) > 0) } func TestSetString(t *testing.T) {