| 1 |
/* |
| 2 |
Copyright 2013-2014 Canonical Ltd. |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify it |
| 5 |
under the terms of the GNU General Public License version 3, as published |
| 6 |
by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but |
| 9 |
WITHOUT ANY WARRANTY; without even the implied warranties of |
| 10 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. See the GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License along |
| 14 |
with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
package acceptance_test |
| 18 |
|
| 19 |
import ( |
| 20 |
"flag" |
| 21 |
"fmt" |
| 22 |
"testing" |
| 23 |
|
| 24 |
. "gopkg.in/check.v1" |
| 25 |
|
| 26 |
"gitlab.com/ubports/development/core/lomiri-push-service/server/acceptance/suites" |
| 27 |
) |
| 28 |
|
| 29 |
func TestAcceptance(t *testing.T) { TestingT(t) } |
| 30 |
|
| 31 |
var serverCmd = flag.String("server", "", "server to test") |
| 32 |
|
| 33 |
func testServerConfig(addr, httpAddr string) map[string]interface{} { |
| 34 |
cfg := make(map[string]interface{}) |
| 35 |
suites.FillServerConfig(cfg, addr) |
| 36 |
suites.FillHTTPServerConfig(cfg, httpAddr) |
| 37 |
cfg["delivery_domain"] = "push-delivery" |
| 38 |
return cfg |
| 39 |
} |
| 40 |
|
| 41 |
// Start a server. |
| 42 |
func StartServer(c *C, s *suites.AcceptanceSuite, handle *suites.ServerHandle) { |
| 43 |
if *serverCmd == "" { |
| 44 |
c.Skip("executable server not specified") |
| 45 |
} |
| 46 |
tmpDir := c.MkDir() |
| 47 |
cfg := testServerConfig("127.0.0.1:0", "127.0.0.1:0") |
| 48 |
cfgFilename := suites.WriteConfig(c, tmpDir, "config.json", cfg) |
| 49 |
logs, killServer := suites.RunAndObserve(c, *serverCmd, cfgFilename) |
| 50 |
s.KillGroup["server"] = killServer |
| 51 |
handle.ServerHTTPAddr = suites.ExtractListeningAddr(c, logs, suites.HTTPListeningOnPat) |
| 52 |
s.ServerAPIURL = fmt.Sprintf("http://%s", handle.ServerHTTPAddr) |
| 53 |
handle.ServerAddr = suites.ExtractListeningAddr(c, logs, suites.DevListeningOnPat) |
| 54 |
handle.ServerEvents = logs |
| 55 |
} |
| 56 |
|
| 57 |
// ping pong/connectivity |
| 58 |
var _ = Suite(&suites.PingPongAcceptanceSuite{suites.AcceptanceSuite{StartServer: StartServer}}) |
| 59 |
|
| 60 |
// broadcast |
| 61 |
var _ = Suite(&suites.BroadcastAcceptanceSuite{suites.AcceptanceSuite{StartServer: StartServer}}) |
| 62 |
|
| 63 |
// unicast |
| 64 |
var _ = Suite(&suites.UnicastAcceptanceSuite{suites.AcceptanceSuite{StartServer: StartServer}, nil}) |