-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Ignore existing package hashes for providers lock
command
#31389
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
terraform { | ||
required_providers { | ||
test = { | ||
source = "hashicorp/test" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,3 +216,94 @@ func TestLocksProviderSetRemove(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestProviderLockContainsAll(t *testing.T) { | ||
provider := addrs.NewDefaultProvider("provider") | ||
v2 := getproviders.MustParseVersion("2.0.0") | ||
v2EqConstraints := getproviders.MustParseVersionConstraints("2.0.0") | ||
|
||
t.Run("non-symmetric", func(t *testing.T) { | ||
target := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{ | ||
"9r3i9a9QmASqMnQM", | ||
"K43RHM2klOoywtyW", | ||
"swJPXfuCNhJsTM5c", | ||
}) | ||
|
||
original := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{ | ||
"9r3i9a9QmASqMnQM", | ||
"1ZAChGWUMWn4zmIk", | ||
"K43RHM2klOoywtyW", | ||
"HWjRvIuWZ1LVatnc", | ||
"swJPXfuCNhJsTM5c", | ||
"KwhJK4p/U2dqbKhI", | ||
}) | ||
|
||
if !original.ContainsAll(target) { | ||
t.Fatalf("orginal should contain all hashes in target") | ||
} | ||
if target.ContainsAll(original) { | ||
t.Fatalf("target should not contain all hashes in orginal") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: this seems like a good opportunity to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
}) | ||
|
||
t.Run("symmetric", func(t *testing.T) { | ||
target := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{ | ||
"9r3i9a9QmASqMnQM", | ||
"K43RHM2klOoywtyW", | ||
"swJPXfuCNhJsTM5c", | ||
}) | ||
|
||
original := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{ | ||
"9r3i9a9QmASqMnQM", | ||
"K43RHM2klOoywtyW", | ||
"swJPXfuCNhJsTM5c", | ||
}) | ||
|
||
if !original.ContainsAll(target) { | ||
t.Fatalf("orginal should contain all hashes in target") | ||
} | ||
if !target.ContainsAll(original) { | ||
t.Fatalf("target should not contain all hashes in orginal") | ||
} | ||
}) | ||
|
||
t.Run("edge case - null", func(t *testing.T) { | ||
original := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{ | ||
"9r3i9a9QmASqMnQM", | ||
"K43RHM2klOoywtyW", | ||
"swJPXfuCNhJsTM5c", | ||
}) | ||
|
||
if !original.ContainsAll(nil) { | ||
t.Fatalf("orginal should report true on nil") | ||
} | ||
}) | ||
|
||
t.Run("edge case - empty", func(t *testing.T) { | ||
original := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{ | ||
"9r3i9a9QmASqMnQM", | ||
"K43RHM2klOoywtyW", | ||
"swJPXfuCNhJsTM5c", | ||
}) | ||
|
||
target := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{}) | ||
|
||
if !original.ContainsAll(target) { | ||
t.Fatalf("orginal should report true on empty") | ||
} | ||
}) | ||
|
||
t.Run("edge case - original empty", func(t *testing.T) { | ||
original := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{}) | ||
|
||
target := NewProviderLock(provider, v2, v2EqConstraints, []getproviders.Hash{ | ||
"9r3i9a9QmASqMnQM", | ||
"K43RHM2klOoywtyW", | ||
"swJPXfuCNhJsTM5c", | ||
}) | ||
|
||
if original.ContainsAll(target) { | ||
t.Fatalf("orginal should report false when empty") | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding of this call and the function it's calling is that it will return
true
only ifplatformLock
doesn't add any new hashes compared tooldLock
, which feels opposite to the message it's printing. Am I misunderstanding the behavior ofContainsAll
? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot! I had my logic the wrong way, I've fixed it now. I followed the second idea, so split this out into a function and added some tests. Left a simple switch statement in the original function.