blob: 1f2eec215f51ac0a469061b581cb91b23548b574 [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) {
Stephane Barbarie06c4a742018-10-01 11:09:32 -040030 node := &node{}
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040031 hash := fmt.Sprintf("%x", md5.Sum([]byte("origin_hash")))
Stephane Barbarieec0919b2018-09-05 14:14:29 -040032 origin := &NonPersistedRevision{
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040033 Config: &DataRevision{},
Stephane Barbarieec0919b2018-09-05 14:14:29 -040034 Children: make(map[string][]Revision),
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040035 Hash: hash,
Stephane Barbarieec0919b2018-09-05 14:14:29 -040036 Branch: &Branch{},
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040037 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
Stephane Barbarieec0919b2018-09-05 14:14:29 -040043 t.Logf("New Branch created: %+v\n", BRANCH)
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040044}
45
46func Test_ConfigBranch_AddRevision(t *testing.T) {
47 HASH = fmt.Sprintf("%x", md5.Sum([]byte("revision_hash")))
Stephane Barbarieec0919b2018-09-05 14:14:29 -040048 rev := &NonPersistedRevision{
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040049 Config: &DataRevision{},
Stephane Barbarieec0919b2018-09-05 14:14:29 -040050 Children: make(map[string][]Revision),
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040051 Hash: HASH,
Stephane Barbarieec0919b2018-09-05 14:14:29 -040052 Branch: &Branch{},
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040053 WeakRef: "need to fix this",
54 }
55
Stephane Barbarieec0919b2018-09-05 14:14:29 -040056 BRANCH.Revisions[HASH] = rev
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040057 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) {
Stephane Barbarieec0919b2018-09-05 14:14:29 -040069 rev := BRANCH.Origin
70 t.Logf("Got Origin revision:%+v\n", rev)
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040071}