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

fix(fetcher): corrects filename used when specifying a version #155

Merged
merged 1 commit into from
Jan 12, 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
24 changes: 14 additions & 10 deletions tools/fetcher/pkg/artifact.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package pkg

import "fmt"
import (
"fmt"
"strings"
)

// typeMap maps artifact types to their corresponding file names.
var TypeMap = map[string]string{
"genesis": "block0.bin",
"vit": "database.sqlite3",
"genesis": "block0-VERSION.bin",
"vit": "database-VERSION.sqlite3",
}

// ArtifactFetcher is used to fetch artifacts from a store.
Expand All @@ -18,13 +21,7 @@ type ArtifactFetcher struct {
// Fetch fetches the given artifact from the store.
// If id is empty, it will use the base artifact filename with no version suffix.
func (f *ArtifactFetcher) Fetch(artifactType string, version string) ([]byte, error) {
var key string
if version == "" {
key = fmt.Sprintf("%s/%s/%s", f.Environment, f.Fund, TypeMap[artifactType])
} else {
key = fmt.Sprintf("%s/%s/%s-%s", f.Environment, f.Fund, TypeMap[artifactType], version)
}

key := fmt.Sprintf("%s/%s/%s", f.Environment, f.Fund, mkFileName(artifactType, f.Fund, version))
return f.Store.Fetch(key)
}

Expand All @@ -36,3 +33,10 @@ func NewArtifactFetcher(environment, fund string, store Store) ArtifactFetcher {
Store: store,
}
}

func mkFileName(artifactType, fund, version string) string {
if version == "" {
return strings.Replace(TypeMap[artifactType], "-VERSION", "", 1)
}
return strings.Replace(TypeMap[artifactType], "VERSION", fmt.Sprintf("%s-%s", fund, version), 1)
}
2 changes: 1 addition & 1 deletion tools/fetcher/pkg/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("Artifact", func() {
fetcher := pkg.NewArtifactFetcher("env", "fund", store)
_, err := fetcher.Fetch("genesis", "1.0.0")
Expect(err).ToNot(HaveOccurred())
Expect(usedKey).To(Equal("env/fund/block0.bin-1.0.0"))
Expect(usedKey).To(Equal("env/fund/block0-fund-1.0.0.bin"))
})

It("should return the artifact", func() {
Expand Down