package repocli import ( "github.com/stretchr/testify/require" "bytes" "context" "encoding/json" "fmt" "math/rand" "testing" "time" ) func xxxTestClientGetManifest(t *testing.T) { rawrepo := "mirror.gcr.io/alpine" tags := []string{ "3.20.0", "sha256:29e5ba63e79337818e6c63cfcc68e2ab4e9ca483853b2de303bfbfba9372426c", } for _, tag := range tags { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) exist, mime, man, err := cli.GetManifest(ctx, rawrepo, tag) 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) { rawrepo := "mirror.gcr.io/alpine" tags := []string{ "3.20.0", "sha256:29e5ba63e79337818e6c63cfcc68e2ab4e9ca483853b2de303bfbfba9372426c", } for _, tag := range tags { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) exist, mime, size, csum, err := cli.ManifestExists(ctx, rawrepo, tag) 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) { rawrepos := []string{ "mirror.gcr.io/alpine", } for _, rawrepo := range rawrepos { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) digest := "sha256:3b8747b05489980f63da1d2b8e5a444c55777f69540394397b0bc1c76c3e41f2" exist, size, err := cli.BlobExists(ctx, rawrepo, digest) require.NoError(t, err) require.True(t, exist) fmt.Printf("Size: %d\n", size) } } func xxxTestClientGetBlob(t *testing.T) { rawrepos := []string{ "mirror.gcr.io/alpine", } for _, rawrepo := range rawrepos { cli := NewClient() ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) buffer := bytes.NewBuffer(nil) digest := "sha256:3b8747b05489980f63da1d2b8e5a444c55777f69540394397b0bc1c76c3e41f2" exist, err := cli.GetBlob(ctx, rawrepo, buffer, digest) require.NoError(t, err) require.True(t, exist) fmt.Printf("Size: %d\n", len(buffer.Bytes())) } } func xxxxTestClientGetUpload(t *testing.T) { rawrepos := []string{ "mstore:mstore@localhost:1025/alpine:3.20.0", } cli := NewClient() cli.UseMiddleware(NewBasicAuthMiddleware("mstore", "mstore")) for _, rawrepo := range rawrepos { var err error var loc string { ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) loc, err = cli.GetUpload(ctx, rawrepo) require.NoError(t, err) fmt.Printf("Upload 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) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) bloc, err := cli.PatchUpload(ctx, rawrepo, src, loc, int64(len(srcdata))) require.NoError(t, err) fmt.Printf("Path 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) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) bloc, err := cli.PutUpload(ctx, rawrepo, src, loc, digest, int64(len(srcdata))) require.NoError(t, err) fmt.Printf("Put blob Location: %s\n", bloc) } } } func xxxxTestClientGetToken(t *testing.T) { var token string var err error { cli := NewClient() cli.UseMiddleware(NewBasicAuthMiddleware("onborodin", "2Albert334")) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) token, err = cli.GetToken(ctx, "https://auth.docker.io/token") require.NoError(t, err) } fmt.Printf("Token: %s\n", token) { rawrepo := "docker.io/onborodin/toolbox:0.18" cli := NewClient() cli.UseMiddleware(NewBearerAuthMiddleware(token)) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) loc, err := cli.GetUpload(ctx, rawrepo) require.NoError(t, err) fmt.Printf("Upload Location: %s\n", loc) } }