| 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 statusscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/ |
| 17 | |
| 18 | import ( |
| 19 | "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/" |
| 20 | |
| 21 | ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/ "github.com/opencontainers/image-spec/specs-go/v1scip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/" |
| 22 | ) |
| 23 | |
| 24 | func TestTracker_TryCommitscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/TestTracker_TryCommit().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 25 | tracker := NewTrackerscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/NewTracker().() |
| 26 | var desc ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/.Descriptorscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor# |
| 27 | |
| 28 | notify, committed := tracker.TryCommitscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#TryCommit().(desc) |
| 29 | if !committed { |
| 30 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("Tracker.TryCommit() got = %v, want %v", committed, true) |
| 31 | } |
| 32 | |
| 33 | done, committed := tracker.TryCommitscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#TryCommit().(desc) |
| 34 | if committed { |
| 35 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("Tracker.TryCommit() got = %v, want %v", committed, false) |
| 36 | } |
| 37 | |
| 38 | done2, committed := tracker.TryCommitscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#TryCommit().(desc) |
| 39 | if committed { |
| 40 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("Tracker.TryCommit() got = %v, want %v", committed, false) |
| 41 | } |
| 42 | |
| 43 | // status: working in progress |
| 44 | select { |
| 45 | case <-done: |
| 46 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected done") |
| 47 | default: |
| 48 | } |
| 49 | |
| 50 | select { |
| 51 | case <-done2: |
| 52 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#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.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected in progress") |
| 64 | } |
| 65 | |
| 66 | select { |
| 67 | case <-done2: |
| 68 | default: |
| 69 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected in progress") |
| 70 | } |
| 71 | } |