-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added occurrence for the WaitLogStrategy
This is related to the work @giorgioazzinnaro is doing here #98 . Now you can declare how many times a log line should appear before having the container declared as ready. Signed-off-by: Gianluca Arbezzano <[email protected]>
- Loading branch information
Gianluca Arbezzano
committed
Oct 3, 2019
1 parent
de4c7e2
commit 456f324
Showing
4 changed files
with
84 additions
and
1 deletion.
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,65 @@ | ||
package wait | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"io/ioutil" | ||
"testing" | ||
"time" | ||
|
||
"github.com/docker/go-connections/nat" | ||
) | ||
|
||
type noopStrategyTarget struct { | ||
ioReaderCloser io.ReadCloser | ||
} | ||
|
||
func (st noopStrategyTarget) Host(ctx context.Context) (string, error) { | ||
return "", nil | ||
} | ||
|
||
func (st noopStrategyTarget) MappedPort(ctx context.Context, n nat.Port) (nat.Port, error) { | ||
return n, nil | ||
} | ||
|
||
func (st noopStrategyTarget) Logs(ctx context.Context) (io.ReadCloser, error) { | ||
return st.ioReaderCloser, nil | ||
} | ||
|
||
func TestWaitForLog(t *testing.T) { | ||
target := noopStrategyTarget{ | ||
ioReaderCloser: ioutil.NopCloser(bytes.NewReader([]byte("dude"))), | ||
} | ||
wg := NewLogStrategy("dude").WithStartupTimeout(100 * time.Microsecond) | ||
err := wg.WaitUntilReady(context.Background(), target) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestWaitWithMaxOccurence(t *testing.T) { | ||
target := noopStrategyTarget{ | ||
ioReaderCloser: ioutil.NopCloser(bytes.NewReader([]byte("hello\r\ndude\n\rdude"))), | ||
} | ||
wg := NewLogStrategy("dude"). | ||
WithStartupTimeout(100 * time.Microsecond). | ||
WithOccurence(2) | ||
err := wg.WaitUntilReady(context.Background(), target) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestWaitWithMaxOccurenceButItWillNeverHappen(t *testing.T) { | ||
target := noopStrategyTarget{ | ||
ioReaderCloser: ioutil.NopCloser(bytes.NewReader([]byte("hello\r\ndude"))), | ||
} | ||
wg := NewLogStrategy("blaaa"). | ||
WithStartupTimeout(100 * time.Microsecond). | ||
WithOccurence(2) | ||
err := wg.WaitUntilReady(context.Background(), target) | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
} |