add config testing.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-01 11:01:54 +08:00
parent 6994f7f3de
commit 64db4504bb
3 changed files with 46 additions and 1 deletions

45
gorush/config_test.go Normal file
View File

@ -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)
}

View File

@ -5,8 +5,8 @@ import (
"github.com/buger/jsonparser" "github.com/buger/jsonparser"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"net/http" "net/http"
"testing"
"runtime" "runtime"
"testing"
) )
var go_version = runtime.Version() var go_version = runtime.Version()