Skip to content

Commit 01fc0c8

Browse files
authored
fix(fetcher): corrects filename used when specifying a version (#155)
1 parent 862b83a commit 01fc0c8

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

tools/fetcher/pkg/artifact.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package pkg
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"strings"
6+
)
47

58
// typeMap maps artifact types to their corresponding file names.
69
var TypeMap = map[string]string{
7-
"genesis": "block0.bin",
8-
"vit": "database.sqlite3",
10+
"genesis": "block0-VERSION.bin",
11+
"vit": "database-VERSION.sqlite3",
912
}
1013

1114
// ArtifactFetcher is used to fetch artifacts from a store.
@@ -18,13 +21,7 @@ type ArtifactFetcher struct {
1821
// Fetch fetches the given artifact from the store.
1922
// If id is empty, it will use the base artifact filename with no version suffix.
2023
func (f *ArtifactFetcher) Fetch(artifactType string, version string) ([]byte, error) {
21-
var key string
22-
if version == "" {
23-
key = fmt.Sprintf("%s/%s/%s", f.Environment, f.Fund, TypeMap[artifactType])
24-
} else {
25-
key = fmt.Sprintf("%s/%s/%s-%s", f.Environment, f.Fund, TypeMap[artifactType], version)
26-
}
27-
24+
key := fmt.Sprintf("%s/%s/%s", f.Environment, f.Fund, mkFileName(artifactType, f.Fund, version))
2825
return f.Store.Fetch(key)
2926
}
3027

@@ -36,3 +33,10 @@ func NewArtifactFetcher(environment, fund string, store Store) ArtifactFetcher {
3633
Store: store,
3734
}
3835
}
36+
37+
func mkFileName(artifactType, fund, version string) string {
38+
if version == "" {
39+
return strings.Replace(TypeMap[artifactType], "-VERSION", "", 1)
40+
}
41+
return strings.Replace(TypeMap[artifactType], "VERSION", fmt.Sprintf("%s-%s", fund, version), 1)
42+
}

tools/fetcher/pkg/artifact_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var _ = Describe("Artifact", func() {
2626
fetcher := pkg.NewArtifactFetcher("env", "fund", store)
2727
_, err := fetcher.Fetch("genesis", "1.0.0")
2828
Expect(err).ToNot(HaveOccurred())
29-
Expect(usedKey).To(Equal("env/fund/block0.bin-1.0.0"))
29+
Expect(usedKey).To(Equal("env/fund/block0-fund-1.0.0.bin"))
3030
})
3131

3232
It("should return the artifact", func() {

0 commit comments

Comments
 (0)