memregistry MEMREGISTRY

env oldRegistry=$CUE_REGISTRY

# smoke-test the dry-run output.
exec cue mod mirror --dry-run --to $MEMREGISTRY example.com
stdout '^mirroring baz.org@v0.5.0$'
stdout '^push .*/baz.org@sha256:6a99876cf4d65e06d0d7ce3e5e7a8217d919f0b603c47d39b0ecf7db5299d85a \[355 bytes\]$'
stdout '^tag .*/baz.org:v0.5.0@sha256:c145b84adf1458ec694b142ba85cd4a39aec82c1b31936694e0ca0abfc99a4fc$'

exec cue mod mirror --to $MEMREGISTRY example.com
cmp stdout want-mirror1-stdout

# The dry-run output should not mention any push or tag operations now
# because the content is already present.
exec cue mod mirror --dry-run --to $MEMREGISTRY example.com
stdout '^mirroring baz.org@v0.5.0$'
! stdout '^(push|tag)'

# Check that we can use the mirrored content.
cd example
env CUE_REGISTRY=$MEMREGISTRY
exec cue mod tidy
exec cue export
cmp stdout $WORK/want-export-stdout

# Try again with all versions.
exec cue mod mirror --to $MEMREGISTRY --from $oldRegistry --all-versions example.com
cmp stdout $WORK/want-mirror2-stdout

-- want-mirror1-stdout --
mirroring baz.org@v0.5.0
mirroring bar.com@v0.5.0
mirroring baz.org@v0.0.2
mirroring bar.com@v0.0.2
mirroring baz.org@v0.10.1
mirroring foo.com/bar/hello@v0.2.3
mirroring example.com@v0.0.1
-- want-mirror2-stdout --
mirroring foo.com/bar/hello@v0.2.10
mirroring example.com@v0.0.0
mirroring baz.org@v0.5.0
mirroring bar.com@v0.5.0
mirroring baz.org@v0.0.2
mirroring bar.com@v0.0.2
mirroring baz.org@v0.10.1
mirroring foo.com/bar/hello@v0.2.3
mirroring example.com@v0.0.1
-- want-export-stdout --
{
    "bar.com@v0": "v0.5.0",
    "baz.org@v0": "v0.10.1",
    "foo.com/bar/hello@v0": "v0.2.3",
    "main": "main",
    "example.com@v0": "v0.0.1"
}
-- example/cue.mod/module.cue --
module: "main.org"
language: version: "v0.8.0"

-- example/main.cue --
package main
import "example.com@v0:main"

main
-- _registry/example.com_v0.0.0/cue.mod/module.cue --
module: "example.com@v0"
language: version: "v0.8.0"
deps: {
	"foo.com/bar/hello@v0": v: "v0.2.10"
}

-- _registry/example.com_v0.0.0/top.cue --
package main

"example.com@v0": "v0.0.0"

-- _registry/example.com_v0.0.1/cue.mod/module.cue --
module: "example.com@v0"
language: version: "v0.8.0"
deps: {
	"foo.com/bar/hello@v0": v: "v0.2.3"
	"bar.com@v0": v: "v0.5.0"
}

-- _registry/example.com_v0.0.1/top.cue --
package main

import a "foo.com/bar/hello"
a
main: "main"
"example.com@v0": "v0.0.1"

-- _registry/unused.com_v0.2.4/cue.mod/module.cue --
module: "unused.com@v0"
language: version: "v0.8.0"

-- _registry/foo.com_bar_hello_v0.2.3/cue.mod/module.cue --
module: "foo.com/bar/hello@v0"
language: version: "v0.8.0"
deps: {
	"bar.com@v0": v: "v0.0.2"
	"baz.org@v0": v: "v0.10.1"
}

-- _registry/foo.com_bar_hello_v0.2.3/x.cue --
package hello
import (
	a "bar.com/bar@v0"
	b "baz.org@v0:baz"
)
"foo.com/bar/hello@v0": "v0.2.3"
a
b

-- _registry/foo.com_bar_hello_v0.2.10/cue.mod/module.cue --
module: "foo.com/bar/hello@v0"
language: version: "v0.8.0"

-- _registry/foo.com_bar_hello_v0.2.10/x.cue --
package hello

-- _registry/bar.com_v0.0.2/cue.mod/module.cue --
module: "bar.com@v0"
language: version: "v0.8.0"
deps: "baz.org@v0": v: "v0.0.2"

-- _registry/bar.com_v0.0.2/bar/x.cue --
package bar
import a "baz.org@v0:baz"
"bar.com@v0": "v0.0.2"
a


-- _registry/bar.com_v0.5.0/cue.mod/module.cue --
module: "bar.com@v0"
language: version: "v0.8.0"
deps: "baz.org@v0": v: "v0.5.0"

-- _registry/bar.com_v0.5.0/bar/x.cue --
package bar
import a "baz.org@v0:baz"
"bar.com@v0": "v0.5.0"
a


-- _registry/baz.org_v0.0.2/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.0.2/baz.cue --
package baz
"baz.org@v0": "v0.0.2"


-- _registry/baz.org_v0.1.2/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.1.2/baz.cue --
package baz
"baz.org@v0": "v0.1.2"


-- _registry/baz.org_v0.5.0/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.5.0/baz.cue --
package baz
"baz.org@v0": "v0.5.0"


-- _registry/baz.org_v0.10.1/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.10.1/baz.cue --
package baz
"baz.org@v0": "v0.10.1"
