You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2016/12/08 18:46:17 UTC

[15/20] incubator-trafficcontrol git commit: Add TM2 cache.TestAvailableStatusesCopy

Add TM2 cache.TestAvailableStatusesCopy


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/d08c9bad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/d08c9bad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/d08c9bad

Branch: refs/heads/master
Commit: d08c9bad652b6fc654271b9d8ea4ce1d984b5864
Parents: 34c0b4f
Author: Robert Butts <ro...@gmail.com>
Authored: Wed Dec 7 15:19:44 2016 -0700
Committer: Dave Neuman <ne...@apache.org>
Committed: Thu Dec 8 11:44:33 2016 -0700

----------------------------------------------------------------------
 .../traffic_monitor/cache/data_test.go          | 50 ++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d08c9bad/traffic_monitor/experimental/traffic_monitor/cache/data_test.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/cache/data_test.go b/traffic_monitor/experimental/traffic_monitor/cache/data_test.go
new file mode 100644
index 0000000..3788e7c
--- /dev/null
+++ b/traffic_monitor/experimental/traffic_monitor/cache/data_test.go
@@ -0,0 +1,50 @@
+package cache
+
+import (
+	"math/rand"
+	"reflect"
+	"testing"
+
+	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/enum"
+)
+
+func randBool() bool {
+	return rand.Int()%2 == 0
+}
+
+func randStr() string {
+	chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_"
+	num := 100
+	s := ""
+	for i := 0; i < num; i++ {
+		s += string(chars[rand.Intn(len(chars))])
+	}
+	return s
+}
+
+func randAvailableStatuses() AvailableStatuses {
+	a := AvailableStatuses{}
+	num := 100
+	for i := 0; i < num; i++ {
+		a[enum.CacheName(randStr())] = AvailableStatus{Available: randBool(), Status: randStr()}
+	}
+	return a
+}
+
+func TestAvailableStatusesCopy(t *testing.T) {
+	num := 100
+	for i := 0; i < num; i++ {
+		a := randAvailableStatuses()
+		b := a.Copy()
+
+		if !reflect.DeepEqual(a, b) {
+			t.Errorf("expected a and b DeepEqual, actual copied map not equal", a, b)
+		}
+
+		// verify a and b don't point to the same map
+		a[enum.CacheName(randStr())] = AvailableStatus{Available: randBool(), Status: randStr()}
+		if reflect.DeepEqual(a, b) {
+			t.Errorf("expected a != b, actual a and b point to the same map", a)
+		}
+	}
+}