github.com/jdolitsky/cnab-go@v0.7.1-beta1/action/status_test.go (about) 1 package action 2 3 import ( 4 "errors" 5 "io/ioutil" 6 "testing" 7 8 "github.com/deislabs/cnab-go/driver" 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 // makes sure Status implements Action interface 14 var _ Action = &Status{} 15 16 func TestStatus_Run(t *testing.T) { 17 out := func(op *driver.Operation) error { 18 op.Out = ioutil.Discard 19 return nil 20 } 21 22 t.Run("happy-path", func(t *testing.T) { 23 st := &Status{ 24 Driver: &mockDriver{ 25 shouldHandle: true, 26 Result: driver.OperationResult{ 27 Outputs: map[string]string{ 28 "/tmp/some/path": "SOME CONTENT", 29 }, 30 }, 31 Error: nil, 32 }, 33 } 34 c := newClaim() 35 err := st.Run(c, mockSet, out) 36 assert.NoError(t, err) 37 // Status is not a modifying action 38 assert.Empty(t, c.Outputs) 39 }) 40 41 t.Run("configure operation", func(t *testing.T) { 42 c := newClaim() 43 d := &mockDriver{ 44 shouldHandle: true, 45 Result: driver.OperationResult{ 46 Outputs: map[string]string{ 47 "/tmp/some/path": "SOME CONTENT", 48 }, 49 }, 50 Error: nil, 51 } 52 inst := &Status{Driver: d} 53 addFile := func(op *driver.Operation) error { 54 op.Files["/tmp/another/path"] = "ANOTHER FILE" 55 return nil 56 } 57 require.NoError(t, inst.Run(c, mockSet, out, addFile)) 58 assert.Contains(t, d.Operation.Files, "/tmp/another/path") 59 }) 60 61 t.Run("error case: configure operation", func(t *testing.T) { 62 c := newClaim() 63 d := &mockDriver{ 64 shouldHandle: true, 65 Result: driver.OperationResult{ 66 Outputs: map[string]string{ 67 "/tmp/some/path": "SOME CONTENT", 68 }, 69 }, 70 Error: nil, 71 } 72 inst := &Status{Driver: d} 73 sabotage := func(op *driver.Operation) error { 74 return errors.New("oops") 75 } 76 require.EqualError(t, inst.Run(c, mockSet, out, sabotage), "oops") 77 }) 78 79 t.Run("error case: driver doesn't handle image", func(t *testing.T) { 80 c := newClaim() 81 st := &Status{Driver: &mockDriver{Error: errors.New("I always fail")}} 82 err := st.Run(c, mockSet, out) 83 assert.Error(t, err) 84 }) 85 }