Skip to content

Commit

Permalink
fix store tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Sep 20, 2023
1 parent 0d95583 commit 9f71109
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 147 deletions.
100 changes: 61 additions & 39 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,65 @@ func TestStore_GetByName(t *testing.T) {
},
{
name: "empty request",
storeRoot: "testdata/store/valid",
storeRoot: "testdata/store/valid-sha256-only",
toolName: "",
},
{
name: "hit by name only",
storeRoot: "testdata/store/valid",
storeRoot: "testdata/store/valid-sha256-only",
toolName: "golangci-lint",
want: []StoreEntry{
{
Name: "golangci-lint",
InstalledVersion: "v1.54.2",
Digests: "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
PathInRoot: "golangci-lint",
Digests: map[string]string{
"sha256": "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
},
PathInRoot: "golangci-lint",
},
},
},
{
name: "hit by name and exact version",
storeRoot: "testdata/store/valid",
storeRoot: "testdata/store/valid-sha256-only",
toolName: "golangci-lint",
versions: []string{"v1.54.2"},
want: []StoreEntry{
{
Name: "golangci-lint",
InstalledVersion: "v1.54.2",
Digests: "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
PathInRoot: "golangci-lint",
Digests: map[string]string{
"sha256": "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
},
PathInRoot: "golangci-lint",
},
},
},
{
name: "hit by name and multiple versions",
storeRoot: "testdata/store/valid",
storeRoot: "testdata/store/valid-sha256-only",
toolName: "golangci-lint",
versions: []string{"v1.54.1", "v1.54.2", "v1.54.3"},
want: []StoreEntry{
{
Name: "golangci-lint",
InstalledVersion: "v1.54.2",
Digests: "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
PathInRoot: "golangci-lint",
Digests: map[string]string{
"sha256": "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
},
PathInRoot: "golangci-lint",
},
},
},
{
name: "miss by bad version",
storeRoot: "testdata/store/valid",
storeRoot: "testdata/store/valid-sha256-only",
toolName: "golangci-lint",
versions: []string{"v1.54.3"},
},
{
name: "miss",
storeRoot: "testdata/store/valid",
storeRoot: "testdata/store/valid-sha256-only",
toolName: "best-tool", // bogus
},
}
Expand Down Expand Up @@ -112,64 +118,80 @@ func TestStore_Entries(t *testing.T) {
storeRoot: "testdata/store/missing",
},
{
name: "valid store",
storeRoot: "testdata/store/valid",
name: "valid store (sha256 only)",
storeRoot: "testdata/store/valid-sha256-only",
want: []StoreEntry{
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "quill",
InstalledVersion: "v0.4.1",
Digests: "56656877b8b0e0c06a96e83df12157565b91bb8f6b55c4051c0466edf0f08b85",
PathInRoot: "quill",
Digests: map[string]string{
"sha256": "56656877b8b0e0c06a96e83df12157565b91bb8f6b55c4051c0466edf0f08b85",
},
PathInRoot: "quill",
},
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "chronicle",
InstalledVersion: "v0.7.0",
Digests: "e011590e5d55188e03a2fd58524853ddacd23ec2e5d58535e061339777c4043f",
PathInRoot: "chronicle",
Digests: map[string]string{
"sha256": "e011590e5d55188e03a2fd58524853ddacd23ec2e5d58535e061339777c4043f",
},
PathInRoot: "chronicle",
},
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "gosimports",
InstalledVersion: "v0.3.8",
Digests: "9e5837236320efadb7a94675866cbd95e7a9716d635f3863603859698a37591a",
PathInRoot: "gosimports",
Digests: map[string]string{
"sha256": "9e5837236320efadb7a94675866cbd95e7a9716d635f3863603859698a37591a",
},
PathInRoot: "gosimports",
},
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "glow",
InstalledVersion: "v1.5.1",
Digests: "c6f05b9383f97fbb6fb2bb84b87b3b99ed7a1708d8a1634ff66d5bff8180f3b0",
PathInRoot: "glow",
Digests: map[string]string{
"sha256": "c6f05b9383f97fbb6fb2bb84b87b3b99ed7a1708d8a1634ff66d5bff8180f3b0",
},
PathInRoot: "glow",
},
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "goreleaser",
InstalledVersion: "v1.20.0",
Digests: "307dd15253ab292a57dff221671659f3133593df485cc08fdd8158d63222bb16",
PathInRoot: "goreleaser",
Digests: map[string]string{
"sha256": "307dd15253ab292a57dff221671659f3133593df485cc08fdd8158d63222bb16",
},
PathInRoot: "goreleaser",
},
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "golangci-lint",
InstalledVersion: "v1.54.2",
Digests: "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
PathInRoot: "golangci-lint",
Digests: map[string]string{
"sha256": "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d",
},
PathInRoot: "golangci-lint",
},
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "bouncer",
InstalledVersion: "v0.4.0",
Digests: "de42a2453c8e9b2587358c1f244a5cc0091c71385126f0fa3c0b3aec0feeaa4d",
PathInRoot: "bouncer",
Digests: map[string]string{
"sha256": "de42a2453c8e9b2587358c1f244a5cc0091c71385126f0fa3c0b3aec0feeaa4d",
},
PathInRoot: "bouncer",
},
{
root: "testdata/store/valid",
root: "testdata/store/valid-sha256-only",
Name: "task",
InstalledVersion: "v3.29.1",
Digests: "8d92c81f07960c5363a1f424e88dd4b64a1dd4251378d53873fa65ea1aab271b",
PathInRoot: "task",
Digests: map[string]string{
"sha256": "8d92c81f07960c5363a1f424e88dd4b64a1dd4251378d53873fa65ea1aab271b",
},
PathInRoot: "task",
},
},
},
Expand Down Expand Up @@ -264,7 +286,7 @@ func TestStore_AddTool(t *testing.T) {
}

func TestStore_Entries_IsACopy(t *testing.T) {
store, err := NewStore("testdata/store/valid")
store, err := NewStore("testdata/store/valid-sha256-only")
require.NoError(t, err)

gotEntries := store.Entries()
Expand Down
68 changes: 68 additions & 0 deletions testdata/store/valid-sha256-only/.binny.state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"entries": [
{
"name": "quill",
"version": "v0.4.1",
"digests": {
"sha256": "56656877b8b0e0c06a96e83df12157565b91bb8f6b55c4051c0466edf0f08b85"
},
"path": "quill"
},
{
"name": "chronicle",
"version": "v0.7.0",
"digests": {
"sha256": "e011590e5d55188e03a2fd58524853ddacd23ec2e5d58535e061339777c4043f"
},
"path": "chronicle"
},
{
"name": "gosimports",
"version": "v0.3.8",
"digests": {
"sha256": "9e5837236320efadb7a94675866cbd95e7a9716d635f3863603859698a37591a"
},
"path": "gosimports"
},
{
"name": "glow",
"version": "v1.5.1",
"digests": {
"sha256": "c6f05b9383f97fbb6fb2bb84b87b3b99ed7a1708d8a1634ff66d5bff8180f3b0"
},
"path": "glow"
},
{
"name": "goreleaser",
"version": "v1.20.0",
"digests": {
"sha256": "307dd15253ab292a57dff221671659f3133593df485cc08fdd8158d63222bb16"
},
"path": "goreleaser"
},
{
"name": "golangci-lint",
"version": "v1.54.2",
"digests": {
"sha256": "06c3715b43f4e92d0e9ec98ba8aa0f0c08c8963b2862ec130ec8e1c1ad9e1d1d"
},
"path": "golangci-lint"
},
{
"name": "bouncer",
"version": "v0.4.0",
"digests": {
"sha256": "de42a2453c8e9b2587358c1f244a5cc0091c71385126f0fa3c0b3aec0feeaa4d"
},
"path": "bouncer"
},
{
"name": "task",
"version": "v3.29.1",
"digests": {
"sha256": "8d92c81f07960c5363a1f424e88dd4b64a1dd4251378d53873fa65ea1aab271b"
},
"path": "task"
}
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 0 additions & 52 deletions testdata/store/valid/.binny.state.json

This file was deleted.

11 changes: 7 additions & 4 deletions tool/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/anchore/binny"
)

func Test_check(t *testing.T) {
func Test_check_sha256(t *testing.T) {
tests := []struct {
name string
storeRoot string
Expand All @@ -18,8 +18,8 @@ func Test_check(t *testing.T) {
wantErr require.ErrorAssertionFunc
}{
{
name: "valid",
storeRoot: "testdata/store/valid",
name: "valid (sha256)",
storeRoot: "testdata/store/valid-sha256-only",
resolvedVersion: "v1.54.2",
verifyDigest: true,
toolName: "golangci-lint",
Expand Down Expand Up @@ -57,7 +57,10 @@ func Test_check(t *testing.T) {
store, err := binny.NewStore(tt.storeRoot)
require.NoError(t, err)

tt.wantErr(t, Check(tt.toolName, tt.resolvedVersion, store, tt.verifyDigest))
tt.wantErr(t, Check(tt.toolName, tt.resolvedVersion, store, VerifyConfig{
VerifyXXH64Digest: false,
VerifySHA256Digest: tt.verifyDigest,
}))
})
}
}
Loading

0 comments on commit 9f71109

Please sign in to comment.