Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add : delete mock json in test case of apollo #304

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config_center/apollo/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"strings"
"sync"
"testing"
"time"
)

import (
Expand Down Expand Up @@ -171,6 +173,7 @@ func Test_GetConfig(t *testing.T) {
mapContent, err := configuration.Parser().Parse(configs)
assert.NoError(t, err)
assert.Equal(t, "ikurento.com", mapContent["application.organization"])
deleteMockJson(t)
}

func Test_GetConfigItem(t *testing.T) {
Expand All @@ -180,6 +183,7 @@ func Test_GetConfigItem(t *testing.T) {
configuration.SetParser(&parser.DefaultConfigurationParser{})
assert.NoError(t, err)
assert.Equal(t, "ikurento.com", configs)
deleteMockJson(t)
}

func initMockApollo(t *testing.T) *apolloConfiguration {
Expand Down Expand Up @@ -216,6 +220,7 @@ func TestAddListener(t *testing.T) {
listener.wg.Wait()
assert.Equal(t, "registries.hangzhouzk.username", listener.event)
assert.Greater(t, listener.count, 0)
deleteMockJson(t)
}

func TestRemoveListener(t *testing.T) {
Expand Down Expand Up @@ -244,6 +249,7 @@ func TestRemoveListener(t *testing.T) {
})
assert.Equal(t, listenerCount, 0)
assert.Equal(t, listener.count, 0)
deleteMockJson(t)
}

type apolloDataListener struct {
Expand All @@ -260,3 +266,10 @@ func (l *apolloDataListener) Process(configType *config_center.ConfigChangeEvent
l.count++
l.event = configType.Key
}

func deleteMockJson(t *testing.T) {
//because the file write in another goroutine,so have a break ...
time.Sleep(100 * time.Millisecond)
remove := os.Remove("mockDubbog.properties.json")
t.Log("remove result:", remove)
}