Skip to content

Commit

Permalink
Reorganize config test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Dec 24, 2012
1 parent 218a696 commit d9ec69c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
47 changes: 31 additions & 16 deletions shadowsocks/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,64 @@ import (
"testing"
)

func TestParseConfig1Password(t *testing.T) {
config, err := ParseConfig("testdata/config-one-passwd.json")
func TestConfigJson(t *testing.T) {
config, err := ParseConfig("testdata/config.json")
if err != nil {
t.Error("error parsing single password config:", err)
t.Error("error parsing config.json:", err)
}

if config.Password != "barfoo!" {
t.Error("wrong password from config")
}
if config.Timeout != 60 {
t.Error("tiemout wrong")
}
if !config.CacheEncTable {
t.Error("cache_enctable should be true")
if config.Timeout != 0 {
t.Error("tiemout should default to 0")
}
srvArr := config.GetServerArray()
if len(srvArr) != 1 || srvArr[0] != "127.0.0.1" {
t.Error("server option is not set correctly")
}
if config.CacheEncTable {
t.Error("cache_enctable should be false by default")
}
}

func TestParseConfigMultiPassword(t *testing.T) {
config, err := ParseConfig("testdata/config-multi-passwd.json")
func TestServerMultiPort(t *testing.T) {
config, err := ParseConfig("testdata/server-multi-port.json")
if err != nil {
t.Error("error parsing multi password config:", err)
t.Error("error parsing multi server-multi-port.json:", err)
}

if config.Password != "barfoo!" {
t.Error("wrong password from config")
}
if config.PortPassword["8387"] != "foobar" {
t.Error("wrong multiple password for port 8387")
}
if config.PortPassword["8388"] != "barfoo" {
t.Error("wrong multiple password for port 8388")
}
if config.PortPassword["8389"] != "" {
t.Error("should have no password for port 8389")
}

if !config.CacheEncTable {
t.Error("cache_enctable should be true")
}
}

func TestDeprecatedClientMultiServerArray(t *testing.T) {
// This form of config is deprecated. Provided only for backward compatibility.
config, err := ParseConfig("testdata/deprecated-client-multi-server.json")
if err != nil {
t.Error("error parsing deprecated-client-multi-server.json:", err)
}

srvArr := config.GetServerArray()
if len(srvArr) != 2 {
t.Error("server option is not set correctly")
}
if srvArr[0] != "127.0.0.1" {
t.Error("1st server wrong")
t.Error("1st server wrong, got %v", srvArr[0])
}
if srvArr[1] != "127.0.1.1" {
t.Error("2nd server wrong")
t.Error("2nd server wrong, got %v", srvArr[0])
}
}

Expand Down
11 changes: 0 additions & 11 deletions shadowsocks/testdata/config-multi-passwd.json

This file was deleted.

8 changes: 0 additions & 8 deletions shadowsocks/testdata/config-one-passwd.json

This file was deleted.

6 changes: 6 additions & 0 deletions shadowsocks/testdata/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"server":"127.0.0.1",
"server_port":8388,
"local_port":1081,
"password":"barfoo!"
}
7 changes: 7 additions & 0 deletions shadowsocks/testdata/deprecated-client-multi-server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"server":["127.0.0.1", "127.0.1.1"],
"server_port":8388,
"local_port":1081,
"password":"barfoo!",
"timeout":60
}
8 changes: 8 additions & 0 deletions shadowsocks/testdata/server-multi-port.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"port_password": {
"8387": "foobar",
"8388": "barfoo"
},
"timeout": 60,
"cache_enctable": true
}

0 comments on commit d9ec69c

Please sign in to comment.