Skip to content

Commit

Permalink
Merge ee35583 into dce914d
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Oct 8, 2019
2 parents dce914d + ee35583 commit f5aed45
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 336 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ before_install:
- Project=apollo

install:
- go get github.com/cihub/seelog
- go get github.com/coocood/freecache
- chmod u+x depend.sh
- ./depend.sh

script:
- chmod u+x coverage.sh
Expand Down
70 changes: 35 additions & 35 deletions app_config_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package agollo

import (
"github.com/zouyx/agollo/test"
. "github.com/tevid/gohamcrest"
"testing"
"time"
)

func TestInit(t *testing.T) {
config := GetAppConfig(nil)

test.NotNil(t, config)
test.Equal(t, "test", config.AppId)
test.Equal(t, "dev", config.Cluster)
test.Equal(t, "application", config.NamespaceName)
test.Equal(t, "localhost:8888", config.Ip)
Assert(t, config,NotNilVal())
Assert(t, "test", Equal(config.AppId))
Assert(t, "dev", Equal(config.Cluster))
Assert(t, "application", Equal(config.NamespaceName))
Assert(t, "localhost:8888", Equal(config.Ip))

apolloConfig := GetCurrentApolloConfig()
test.Equal(t, "test", apolloConfig.AppId)
test.Equal(t, "dev", apolloConfig.Cluster)
test.Equal(t, "application", apolloConfig.NamespaceName)
Assert(t, "test", Equal(apolloConfig.AppId))
Assert(t, "dev", Equal(apolloConfig.Cluster))
Assert(t, "application", Equal(apolloConfig.NamespaceName))

}

Expand All @@ -36,16 +36,16 @@ func TestStructInit(t *testing.T) {
})

config := GetAppConfig(nil)
test.NotNil(t, config)
test.Equal(t, "test1", config.AppId)
test.Equal(t, "dev1", config.Cluster)
test.Equal(t, "application1", config.NamespaceName)
test.Equal(t, "localhost:8889", config.Ip)
Assert(t, config, NotNilVal())
Assert(t, "test1", Equal(config.AppId))
Assert(t, "dev1", Equal(config.Cluster))
Assert(t, "application1", Equal(config.NamespaceName))
Assert(t, "localhost:8889", Equal(config.Ip))

apolloConfig := GetCurrentApolloConfig()
test.Equal(t, "test1", apolloConfig.AppId)
test.Equal(t, "dev1", apolloConfig.Cluster)
test.Equal(t, "application1", apolloConfig.NamespaceName)
Assert(t, "test1", Equal(apolloConfig.AppId))
Assert(t, "dev1", Equal(apolloConfig.Cluster))
Assert(t, "application1", Equal(apolloConfig.NamespaceName))

//revert file config
initFileConfig()
Expand All @@ -54,20 +54,20 @@ func TestStructInit(t *testing.T) {
func TestGetConfigUrl(t *testing.T) {
appConfig := getTestAppConfig()
url := getConfigUrl(appConfig)
test.StartWith(t, "http://localhost:8888/configs/test/dev/application?releaseKey=&ip=", url)
Assert(t, url, StartWith("http://localhost:8888/configs/test/dev/application?releaseKey=&ip="))
}

func TestGetConfigUrlByHost(t *testing.T) {
appConfig := getTestAppConfig()
url := getConfigUrlByHost(appConfig, "http://baidu.com/")
test.StartWith(t, "http://baidu.com/configs/test/dev/application?releaseKey=&ip=", url)
Assert(t, url, StartWith("http://baidu.com/configs/test/dev/application?releaseKey=&ip="))
}

func TestGetServicesConfigUrl(t *testing.T) {
appConfig := getTestAppConfig()
url := getServicesConfigUrl(appConfig)
ip := getInternal()
test.Equal(t, "http://localhost:8888/services/config?appId=test&ip="+ip, url)
Assert(t, "http://localhost:8888/services/config?appId=test&ip="+ip, Equal(url))
}

func getTestAppConfig() *AppConfig {
Expand Down Expand Up @@ -95,9 +95,9 @@ func trySyncServerIpList(t *testing.T) {
newAppConfig.Ip = server.URL
err := syncServerIpList(newAppConfig)

test.Nil(t, err)
Assert(t, err,NilVal())

test.Equal(t, 10, len(servers))
Assert(t, 10, Equal(len(servers)))

}

Expand All @@ -109,38 +109,38 @@ func TestSelectHost(t *testing.T) {
t.Log("appconfig select host:" + appConfig.selectHost())

host := "http://localhost:8888/"
test.Equal(t, host, appConfig.getHost())
test.Equal(t, host, appConfig.selectHost())
Assert(t, host, Equal(appConfig.getHost()))
Assert(t, host, Equal(appConfig.selectHost()))

//check select next time
appConfig.setNextTryConnTime(5)
test.NotEqual(t, host, appConfig.selectHost())
Assert(t, host, NotEqual(appConfig.selectHost()))
time.Sleep(6 * time.Second)
test.Equal(t, host, appConfig.selectHost())
Assert(t, host, Equal(appConfig.selectHost()))

//check servers
appConfig.setNextTryConnTime(5)
firstHost := appConfig.selectHost()
test.NotEqual(t, host, firstHost)
Assert(t, host, NotEqual(firstHost))
setDownNode(firstHost)

secondHost := appConfig.selectHost()
test.NotEqual(t, host, secondHost)
test.NotEqual(t, firstHost, secondHost)
Assert(t, host, NotEqual(secondHost))
Assert(t, firstHost, NotEqual(secondHost))
setDownNode(secondHost)

thirdHost := appConfig.selectHost()
test.NotEqual(t, host, thirdHost)
test.NotEqual(t, firstHost, thirdHost)
test.NotEqual(t, secondHost, thirdHost)
Assert(t, host, NotEqual(thirdHost))
Assert(t, firstHost, NotEqual(thirdHost))
Assert(t, secondHost, NotEqual(thirdHost))

for host := range servers {
setDownNode(host)
}

test.Equal(t, "", appConfig.selectHost())
Assert(t, "", Equal(appConfig.selectHost()))

//no servers
servers = make(map[string]*serverInfo, 0)
test.Equal(t, "", appConfig.selectHost())
}
Assert(t, "", Equal(appConfig.selectHost()))
}
32 changes: 16 additions & 16 deletions change_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package agollo
import (
"encoding/json"
"fmt"
"github.com/zouyx/agollo/test"
. "github.com/tevid/gohamcrest"
"testing"
"time"
)
Expand All @@ -17,19 +17,19 @@ func TestListenChangeEvent(t *testing.T) {
bytes, _ := json.Marshal(changeEvent)
fmt.Println("event:", string(bytes))

test.Equal(t, "application", changeEvent.Namespace)
Assert(t, "application", Equal(changeEvent.Namespace))

test.Equal(t, "string", changeEvent.Changes["string"].NewValue)
test.Equal(t, "", changeEvent.Changes["string"].OldValue)
test.Equal(t, ADDED, changeEvent.Changes["string"].ChangeType)
Assert(t, "string", Equal(changeEvent.Changes["string"].NewValue))
Assert(t, "", Equal(changeEvent.Changes["string"].OldValue))
Assert(t, ADDED, Equal(changeEvent.Changes["string"].ChangeType))

test.Equal(t, "value1", changeEvent.Changes["key1"].NewValue)
test.Equal(t, "", changeEvent.Changes["key2"].OldValue)
test.Equal(t, ADDED, changeEvent.Changes["key1"].ChangeType)
Assert(t, "value1", Equal(changeEvent.Changes["key1"].NewValue))
Assert(t, "", Equal(changeEvent.Changes["key2"].OldValue))
Assert(t, ADDED, Equal(changeEvent.Changes["key1"].ChangeType))

test.Equal(t, "value2", changeEvent.Changes["key2"].NewValue)
test.Equal(t, "", changeEvent.Changes["key2"].OldValue)
test.Equal(t, ADDED, changeEvent.Changes["key2"].ChangeType)
Assert(t, "value2", Equal(changeEvent.Changes["key2"].NewValue))
Assert(t, "", Equal(changeEvent.Changes["key2"].OldValue))
Assert(t, ADDED, Equal(changeEvent.Changes["key2"].ChangeType))

}

Expand All @@ -49,12 +49,12 @@ func buildNotifyResult(t *testing.T) {
err := autoSyncConfigServices(newAppConfig)
err = autoSyncConfigServices(newAppConfig)

test.Nil(t, err)
Assert(t, err,NilVal())

config := GetCurrentApolloConfig()

test.Equal(t, "100004458", config.AppId)
test.Equal(t, "default", config.Cluster)
test.Equal(t, "application", config.NamespaceName)
test.Equal(t, "20170430092936-dee2d58e74515ff3", config.ReleaseKey)
Assert(t, "100004458", Equal(config.AppId))
Assert(t, "default", Equal(config.Cluster))
Assert(t, "application", Equal(config.NamespaceName))
Assert(t, "20170430092936-dee2d58e74515ff3", Equal(config.ReleaseKey))
}
22 changes: 11 additions & 11 deletions component_common_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package agollo

import (
"github.com/zouyx/agollo/test"
. "github.com/tevid/gohamcrest"
"testing"
)

Expand All @@ -19,15 +19,15 @@ func TestCreateApolloConfigWithJson(t *testing.T) {

config, err := createApolloConfigWithJson([]byte(jsonStr))

test.Nil(t, err)
test.NotNil(t, config)
Assert(t, err,NilVal())
Assert(t, config,NotNilVal())

test.Equal(t, "100004458", config.AppId)
test.Equal(t, "default", config.Cluster)
test.Equal(t, "application", config.NamespaceName)
test.Equal(t, "20170430092936-dee2d58e74515ff3", config.ReleaseKey)
test.Equal(t, "value1", config.Configurations["key1"])
test.Equal(t, "value2", config.Configurations["key2"])
Assert(t, "100004458", Equal(config.AppId))
Assert(t, "default", Equal(config.Cluster))
Assert(t, "application", Equal(config.NamespaceName))
Assert(t, "20170430092936-dee2d58e74515ff3", Equal(config.ReleaseKey))
Assert(t, "value1", Equal(config.Configurations["key1"]))
Assert(t, "value2", Equal(config.Configurations["key2"]))

}

Expand All @@ -36,6 +36,6 @@ func TestCreateApolloConfigWithJsonError(t *testing.T) {

config, err := createApolloConfigWithJson([]byte(jsonStr))

test.NotNil(t, err)
test.Nil(t, config)
Assert(t, err,NotNilVal())
Assert(t, config,NilVal())
}

0 comments on commit f5aed45

Please sign in to comment.