github.com/drycc/workflow-cli@v1.5.3-0.20240322092846-d4ee25983af9/pkg/testutil/testutil_test.go (about) 1 package testutil 2 3 import ( 4 "bytes" 5 "io" 6 "net/http" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 type nopCloser struct { 13 io.Reader 14 } 15 16 func (nopCloser) Close() error { return nil } 17 18 // TestStripProgress ensures StripProgress strips what is expected. 19 func TestStripProgress(t *testing.T) { 20 testInput := "Lorem ipsum dolar sit amet" 21 expectedOutput := "Lorem ipsum dolar sit amet" 22 23 assert.Equal(t, StripProgress(testInput), expectedOutput, "output") 24 25 testInput = "Lorem ipsum dolar sit amet...\b\b\b" 26 assert.Equal(t, StripProgress(testInput), expectedOutput, "output") 27 } 28 29 // TestAssertBody ensures AssertBody correctly marshals into the interface. 30 func TestAssertBody(t *testing.T) { 31 32 b := nopCloser{bytes.NewBufferString(`{"data":{"lorem":"ipsum"},"dolar":["sit","amet"]}`)} 33 34 sampleRequest := http.Request{ 35 Body: b, 36 } 37 38 expected := map[string]interface{}{ 39 "data": map[string]interface{}{ 40 "lorem": "ipsum", 41 }, 42 "dolar": []string{ 43 "sit", 44 "amet", 45 }, 46 } 47 48 AssertBody(t, expected, &sampleRequest) 49 }