| 1 |
/* |
| 2 |
Copyright The ORAS Authors. |
| 3 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
you may not use this file except in compliance with the License. |
| 5 |
You may obtain a copy of the License at |
| 6 |
|
| 7 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
| 9 |
Unless required by applicable law or agreed to in writing, software |
| 10 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
See the License for the specific language governing permissions and |
| 13 |
limitations under the License. |
| 14 |
*/ |
| 15 |
|
| 16 |
package copyutil |
| 17 |
|
| 18 |
import ( |
| 19 |
"reflect" |
| 20 |
"testing" |
| 21 |
|
| 22 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| 23 |
) |
| 24 |
|
| 25 |
func TestStack(t *testing.T) { |
| 26 |
var stack Stack |
| 27 |
isEmpty := stack.IsEmpty() |
| 28 |
if !isEmpty { |
| 29 |
t.Errorf("Stack.IsEmpty() = %v, want %v", isEmpty, true) |
| 30 |
} |
| 31 |
|
| 32 |
items := []NodeInfo{ |
| 33 |
{ocispec.Descriptor{}, 0}, |
| 34 |
{ocispec.Descriptor{}, 1}, |
| 35 |
{ocispec.Descriptor{}, 2}, |
| 36 |
} |
| 37 |
for _, item := range items { |
| 38 |
stack.Push(item) |
| 39 |
} |
| 40 |
|
| 41 |
i := len(items) - 1 |
| 42 |
for !stack.IsEmpty() { |
| 43 |
got, ok := stack.Pop() |
| 44 |
if !ok { |
| 45 |
t.Fatalf("Stack.Pop() = %v, want %v", ok, true) |
| 46 |
} |
| 47 |
if !reflect.DeepEqual(got, items[i]) { |
| 48 |
t.Errorf("Stack.Pop() = %v, want %v", got, items[i]) |
| 49 |
} |
| 50 |
i-- |
| 51 |
} |
| 52 |
|
| 53 |
_, ok := stack.Pop() |
| 54 |
if ok { |
| 55 |
t.Errorf("Stack.Pop() = %v, want %v", ok, false) |
| 56 |
} |
| 57 |
} |