| 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 status |
| 17 |
|
| 18 |
import ( |
| 19 |
"testing" |
| 20 |
|
| 21 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| 22 |
) |
| 23 |
|
| 24 |
func TestTracker_TryCommit(t *testing.T) { |
| 25 |
tracker := NewTracker() |
| 26 |
var desc ocispec.Descriptor |
| 27 |
|
| 28 |
notify, committed := tracker.TryCommit(desc) |
| 29 |
if !committed { |
| 30 |
t.Fatalf("Tracker.TryCommit() got = %v, want %v", committed, true) |
| 31 |
} |
| 32 |
|
| 33 |
done, committed := tracker.TryCommit(desc) |
| 34 |
if committed { |
| 35 |
t.Fatalf("Tracker.TryCommit() got = %v, want %v", committed, false) |
| 36 |
} |
| 37 |
|
| 38 |
done2, committed := tracker.TryCommit(desc) |
| 39 |
if committed { |
| 40 |
t.Fatalf("Tracker.TryCommit() got = %v, want %v", committed, false) |
| 41 |
} |
| 42 |
|
| 43 |
// status: working in progress |
| 44 |
select { |
| 45 |
case <-done: |
| 46 |
t.Fatalf("unexpected done") |
| 47 |
default: |
| 48 |
} |
| 49 |
|
| 50 |
select { |
| 51 |
case <-done2: |
| 52 |
t.Fatalf("unexpected done") |
| 53 |
default: |
| 54 |
} |
| 55 |
|
| 56 |
// mark status as done |
| 57 |
close(notify) |
| 58 |
|
| 59 |
// status: done |
| 60 |
select { |
| 61 |
case <-done: |
| 62 |
default: |
| 63 |
t.Fatalf("unexpected in progress") |
| 64 |
} |
| 65 |
|
| 66 |
select { |
| 67 |
case <-done2: |
| 68 |
default: |
| 69 |
t.Fatalf("unexpected in progress") |
| 70 |
} |
| 71 |
} |