зеркало из https://github.com/golang/dep.git
Write vendor, regardless of lock, if force is true
Fix misunderstanding about when lock and newlock should be set in the SafeWriter tests.
This commit is contained in:
Родитель
55422bc13b
Коммит
2287888873
|
@ -30,10 +30,10 @@ type SafeWriter struct {
|
|||
|
||||
// SafeWriterPayload represents the actions SafeWriter will execute when SafeWriter.Write is called.
|
||||
type SafeWriterPayload struct {
|
||||
Manifest *Manifest
|
||||
Lock *Lock
|
||||
LockDiff *LockDiff
|
||||
ForceWriteVendor bool
|
||||
Manifest *Manifest
|
||||
Lock *Lock
|
||||
LockDiff *LockDiff
|
||||
WriteVendor bool
|
||||
}
|
||||
|
||||
func (payload *SafeWriterPayload) HasLock() bool {
|
||||
|
@ -45,10 +45,7 @@ func (payload *SafeWriterPayload) HasManifest() bool {
|
|||
}
|
||||
|
||||
func (payload *SafeWriterPayload) HasVendor() bool {
|
||||
// TODO(carolynvs) this can be calculated based on if we are writing the lock
|
||||
// init -> switch to newlock
|
||||
// ensure checks existence, why not move that into the prep?
|
||||
return payload.ForceWriteVendor
|
||||
return payload.WriteVendor
|
||||
}
|
||||
|
||||
// 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) {
|
|||
// written out based on newLock if present, else lock, else error.
|
||||
func (sw *SafeWriter) Prepare(manifest *Manifest, lock *Lock, newLock *Lock, forceVendor bool) {
|
||||
sw.Payload = &SafeWriterPayload{
|
||||
Manifest: manifest,
|
||||
ForceWriteVendor: forceVendor,
|
||||
Manifest: manifest,
|
||||
WriteVendor: forceVendor,
|
||||
}
|
||||
|
||||
if newLock != nil {
|
||||
if lock == nil {
|
||||
sw.Payload.Lock = newLock
|
||||
sw.Payload.ForceWriteVendor = true
|
||||
sw.Payload.WriteVendor = true
|
||||
} else {
|
||||
diff := diffLocks(lock, newLock)
|
||||
if diff != nil {
|
||||
sw.Payload.Lock = newLock
|
||||
sw.Payload.LockDiff = diff
|
||||
sw.Payload.ForceWriteVendor = true
|
||||
sw.Payload.WriteVendor = true
|
||||
} else if forceVendor {
|
||||
sw.Payload.Lock = newLock
|
||||
sw.Payload.WriteVendor = true
|
||||
}
|
||||
}
|
||||
} else if lock != nil {
|
||||
|
|
|
@ -165,14 +165,14 @@ func TestSafeWriter_ManifestAndUnmodifiedLock(t *testing.T) {
|
|||
pc.Load()
|
||||
|
||||
var sw SafeWriter
|
||||
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, nil, false)
|
||||
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, false)
|
||||
|
||||
// Verify prepared actions
|
||||
if !sw.Payload.HasManifest() {
|
||||
t.Fatal("Expected the payload to contain the manifest")
|
||||
}
|
||||
if !sw.Payload.HasLock() {
|
||||
t.Fatal("Expected the payload to contain the lock")
|
||||
if sw.Payload.HasLock() {
|
||||
t.Fatal("Did not expect the payload to contain the lock")
|
||||
}
|
||||
if sw.Payload.HasVendor() {
|
||||
t.Fatal("Did not expect the payload to contain the vendor directory")
|
||||
|
@ -208,7 +208,7 @@ func TestSafeWriter_ManifestAndUnmodifiedLockWithForceVendor(t *testing.T) {
|
|||
pc.Load()
|
||||
|
||||
var sw SafeWriter
|
||||
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, nil, true)
|
||||
sw.Prepare(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, true)
|
||||
|
||||
// Verify prepared actions
|
||||
if !sw.Payload.HasManifest() {
|
||||
|
@ -339,7 +339,7 @@ func TestSafeWriter_ForceVendorWhenVendorAlreadyExists(t *testing.T) {
|
|||
|
||||
var sw SafeWriter
|
||||
// Populate vendor
|
||||
sw.Prepare(nil, pc.Project.Lock, nil, true)
|
||||
sw.Prepare(nil, pc.Project.Lock, pc.Project.Lock, true)
|
||||
err := sw.Write(pc.Project.AbsRoot, pc.SourceManager)
|
||||
h.Must(errors.Wrap(err, "SafeWriter.Write failed"))
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче