diff --git a/config/apns.yaml b/config/config.yaml similarity index 100% rename from config/apns.yaml rename to config/config.yaml diff --git a/gorush/config_test.go b/gorush/config_test.go new file mode 100644 index 0000000..1811042 --- /dev/null +++ b/gorush/config_test.go @@ -0,0 +1,45 @@ +package gopush + +import ( + "github.com/stretchr/testify/assert" + "io/ioutil" + "log" + "os" + "testing" +) + +// Test file is missing +func TestMissingFile(t *testing.T) { + filename := "test" + _, err := LoadConfYaml(filename) + + assert.NotNil(t, err) +} + +// Test wrong json format +func TestWrongYAMLormat(t *testing.T) { + content := []byte(`Wrong format`) + + filename := "tempfile" + + if err := ioutil.WriteFile(filename, content, 0644); err != nil { + log.Fatalf("WriteFile %s: %v", filename, err) + } + + // clean up + defer os.Remove(filename) + + // parse JSON format error + _, err := LoadConfYaml(filename) + + assert.NotNil(t, err) +} + +// Test config file. +func TestReadConfig(t *testing.T) { + config, err := LoadConfYaml("../config/config.yaml") + + assert.Nil(t, err) + assert.Equal(t, "8088", config.Core.Port) + assert.False(t, config.Android.Enabled) +} diff --git a/gorush/server_test.go b/gorush/server_test.go index 596cd92..e402c32 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -5,8 +5,8 @@ import ( "github.com/buger/jsonparser" "github.com/stretchr/testify/assert" "net/http" - "testing" "runtime" + "testing" ) var go_version = runtime.Version()