blob: 719bd82227287098b5690b780fb90785b2cef2de [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040016package model
17
18import (
19 "crypto/md5"
20 "fmt"
21 "testing"
22)
23
24var (
25 BRANCH *Branch
26 HASH string
27)
28
29func Test_ConfigBranch_New(t *testing.T) {
30 node := &Node{}
31 hash := fmt.Sprintf("%x", md5.Sum([]byte("origin_hash")))
32 origin := &Revision{
33 Config: &DataRevision{},
34 Children: make(map[string][]*Revision),
35 Hash: hash,
36 branch: &Branch{},
37 WeakRef: "need to fix this",
38 }
39 txid := fmt.Sprintf("%x", md5.Sum([]byte("branch_transaction_id")))
40
41 BRANCH = NewBranch(node, txid, origin, true)
42
43 t.Logf("New branch created: %+v\n", BRANCH)
44}
45
46func Test_ConfigBranch_AddRevision(t *testing.T) {
47 HASH = fmt.Sprintf("%x", md5.Sum([]byte("revision_hash")))
48 rev := &Revision{
49 Config: &DataRevision{},
50 Children: make(map[string][]*Revision),
51 Hash: HASH,
52 branch: &Branch{},
53 WeakRef: "need to fix this",
54 }
55
56 BRANCH.revisions[HASH] = rev
57 t.Logf("Added revision: %+v\n", rev)
58}
59
60func Test_ConfigBranch_GetRevision(t *testing.T) {
61 rev := BRANCH.get(HASH)
62 t.Logf("Got revision for hash:%s rev:%+v\n", HASH, rev)
63}
64func Test_ConfigBranch_LatestRevision(t *testing.T) {
65 rev := BRANCH.GetLatest()
66 t.Logf("Got GetLatest revision:%+v\n", rev)
67}
68func Test_ConfigBranch_OriginRevision(t *testing.T) {
69 rev := BRANCH.origin
70 t.Logf("Got origin revision:%+v\n", rev)
71}