-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
179 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package steps | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_isUpdate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input StepInput | ||
in string | ||
want bool | ||
}{ | ||
{ | ||
name: "test input with no existing value", | ||
input: StepInput{ | ||
Name: "idontexist", | ||
AlreadyExist: false, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "test input with existing value and want to update", | ||
input: StepInput{ | ||
Name: "iexist", | ||
AlreadyExist: true, | ||
}, | ||
in: "y", | ||
want: true, | ||
}, | ||
{ | ||
name: "test input with existing value and dont want to update", | ||
input: StepInput{ | ||
Name: "iexist", | ||
AlreadyExist: true, | ||
}, | ||
in: "n", | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Create a buffer to store the input string. | ||
var buf bytes.Buffer | ||
|
||
// Create a new io.ReaderCloser using the buffer. | ||
reader := io.NopCloser(&buf) | ||
|
||
// Write the input string to the buffer. | ||
buf.WriteString(fmt.Sprintf("%s\n", tt.in)) | ||
|
||
update := isUpdate(tt.input, reader) | ||
assert.Equal(t, tt.want, update) | ||
}) | ||
} | ||
} |
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