github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/containerupdate/fake_container_updater.go (about) 1 package containerupdate 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "io" 8 9 "github.com/tilt-dev/tilt/internal/store/liveupdates" 10 "github.com/tilt-dev/tilt/pkg/model" 11 ) 12 13 type FakeContainerUpdater struct { 14 UpdateErrs []error 15 16 Calls []UpdateContainerCall 17 } 18 19 type UpdateContainerCall struct { 20 ContainerInfo liveupdates.Container 21 Archive io.Reader 22 ToDelete []string 23 Cmds []model.Cmd 24 HotReload bool 25 } 26 27 func (cu *FakeContainerUpdater) SetUpdateErr(err error) { 28 cu.UpdateErrs = []error{err} 29 } 30 31 func (cu *FakeContainerUpdater) UpdateContainer(ctx context.Context, cInfo liveupdates.Container, 32 archiveToCopy io.Reader, filesToDelete []string, cmds []model.Cmd, hotReload bool) error { 33 34 var archive bytes.Buffer 35 if _, err := io.Copy(&archive, archiveToCopy); err != nil { 36 return fmt.Errorf("FakeContainerUpdater failed to read archive: %v", err) 37 } 38 cu.Calls = append(cu.Calls, UpdateContainerCall{ 39 ContainerInfo: cInfo, 40 Archive: &archive, 41 ToDelete: filesToDelete, 42 Cmds: cmds, 43 HotReload: hotReload, 44 }) 45 46 // If we're supposed to throw an error on this call, throw it (and pop from 47 // the list of UpdateErrs) 48 var err error 49 if len(cu.UpdateErrs) > 0 { 50 err = cu.UpdateErrs[0] 51 cu.UpdateErrs = append([]error{}, cu.UpdateErrs[1:]...) 52 } 53 return err 54 }