Skip to content

Commit

Permalink
test: add test for status
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <[email protected]>
  • Loading branch information
shizhMSFT committed Dec 31, 2024
1 parent 9f19734 commit f8503f9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/oras/internal/display/status/progress/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package progress

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -99,6 +100,33 @@ func Test_status_String_zeroWidth(t *testing.T) {
t.Error(err)
}
}

func Test_status_String_failure(t *testing.T) {
// zero status and progress
s := newStatus(ocispec.Descriptor{
MediaType: "application/vnd.oci.empty.oras.test.v1+json",
Size: 2,
Digest: "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
})
if status, digest := s.String(console.MinWidth); status != zeroStatus || digest != zeroDigest {
t.Errorf("status.String() = %v, %v, want %v, %v", status, digest, zeroStatus, zeroDigest)
}

// done with failure
s.update(&status{
err: context.Canceled,
prompt: "test",
descriptor: s.descriptor,
offset: 1,
startTime: time.Now().Add(-time.Minute),
endTime: time.Now(),
})
statusStr, digestStr := s.String(120)
if err := testutils.OrderedMatch(statusStr+digestStr, "✗", s.prompt, s.descriptor.MediaType, "1.00/2 B", "50.00%", s.descriptor.Digest.String()); err != nil {
t.Error(err)
}
}

func Test_status_durationString(t *testing.T) {
// zero duration
s := newStatus(ocispec.Descriptor{})
Expand Down

0 comments on commit f8503f9

Please sign in to comment.