Skip to content

Commit

Permalink
add addtional test iterations for background reader
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Jul 5, 2023
1 parent 3ee176f commit 0defb5d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Getting started

In order to test and develop in this repo you will need the following dependencies installed:
- Golang >= 1.20
- Golang
- docker
- make

Expand Down
5 changes: 0 additions & 5 deletions cmd/syft/cli/ui/handle_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,11 @@ func (l attestLogFrame) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case attestLogFrameTickMsg:
l.lines = l.reader.Lines()
// TODO: remove me
fmt.Printf("lines: %#v\n", l.lines)

l.completed = progress.IsCompleted(l.prog)
err := l.prog.Error()
l.failed = err != nil && !progress.IsErrCompleted(err)

fmt.Printf("completed: %#v\n", l.completed)
fmt.Printf("failed: %#v\n", l.failed)

tickCmd := l.handleTick(msg)

return l, tickCmd
Expand Down
8 changes: 8 additions & 0 deletions cmd/syft/cli/ui/handle_attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func TestHandler_handleAttestationStarted(t *testing.T) {
}{
{
name: "attesting in progress",
// note: this model depends on a background reader. Multiple iterations ensures that the
// reader has time to at least start and process the test fixture before the runModel
// test harness completes (which is a fake event loop anyway).
iterations: 2,
eventFn: func(t *testing.T) partybus.Event {
reader := strings.NewReader("contents\nof\nstuff!")

Expand Down Expand Up @@ -54,6 +58,10 @@ func TestHandler_handleAttestationStarted(t *testing.T) {
},
{
name: "attesting complete",
// note: this model depends on a background reader. Multiple iterations ensures that the
// reader has time to at least start and process the test fixture before the runModel
// test harness completes (which is a fake event loop anyway).
iterations: 2,
eventFn: func(t *testing.T) partybus.Event {
reader := strings.NewReader("contents\nof\nstuff!")

Expand Down
6 changes: 3 additions & 3 deletions cmd/syft/cli/ui/util_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ui

import (
"fmt"
"reflect"
"testing"
"unsafe"

tea "github.com/charmbracelet/bubbletea"
)

func runModel(_ testing.TB, m tea.Model, iterations int, message tea.Msg) string {
func runModel(t testing.TB, m tea.Model, iterations int, message tea.Msg) string {
t.Helper()
if iterations == 0 {
iterations = 1
}
Expand All @@ -23,7 +23,7 @@ func runModel(_ testing.TB, m tea.Model, iterations int, message tea.Msg) string
var nextCmds []tea.Cmd
var next tea.Cmd
for _, msg := range msgs {
fmt.Printf("Message: %+v %+v\n", reflect.TypeOf(msg), msg)
t.Logf("Message: %+v %+v\n", reflect.TypeOf(msg), msg)
m, next = m.Update(msg)
nextCmds = append(nextCmds, next)
}
Expand Down

0 comments on commit 0defb5d

Please sign in to comment.