add unit test to test behaviour on start stop

Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
This commit is contained in:
Utkarsh Mani Tripathi
2019-11-28 13:36:49 +05:30
parent e73507f461
commit f14ea31cbb
3 changed files with 259 additions and 2 deletions

53
mock/remote_test.go Normal file
View 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)
}
}
})
}
}