add unit test to test behaviour on start stop
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
This commit is contained in:
53
mock/remote_test.go
Normal file
53
mock/remote_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStartStop(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
count int
|
||||
shutdownAgain bool
|
||||
expectErr bool
|
||||
}{
|
||||
"TargetStartStop": {
|
||||
count: 3,
|
||||
expectErr: false,
|
||||
},
|
||||
"TargetStop": {
|
||||
count: 1,
|
||||
expectErr: true,
|
||||
shutdownAgain: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tt := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
for i := 0; i < tt.count; i++ {
|
||||
bs := &remoteBs{}
|
||||
err := bs.Startup("store1", "", "127.0.0.1", 2147483648, 512)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to initialize tgt, err: ", err)
|
||||
}
|
||||
|
||||
expectErr := false
|
||||
err = bs.Shutdown()
|
||||
if err != nil {
|
||||
expectErr = true
|
||||
}
|
||||
|
||||
if tt.shutdownAgain {
|
||||
err = bs.Shutdown()
|
||||
if err != nil {
|
||||
expectErr = true
|
||||
}
|
||||
}
|
||||
|
||||
if tt.expectErr != expectErr {
|
||||
t.Fatalf("Startup test failed, err: %v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user