summaryrefslogtreecommitdiffstats
path: root/test/sdks_test.go
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-10-23 15:09:06 +0200
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2018-10-24 10:43:37 +0000
commita740425411f120ff7263f16f268e7efd7c19b311 (patch)
tree4ef142dfb4b5c57648e4e00243a234b2ad31f086 /test/sdks_test.go
parent3e3222406a6f015a9fee3720e8ba76ecf58b087f (diff)
testify: assert replace by require
require handles tests to be aborted during an assertion contrary to assert Change-Id: I3062046515c74509ae7ea1b24b7242a42d0191c1 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test/sdks_test.go')
-rw-r--r--test/sdks_test.go62
1 files changed, 31 insertions, 31 deletions
diff --git a/test/sdks_test.go b/test/sdks_test.go
index 1395b16..15f78a3 100644
--- a/test/sdks_test.go
+++ b/test/sdks_test.go
@@ -26,7 +26,7 @@ import (
"time"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
var cpt int
@@ -51,12 +51,12 @@ func ConnectSDKStateChange(t *testing.T, sCli *IOSockClient, channel chan xsapiv
})
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTSDKStateChange}
- assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/register", args, nil))
}
func DisconnectSDKStateChange(t *testing.T, sCli *IOSockClient) {
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTSDKStateChange}
- assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
}
func InitSdkDir() {
@@ -74,12 +74,12 @@ func InitSdkDir() {
func RemoveSdk(t *testing.T, sdk xsapiv1.SDK, chSdks chan xsapiv1.SDK) {
Debugf(t, "remove sdk %v", sdk.ID)
- assert.Nil(t, HTTPCli.Delete("/sdks/"+sdk.ID, &sdk))
+ require.Nil(t, HTTPCli.Delete("/sdks/"+sdk.ID, &sdk))
sdkFromEvt := <-chSdks //waiting for event Uninstalling
- assert.Equal(t, sdk.ID, sdkFromEvt.ID)
- assert.Equal(t, sdkFromEvt.Status, "Un-installing")
+ require.Equal(t, sdk.ID, sdkFromEvt.ID)
+ require.Equal(t, sdkFromEvt.Status, "Un-installing")
sdkFromEvt = <-chSdks //waiting for event not installed
- assert.Equal(t, sdkFromEvt.Status, "Not Installed")
+ require.Equal(t, sdkFromEvt.Status, "Not Installed")
os.RemoveAll(path.Join(os.Getenv(envXdtSdk), sdk.Profile))
os.Remove(strings.Replace(sdk.URL, "file://", "", 1))
}
@@ -88,9 +88,9 @@ func TestSdks(t *testing.T) {
InitSdkDir()
/*get sdk list from sdk_latest.json*/
var sdkArray []xsapiv1.SDK
- assert.Nil(t, HTTPCli.Get("/sdks", &sdkArray))
+ require.Nil(t, HTTPCli.Get("/sdks", &sdkArray))
_, err := os.Stat(path.Join(os.Getenv(envXdtSdk), "sdks_latest.json"))
- assert.Nil(t, err)
+ require.Nil(t, err)
/*create channel fro SDK event*/
chSdks := make(chan xsapiv1.SDK)
@@ -100,46 +100,46 @@ func TestSdks(t *testing.T) {
/*checking startup installing of SDKs*/
for i := 0; i < len(sdkArray); i++ {
re := regexp.MustCompile("^[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+$")
- assert.True(t, re.MatchString(sdkArray[i].ID))
- assert.Equal(t, sdkArray[0].Status, "Not Installed")
+ require.True(t, re.MatchString(sdkArray[i].ID))
+ require.Equal(t, sdkArray[0].Status, "Not Installed")
var sdk xsapiv1.SDK
- assert.Nil(t, HTTPCli.Get("/sdks/"+sdkArray[i].ID, &sdk))
- assert.Equal(t, sdkArray[i], sdk)
+ require.Nil(t, HTTPCli.Get("/sdks/"+sdkArray[i].ID, &sdk))
+ require.Equal(t, sdkArray[i], sdk)
var sdkRes xsapiv1.SDK
/*install sdk*/
Debugf(t, "install sdk %v", sdk.Name)
- assert.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
- assert.Equal(t, sdkRes.Status, "Installing")
+ require.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.Equal(t, sdkRes.Status, "Installing")
sdkFromEvent := <-chSdks //waiting for installing event
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, sdkFromEvent.Status, "Installing")
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, sdkFromEvent.Status, "Installing")
/*abort sdk install*/
Debugf(t, "abort install sdk %v", sdk.Name)
- assert.Nil(t, HTTPCli.Post("/sdks/abortinstall", sdk, &sdkRes))
- assert.Equal(t, sdkRes.Status, "Not Installed")
+ require.Nil(t, HTTPCli.Post("/sdks/abortinstall", sdk, &sdkRes))
+ require.Equal(t, sdkRes.Status, "Not Installed")
sdkFromEvent = <-chSdks //waiting for not installed status*/
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, sdkRes.Status, sdkFromEvent.Status)
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, sdkRes.Status, sdkFromEvent.Status)
}
}
func installFakeSdk(t *testing.T, sdkInstall xsapiv1.SDKInstallArgs, chSdks chan xsapiv1.SDK) xsapiv1.SDK {
InitSdkDir()
var sdkRes xsapiv1.SDK
- assert.Nil(t, HTTPCli.Post("/sdks", sdkInstall, &sdkRes))
+ require.Nil(t, HTTPCli.Post("/sdks", sdkInstall, &sdkRes))
Debugf(t, "Install fake sdk %v (force=%v)", sdkRes.Name, sdkInstall.Force)
- assert.Equal(t, sdkRes.Status, "Installing")
+ require.Equal(t, sdkRes.Status, "Installing")
sdkFromEvent := <-chSdks
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, sdkFromEvent.Status, "Installing")
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, sdkFromEvent.Status, "Installing")
/*waiting for SDKStateChange event from channel*/
sdkFromEvent = <-chSdks
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, "Installed", sdkFromEvent.Status)
- assert.Equal(t, sdkFromEvent.LastError, "")
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, "Installed", sdkFromEvent.Status)
+ require.Equal(t, sdkFromEvent.LastError, "")
Debugf(t, "Fake sdk %v installed", sdkFromEvent.Name)
return sdkFromEvent
}
@@ -172,14 +172,14 @@ func TestSdksError(t *testing.T) {
Debugf(t, "error while installing sdk with no ID and no Filename")
var sdkRes xsapiv1.SDK
/*error with no ID no filename*/
- assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
sdk.ID = "42885c24-374e-3ef0-9723-0c8a05191aa"
Debugf(t, "error while installing sdk with a fake id=%v", sdk.ID)
/*error with fake ID*/
- assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
sdk.ID = ""
sdk.Filename = "fake"
Debugf(t, "error while installing sdk with a fake filename=%v", sdk.Filename)
/*error with fake filename*/
- assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
}