package client import ( "github.com/stretchr/testify/require" "bytes" "context" "encoding/json" "fmt" "math/rand" "testing" "time" ) func TestClientGetManifest(t *testing.T) { rawrefs := []string{ "mirror.gcr.io/alpine:3.20.0", "mirror.gcr.io/alpine:sha256:29e5ba63e79337818e6c63cfcc68e2ab4e9ca483853b2de303bfbfba9372426c", } for _, rawref := range rawrefs { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) exist, mime, man, err := cli.GetManifest(ctx, rawref) require.NoError(t, err) require.True(t, exist) fmt.Printf("Type: %s\n", mime) buffer := bytes.NewBuffer(nil) err = json.Indent(buffer, man, " ", " ") require.NoError(t, err) //fmt.Printf("%s\n", buffer.String()) } } func xxxTestClientManifestExists(t *testing.T) { rawrefs := []string{ "mirror.gcr.io/alpine:3.20.0", "mirror.gcr.io/alpine:sha256:29e5ba63e79337818e6c63cfcc68e2ab4e9ca483853b2de303bfbfba9372426c", } for _, rawref := range rawrefs { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) exist, mime, size, csum, err := cli.ManifestExists(ctx, rawref) require.NoError(t, err) require.True(t, exist) fmt.Printf("MIME: %s\n", mime) fmt.Printf("Size: %d\n", size) fmt.Printf("Sum: %s\n", csum) fmt.Printf("Typ: %d\n", DigestType(csum)) } } func xxxTestClientBlobExists(t *testing.T) { rawrefs := []string{ "mirror.gcr.io/alpine:sha256:3b8747b05489980f63da1d2b8e5a444c55777f69540394397b0bc1c76c3e41f2", } for _, rawref := range rawrefs { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) exist, size, err := cli.BlobExists(ctx, rawref) require.NoError(t, err) require.True(t, exist) fmt.Printf("Size: %d\n", size) } } func xxxTestClientGetBlob(t *testing.T) { rawrefs := []string{ "mirror.gcr.io/alpine:sha256:3b8747b05489980f63da1d2b8e5a444c55777f69540394397b0bc1c76c3e41f2", } for _, rawref := range rawrefs { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) buffer := bytes.NewBuffer(nil) exist, err := cli.GetBlob(ctx, rawref, buffer) require.NoError(t, err) require.True(t, exist) fmt.Printf("Size: %d\n", len(buffer.Bytes())) } } func TestClientGetUpload(t *testing.T) { rawrefs := []string{ "mstore:mstore@localhost:1025/alpine:3.20.0", } for _, rawref := range rawrefs { var err error var loc string { cli := NewClient() cli.SetAuthenticator(NewBasicAuthenticator()) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) loc, err = cli.GetUpload(ctx, rawref) require.NoError(t, err) fmt.Printf("Location: %s\n", loc) } { srcsize := 1024 + 145 srcdata := make([]byte, srcsize) _, err = rand.Read(srcdata) require.NoError(t, err) src := bytes.NewReader(srcdata) digest := SHA256Digest(srcdata) cli := NewClient() cli.SetAuthenticator(NewBasicAuthenticator()) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) bloc, err := cli.PutUpload(ctx, rawref, src, loc, digest, int64(len(srcdata))) require.NoError(t, err) fmt.Printf("Location: %s\n", bloc) } { srcsize := 1024 + 145 srcdata := make([]byte, srcsize) _, err = rand.Read(srcdata) require.NoError(t, err) src := bytes.NewReader(srcdata) //digest := SHA256Digest(srcdata) cli := NewClient() cli.SetAuthenticator(NewBasicAuthenticator()) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) bloc, err := cli.PatchUpload(ctx, rawref, src, loc, int64(len(srcdata))) require.NoError(t, err) fmt.Printf("Location: %s\n", bloc) } } }