@@ -1324,87 +1324,88 @@ func TestSSH(t *testing.T) {
13241324
13251325 ctx := context .Background ()
13261326
1327- compose := environment .New (t ).Up (ctx )
1328- t .Cleanup (func () {
1329- compose .Down ()
1330- })
1327+ databases := []string {"mongo" }
1328+ for _ , db := range databases {
1329+ compose := environment .New (t ).WithEnv ("SHELLHUB_DATABASE" , db ).Up (ctx )
1330+ compose .NewUser (t , ShellHubUsername , ShellHubEmail , ShellHubPassword )
1331+ compose .NewNamespace (t , ShellHubUsername , ShellHubNamespaceName , ShellHubNamespace )
13311332
1332- compose .NewUser (t , ShellHubUsername , ShellHubEmail , ShellHubPassword )
1333- compose .NewNamespace (t , ShellHubUsername , ShellHubNamespaceName , ShellHubNamespace )
1334-
1335- auth := models.UserAuthResponse {}
1336-
1337- require .EventuallyWithT (t , func (tt * assert.CollectT ) {
1338- resp , err := compose .R (ctx ).
1339- SetBody (map [string ]string {
1340- "username" : ShellHubUsername ,
1341- "password" : ShellHubPassword ,
1342- }).
1343- SetResult (& auth ).
1344- Post ("/api/login" )
1345- assert .Equal (tt , 200 , resp .StatusCode ())
1346- assert .NoError (tt , err )
1347- }, 30 * time .Second , 1 * time .Second )
1348-
1349- compose .JWT (auth .Token )
1350-
1351- for _ , tc := range tests {
1352- test := tc
1353- t .Run (test .name , func (tt * testing.T ) {
1354- agent , err := NewAgentContainer (
1355- ctx ,
1356- compose .Env ("SHELLHUB_HTTP_PORT" ),
1357- test .options ... ,
1358- )
1359- require .NoError (tt , err )
1360-
1361- agent .Stop (ctx , nil )
1362-
1363- err = agent .Start (ctx )
1364- require .NoError (tt , err )
1365-
1366- tt .Cleanup (func () {
1367- agent .Stop (context .Background (), nil )
1368- })
1369-
1370- t .Cleanup (func () {
1371- agent .Terminate (context .Background ())
1372- })
1333+ auth := models.UserAuthResponse {}
13731334
1374- devices := []models.Device {}
1335+ require .EventuallyWithT (t , func (tt * assert.CollectT ) {
1336+ resp , err := compose .R (ctx ).
1337+ SetBody (map [string ]string {
1338+ "username" : ShellHubUsername ,
1339+ "password" : ShellHubPassword ,
1340+ }).
1341+ SetResult (& auth ).
1342+ Post ("/api/login" )
1343+ assert .Equal (tt , 200 , resp .StatusCode ())
1344+ assert .NoError (tt , err )
1345+ }, 30 * time .Second , 1 * time .Second )
1346+
1347+ compose .JWT (auth .Token )
1348+
1349+ for _ , tc := range tests {
1350+ test := tc
1351+ t .Run (test .name , func (tt * testing.T ) {
1352+ agent , err := NewAgentContainer (
1353+ ctx ,
1354+ compose .Env ("SHELLHUB_HTTP_PORT" ),
1355+ test .options ... ,
1356+ )
1357+ require .NoError (tt , err )
1358+
1359+ agent .Stop (ctx , nil )
1360+
1361+ err = agent .Start (ctx )
1362+ require .NoError (tt , err )
1363+
1364+ tt .Cleanup (func () {
1365+ agent .Stop (context .Background (), nil )
1366+ })
13751367
1376- require .EventuallyWithT (tt , func (tt * assert.CollectT ) {
1377- resp , err := compose .R (ctx ).SetResult (& devices ).
1378- Get ("/api/devices?status=pending" )
1379- assert .Equal (tt , 200 , resp .StatusCode ())
1380- assert .NoError (tt , err )
1368+ t .Cleanup (func () {
1369+ agent .Terminate (context .Background ())
1370+ })
13811371
1382- assert .Len (tt , devices , 1 )
1383- }, 30 * time .Second , 1 * time .Second )
1372+ devices := []models.Device {}
13841373
1385- resp , err := compose .R (ctx ).
1386- Patch (fmt .Sprintf ("/api/devices/%s/accept" , devices [0 ].UID ))
1387- require .Equal (tt , 200 , resp .StatusCode ())
1388- require .NoError (tt , err )
1374+ require .EventuallyWithT (tt , func (tt * assert.CollectT ) {
1375+ resp , err := compose .R (ctx ).SetResult (& devices ).
1376+ Get ("/api/devices?status=pending" )
1377+ assert .Equal (tt , 200 , resp .StatusCode ())
1378+ assert .NoError (tt , err )
13891379
1390- device := models.Device {}
1380+ assert .Len (tt , devices , 1 )
1381+ }, 30 * time .Second , 1 * time .Second )
13911382
1392- require .EventuallyWithT (tt , func (tt * assert.CollectT ) {
13931383 resp , err := compose .R (ctx ).
1394- SetResult (& device ).
1395- Get (fmt .Sprintf ("/api/devices/%s" , devices [0 ].UID ))
1396- assert .Equal (tt , 200 , resp .StatusCode ())
1397- assert .NoError (tt , err )
1384+ Patch (fmt .Sprintf ("/api/devices/%s/accept" , devices [0 ].UID ))
1385+ require .Equal (tt , 200 , resp .StatusCode ())
1386+ require .NoError (tt , err )
1387+
1388+ device := models.Device {}
1389+
1390+ require .EventuallyWithT (tt , func (tt * assert.CollectT ) {
1391+ resp , err := compose .R (ctx ).
1392+ SetResult (& device ).
1393+ Get (fmt .Sprintf ("/api/devices/%s" , devices [0 ].UID ))
1394+ assert .Equal (tt , 200 , resp .StatusCode ())
1395+ assert .NoError (tt , err )
13981396
1399- assert .True (tt , device .Online )
1400- }, 30 * time .Second , 1 * time .Second )
1397+ assert .True (tt , device .Online )
1398+ }, 30 * time .Second , 1 * time .Second )
14011399
1402- // --
1400+ // --
14031401
1404- test .run (tt , & Environment {
1405- services : compose ,
1406- agent : agent ,
1407- }, & device )
1408- })
1402+ test .run (tt , & Environment {
1403+ services : compose ,
1404+ agent : agent ,
1405+ }, & device )
1406+ })
1407+ }
1408+
1409+ compose .Down ()
14091410 }
14101411}
0 commit comments