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

[NIT-2736] Lower URL case in latest database init #2589

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func setLatestSnapshotUrl(ctx context.Context, initConfig *conf.InitConfig, chai
return fmt.Errorf("failed to parse latest mirror \"%s\": %w", initConfig.LatestBase, err)
}
latestFileUrl := baseUrl.JoinPath(chain, "latest-"+initConfig.Latest+".txt").String()
latestFileUrl = strings.ToLower(latestFileUrl)
latestFileBytes, err := httpGet(ctx, latestFileUrl)
if err != nil {
return fmt.Errorf("failed to get latest file at \"%s\": %w", latestFileUrl, err)
Expand All @@ -312,6 +313,7 @@ func setLatestSnapshotUrl(ctx context.Context, initConfig *conf.InitConfig, chai
} else {
initConfig.Url = baseUrl.JoinPath(latestFile).String()
}
initConfig.Url = strings.ToLower(initConfig.Url)
log.Info("Set latest snapshot url", "url", initConfig.Url)
return nil
}
Expand Down
14 changes: 13 additions & 1 deletion cmd/nitro/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func TestSetLatestSnapshotUrl(t *testing.T) {

testCases := []struct {
name string
chain string
latestContents string
wantUrl func(string) string
}{
Expand All @@ -232,13 +233,20 @@ func TestSetLatestSnapshotUrl(t *testing.T) {
latestContents: "https://some.domain.com/arb1/2024/21/archive.tar.gz",
wantUrl: func(serverAddr string) string { return "https://some.domain.com/arb1/2024/21/archive.tar.gz" },
},
{
name: "chain and contents with upper case",
chain: "ARB1",
latestContents: "ARB1/2024/21/ARCHIVE.TAR.GZ",
wantUrl: func(serverAddr string) string { return serverAddr + "/arb1/2024/21/archive.tar.gz" },
},
}

for _, testCase := range testCases {
t.Log("running test case", testCase.name)

// Create latest file
serverDir := t.TempDir()

err := os.Mkdir(filepath.Join(serverDir, chain), dirPerm)
Require(t, err)
err = os.WriteFile(filepath.Join(serverDir, chain, latestFile), []byte(testCase.latestContents), filePerm)
Expand All @@ -253,7 +261,11 @@ func TestSetLatestSnapshotUrl(t *testing.T) {
initConfig := conf.InitConfigDefault
initConfig.Latest = snapshotKind
initConfig.LatestBase = addr
err = setLatestSnapshotUrl(ctx, &initConfig, chain)
configChain := testCase.chain
if configChain == "" {
configChain = chain
}
err = setLatestSnapshotUrl(ctx, &initConfig, configChain)
Require(t, err)

// Check url
Expand Down
Loading