VOL-1446 : Cleanup of db/model unit tests

- Fixed issues with model components while running tests
- Removed unecessary tests

Change-Id: Ica2007b66f681d03a77144cf2e778aa5a586786a
diff --git a/db/model/branch_test.go b/db/model/branch_test.go
index 26129fa..cf8406c 100644
--- a/db/model/branch_test.go
+++ b/db/model/branch_test.go
@@ -22,11 +22,12 @@
 )
 
 var (
-	BRANCH *Branch
-	HASH   string
+	TestBranch_BRANCH *Branch
+	TestBranch_HASH   string
 )
 
-func Test_ConfigBranch_New(t *testing.T) {
+// Create a new branch and ensure that fields are populated
+func TestBranch_NewBranch(t *testing.T) {
 	node := &node{}
 	hash := fmt.Sprintf("%x", md5.Sum([]byte("origin_hash")))
 	origin := &NonPersistedRevision{
@@ -34,38 +35,75 @@
 		Children: make(map[string][]Revision),
 		Hash:     hash,
 		Branch:   &Branch{},
-		WeakRef:  "need to fix this",
 	}
 	txid := fmt.Sprintf("%x", md5.Sum([]byte("branch_transaction_id")))
 
-	BRANCH = NewBranch(node, txid, origin, true)
+	TestBranch_BRANCH = NewBranch(node, txid, origin, true)
+	t.Logf("New Branch(txid:%s) created: %+v\n", txid, TestBranch_BRANCH)
 
-	t.Logf("New Branch created: %+v\n", BRANCH)
+	if TestBranch_BRANCH.Latest == nil {
+		t.Errorf("Branch latest pointer is nil")
+	} else if TestBranch_BRANCH.Origin == nil {
+		t.Errorf("Branch origin pointer is nil")
+	} else if TestBranch_BRANCH.Node == nil {
+		t.Errorf("Branch node pointer is nil")
+	} else if TestBranch_BRANCH.Revisions == nil {
+		t.Errorf("Branch revisions map is nil")
+	} else if TestBranch_BRANCH.Txid == "" {
+		t.Errorf("Branch transaction id is empty")
+	}
 }
 
-func Test_ConfigBranch_AddRevision(t *testing.T) {
-	HASH = fmt.Sprintf("%x", md5.Sum([]byte("revision_hash")))
+// Add a new revision to the branch
+func TestBranch_AddRevision(t *testing.T) {
+	TestBranch_HASH = fmt.Sprintf("%x", md5.Sum([]byte("revision_hash")))
 	rev := &NonPersistedRevision{
 		Config:   &DataRevision{},
 		Children: make(map[string][]Revision),
-		Hash:     HASH,
+		Hash:     TestBranch_HASH,
 		Branch:   &Branch{},
-		WeakRef:  "need to fix this",
 	}
 
-	BRANCH.Revisions[HASH] = rev
+	TestBranch_BRANCH.AddRevision(rev)
 	t.Logf("Added revision: %+v\n", rev)
+
+	if len(TestBranch_BRANCH.Revisions) == 0 {
+		t.Errorf("Branch revisions map is empty")
+	}
 }
 
-func Test_ConfigBranch_GetRevision(t *testing.T) {
-	rev := BRANCH.GetRevision(HASH)
-	t.Logf("Got revision for hash:%s rev:%+v\n", HASH, rev)
+// Ensure that the added revision can be retrieved
+func TestBranch_GetRevision(t *testing.T) {
+	if rev := TestBranch_BRANCH.GetRevision(TestBranch_HASH); rev == nil {
+		t.Errorf("Unable to retrieve revision for hash:%s", TestBranch_HASH)
+	} else {
+		t.Logf("Got revision for hash:%s rev:%+v\n", TestBranch_HASH, rev)
+	}
 }
-func Test_ConfigBranch_LatestRevision(t *testing.T) {
-	rev := BRANCH.GetLatest()
-	t.Logf("Got GetLatest revision:%+v\n", rev)
+
+// Set the added revision as the latest
+func TestBranch_LatestRevision(t *testing.T) {
+	addedRevision := TestBranch_BRANCH.GetRevision(TestBranch_HASH)
+	TestBranch_BRANCH.SetLatest(addedRevision)
+
+	rev := TestBranch_BRANCH.GetLatest()
+	t.Logf("Retrieved latest revision :%+v", rev)
+
+	if rev == nil {
+		t.Error("Unable to retrieve latest revision")
+	} else if rev.GetHash() != TestBranch_HASH {
+		t.Errorf("Latest revision does not match hash: %s", TestBranch_HASH)
+	}
 }
-func Test_ConfigBranch_OriginRevision(t *testing.T) {
-	rev := BRANCH.Origin
-	t.Logf("Got Origin revision:%+v\n", rev)
+
+// Ensure that the origin revision remains and differs from subsequent revisions
+func TestBranch_OriginRevision(t *testing.T) {
+	rev := TestBranch_BRANCH.Origin
+	t.Logf("Retrieved origin revision :%+v", rev)
+
+	if rev == nil {
+		t.Error("Unable to retrieve origin revision")
+	} else if rev.GetHash() == TestBranch_HASH {
+		t.Errorf("Origin revision should differ from added revision: %s", TestBranch_HASH)
+	}
 }