Skip to content

Commit

Permalink
fix(fetcher): corrects filename used when specifying a version (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman authored Jan 12, 2024
1 parent 862b83a commit 01fc0c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
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

0 comments on commit 01fc0c8

Please sign in to comment.