Skip to content

Commit

Permalink
fix tag test errors from unordered map
Browse files Browse the repository at this point in the history
  • Loading branch information
nnothing1 committed Dec 3, 2024
1 parent f74fe5e commit c33c019
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"log"
"net"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -147,7 +148,6 @@ func TestRegister(t *testing.T) {
"k2": "vv2",
"k3": "vv3",
}
tagList = []string{"k1:vv1", "k2:vv2", "k3:vv3"}
)

// listen on the port, and wait for the health check to connect
Expand Down Expand Up @@ -179,22 +179,26 @@ func TestRegister(t *testing.T) {
assert.Equal(t, testSvcName, gotSvc.Service)
assert.Equal(t, testSvcAddr.String(), fmt.Sprintf("%s:%d", gotSvc.Address, gotSvc.Port))
assert.Equal(t, testSvcWeight, gotSvc.Weights.Passing)
assert.Equal(t, tagList, gotSvc.Tags)
assert.Equal(t, len(tagMap), len(gotSvc.Tags))
for _, tag := range gotSvc.Tags {
kv := strings.Split(tag, ":")
k, v := kv[0], kv[1]
assert.Equal(t, tagMap[k], v)
}
}
}

// TestRegisterWithTTLCheck tests the Register function with ttl check.
func TestRegisterWithTTLCheck(t *testing.T) {
var (
testSvcName = strconv.Itoa(int(time.Now().Unix())) + ".svc.local"
testSvcPort = 8081
testSvcPort = 8084
testSvcWeight = 777
tagMap = map[string]string{
"k1": "vv1",
"k2": "vv2",
"k3": "vv3",
}
tagList = []string{"k1:vv1", "k2:vv2", "k3:vv3"}
)

// listen on the port, and wait for the health check to connect
Expand Down Expand Up @@ -226,7 +230,12 @@ func TestRegisterWithTTLCheck(t *testing.T) {
assert.Equal(t, testSvcName, gotSvc.Service)
assert.Equal(t, testSvcAddr.String(), fmt.Sprintf("%s:%d", gotSvc.Address, gotSvc.Port))
assert.Equal(t, testSvcWeight, gotSvc.Weights.Passing)
assert.Equal(t, tagList, gotSvc.Tags)
assert.Equal(t, len(tagMap), len(gotSvc.Tags))
for _, tag := range gotSvc.Tags {
kv := strings.Split(tag, ":")
k, v := kv[0], kv[1]
assert.Equal(t, tagMap[k], v)
}
}
}

Expand Down

0 comments on commit c33c019

Please sign in to comment.