Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 2287888

Browse files
committed
Write vendor, regardless of lock, if force is true
Fix misunderstanding about when lock and newlock should be set in the SafeWriter tests.
1 parent 55422bc commit 2287888

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

txn_writer.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ type SafeWriter struct {
3030

3131
// SafeWriterPayload represents the actions SafeWriter will execute when SafeWriter.Write is called.
3232
type SafeWriterPayload struct {
33-
Manifest *Manifest
34-
Lock *Lock
35-
LockDiff *LockDiff
36-
ForceWriteVendor bool
33+
Manifest *Manifest
34+
Lock *Lock
35+
LockDiff *LockDiff
36+
WriteVendor bool
3737
}
3838

3939
func (payload *SafeWriterPayload) HasLock() bool {
@@ -45,10 +45,7 @@ func (payload *SafeWriterPayload) HasManifest() bool {
4545
}
4646

4747
func (payload *SafeWriterPayload) HasVendor() bool {
48-
// TODO(carolynvs) this can be calculated based on if we are writing the lock
49-
// init -> switch to newlock
50-
// ensure checks existence, why not move that into the prep?
51-
return payload.ForceWriteVendor
48+
return payload.WriteVendor
5249
}
5350

5451
// LockDiff is the set of differences between an existing lock file and an updated lock file.
@@ -162,20 +159,23 @@ func (diff StringDiff) MarshalJSON() ([]byte, error) {
162159
// written out based on newLock if present, else lock, else error.
163160
func (sw *SafeWriter) Prepare(manifest *Manifest, lock *Lock, newLock *Lock, forceVendor bool) {
164161
sw.Payload = &SafeWriterPayload{
165-
Manifest: manifest,
166-
ForceWriteVendor: forceVendor,
162+
Manifest: manifest,
163+
WriteVendor: forceVendor,
167164
}
168165

169166
if newLock != nil {
170167
if lock == nil {
171168
sw.Payload.Lock = newLock
172-
sw.Payload.ForceWriteVendor = true
169+
sw.Payload.WriteVendor = true
173170
} else {
174171
diff := diffLocks(lock, newLock)
175172
if diff != nil {
176173
sw.Payload.Lock = newLock
177174
sw.Payload.LockDiff = diff
178-
sw.Payload.ForceWriteVendor = true
175+
sw.Payload.WriteVendor = true
176+
} else if forceVendor {
177+
sw.Payload.Lock = newLock
178+
sw.Payload.WriteVendor = true
179179
}
180180
}
181181
} else if lock != nil {

txn_writer_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ func TestSafeWriter_ManifestAndUnmodifiedLock(t *testing.T) {
165165
pc.Load()
166166

167167
var sw SafeWriter
168-
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, nil, false)
168+
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, false)
169169

170170
// Verify prepared actions
171171
if !sw.Payload.HasManifest() {
172172
t.Fatal("Expected the payload to contain the manifest")
173173
}
174-
if !sw.Payload.HasLock() {
175-
t.Fatal("Expected the payload to contain the lock")
174+
if sw.Payload.HasLock() {
175+
t.Fatal("Did not expect the payload to contain the lock")
176176
}
177177
if sw.Payload.HasVendor() {
178178
t.Fatal("Did not expect the payload to contain the vendor directory")
@@ -208,7 +208,7 @@ func TestSafeWriter_ManifestAndUnmodifiedLockWithForceVendor(t *testing.T) {
208208
pc.Load()
209209

210210
var sw SafeWriter
211-
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, nil, true)
211+
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, true)
212212

213213
// Verify prepared actions
214214
if !sw.Payload.HasManifest() {
@@ -339,7 +339,7 @@ func TestSafeWriter_ForceVendorWhenVendorAlreadyExists(t *testing.T) {
339339

340340
var sw SafeWriter
341341
// Populate vendor
342-
sw.Prepare(nil, pc.Project.Lock, nil, true)
342+
sw.Prepare(nil, pc.Project.Lock, pc.Project.Lock, true)
343343
err := sw.Write(pc.Project.AbsRoot, pc.SourceManager)
344344
h.Must(errors.Wrap(err, "SafeWriter.Write failed"))
345345

0 commit comments

Comments
 (0)