Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tags copy test for mirror #5141

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions cmd/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cmd

import (
"bufio"
"bytes"
"crypto/md5"
"crypto/tls"
Expand All @@ -29,6 +30,7 @@ import (
"net/http"
"os"
"os/exec"
"reflect"
"runtime"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -166,6 +168,7 @@ func testsThatDependOnOneAnother(t *testing.T) {
// Mirror
MirrorTempDirectoryStorageClassReducedRedundancy(t)
MirrorTempDirectory(t)
MirrorMinio2MinioWithTagsCopy(t)

// General object tests
FindObjects(t)
Expand Down Expand Up @@ -778,6 +781,56 @@ func MirrorTempDirectory(t *testing.T) {
}
}

type tagListResult struct {
Tagset map[string]string `json:"tagset"`
Status string `json:"status"`
URL string `json:"url"`
VersionID string `json:"versionID"`
}

func MirrorMinio2MinioWithTagsCopy(t *testing.T) {
TargetBucket := CreateBucket(t)
out, err := RunMC(
"mirror",
mainTestBucket,
TargetBucket,
)
fatalIfErrorWMsg(err, out, t)

out, err = RunMC("tag", "list", TargetBucket, "-r")
fatalIfErrorWMsg(err, out, t)
var targetTagsList []tagListResult
outStrs := bufio.NewScanner(strings.NewReader(out))
for outStrs.Scan() {
outStr := outStrs.Text()
if outStr == "" {
continue
}
tagList := new(tagListResult)
if err := json.Unmarshal([]byte(outStr), tagList); err != nil {
fatalIfErrorWMsg(err, out, t)
}
targetTagsList = append(targetTagsList, *tagList)
}

for _, f := range fileMap {
fileFound := false

for _, o := range targetTagsList {
if strings.Contains(o.URL, f.fileNameWithPrefix) {
fileFound = true
if !reflect.DeepEqual(f.tags, o.Tagset) {
fatalMsgOnly(fmt.Sprintf("expecting tags (%s) but got tags (%s)", f.tags, o.Tagset), t)
}
}
}

if !fileFound {
t.Fatalf("File was not mirrored: %s", f.fileNameWithPrefix)
}
}
}

func CatObjectFromStdin(t *testing.T) {
objectName := "pipe-test-object"
CatEchoBucket := CreateBucket(t)
Expand Down
Loading