github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/provider/local/local_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package local_test 5 6 import ( 7 "fmt" 8 "net" 9 "runtime" 10 stdtesting "testing" 11 12 jc "github.com/juju/testing/checkers" 13 gc "gopkg.in/check.v1" 14 15 "github.com/juju/juju/environs" 16 "github.com/juju/juju/provider" 17 "github.com/juju/juju/provider/local" 18 coretesting "github.com/juju/juju/testing" 19 ) 20 21 func TestLocal(t *stdtesting.T) { 22 if runtime.GOOS == "windows" { 23 t.Skip("Local provider is not supported on windows") 24 } 25 gc.TestingT(t) 26 } 27 28 type localSuite struct { 29 coretesting.BaseSuite 30 } 31 32 var _ = gc.Suite(&localSuite{}) 33 34 func (*localSuite) TestProviderRegistered(c *gc.C) { 35 provider, error := environs.Provider(provider.Local) 36 c.Assert(error, gc.IsNil) 37 c.Assert(provider, gc.DeepEquals, local.Provider) 38 } 39 40 func (*localSuite) TestCheckLocalPort(c *gc.C) { 41 // Listen on a random port. 42 ln, err := net.Listen("tcp", "127.0.0.1:0") 43 c.Assert(err, jc.ErrorIsNil) 44 defer ln.Close() 45 port := ln.Addr().(*net.TCPAddr).Port 46 47 checkLocalPort := *local.CheckLocalPort 48 err = checkLocalPort(port, "test port") 49 c.Assert(err, gc.ErrorMatches, fmt.Sprintf("cannot use %d as test port, already in use", port)) 50 51 ln.Close() 52 err = checkLocalPort(port, "test port, no longer in use") 53 c.Assert(err, jc.ErrorIsNil) 54 }