diff --git a/tools/fetcher/pkg/artifact.go b/tools/fetcher/pkg/artifact.go index 633fdfe32..0832ea560 100644 --- a/tools/fetcher/pkg/artifact.go +++ b/tools/fetcher/pkg/artifact.go @@ -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. @@ -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) } @@ -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) +} diff --git a/tools/fetcher/pkg/artifact_test.go b/tools/fetcher/pkg/artifact_test.go index 758ff0112..feb28ce1f 100644 --- a/tools/fetcher/pkg/artifact_test.go +++ b/tools/fetcher/pkg/artifact_test.go @@ -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() {