-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial mocking-out of io.ReadAll in runs delete, added runs delete t…
…o readme Signed-off-by: Eamonn Mansour <[email protected]>
- Loading branch information
Showing
10 changed files
with
191 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright contributors to the Galasa project | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package spi | ||
|
||
import "io" | ||
|
||
// An interface to allow for mocking out "io" package reading-related methods | ||
type ByteReader interface { | ||
ReadAll(reader io.Reader) ([]byte, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright contributors to the Galasa project | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package utils | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/galasa-dev/cli/pkg/spi" | ||
) | ||
|
||
// Implementation of a byte reader to allow mocking out methods from the io package | ||
type ByteReaderImpl struct { | ||
} | ||
|
||
func NewByteReader() spi.ByteReader { | ||
return new(ByteReaderImpl) | ||
} | ||
|
||
func (*ByteReaderImpl) ReadAll(reader io.Reader) ([]byte, error) { | ||
return io.ReadAll(reader) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright contributors to the Galasa project | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package utils | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
|
||
"github.com/galasa-dev/cli/pkg/spi" | ||
) | ||
|
||
// Mock implementation of a byte reader to allow for simulating failed read operations | ||
type MockByteReader struct { | ||
throwReadError bool | ||
} | ||
|
||
func NewMockByteReaderAsMock(throwReadError bool) *MockByteReader { | ||
return &MockByteReader{ | ||
throwReadError: throwReadError, | ||
} | ||
} | ||
|
||
func NewMockByteReader() spi.ByteReader { | ||
return NewMockByteReaderAsMock(false) | ||
} | ||
|
||
func (mockReader *MockByteReader) ReadAll(reader io.Reader) ([]byte, error) { | ||
var err error | ||
var bytes []byte | ||
if mockReader.throwReadError { | ||
err = errors.New("simulating a read failure") | ||
} else { | ||
bytes, err = io.ReadAll(reader) | ||
} | ||
return bytes, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters