khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 1 | /* |
| 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 Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 16 | package model |
| 17 | |
| 18 | import ( |
| 19 | "crypto/md5" |
| 20 | "fmt" |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | var ( |
| 25 | BRANCH *Branch |
| 26 | HASH string |
| 27 | ) |
| 28 | |
| 29 | func Test_ConfigBranch_New(t *testing.T) { |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 30 | node := &node{} |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 31 | hash := fmt.Sprintf("%x", md5.Sum([]byte("origin_hash"))) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 32 | origin := &NonPersistedRevision{ |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 33 | Config: &DataRevision{}, |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 34 | Children: make(map[string][]Revision), |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 35 | Hash: hash, |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 36 | Branch: &Branch{}, |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 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 | |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 43 | t.Logf("New Branch created: %+v\n", BRANCH) |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | func Test_ConfigBranch_AddRevision(t *testing.T) { |
| 47 | HASH = fmt.Sprintf("%x", md5.Sum([]byte("revision_hash"))) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 48 | rev := &NonPersistedRevision{ |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 49 | Config: &DataRevision{}, |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 50 | Children: make(map[string][]Revision), |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 51 | Hash: HASH, |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 52 | Branch: &Branch{}, |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 53 | WeakRef: "need to fix this", |
| 54 | } |
| 55 | |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 56 | BRANCH.Revisions[HASH] = rev |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 57 | t.Logf("Added revision: %+v\n", rev) |
| 58 | } |
| 59 | |
| 60 | func Test_ConfigBranch_GetRevision(t *testing.T) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 61 | rev := BRANCH.GetRevision(HASH) |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 62 | t.Logf("Got revision for hash:%s rev:%+v\n", HASH, rev) |
| 63 | } |
| 64 | func Test_ConfigBranch_LatestRevision(t *testing.T) { |
| 65 | rev := BRANCH.GetLatest() |
| 66 | t.Logf("Got GetLatest revision:%+v\n", rev) |
| 67 | } |
| 68 | func Test_ConfigBranch_OriginRevision(t *testing.T) { |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 69 | rev := BRANCH.Origin |
| 70 | t.Logf("Got Origin revision:%+v\n", rev) |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 71 | } |