本文整理汇总了Golang中github.com/coreos/rkt/tests/testutils.HTTPGet函数的典型用法代码示例。如果您正苦于以下问题:Golang HTTPGet函数的具体用法?Golang HTTPGet怎么用?Golang HTTPGet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPGet函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewTestNetDefaultRestrictedConnectivity
/*
* Default-restricted net
* ---
* Container launches http server on all its interfaces
* Host must be able to connects to container's http server via container's
* eth0's IPv4
* TODO: verify that the container isn't NATed
*/
func NewTestNetDefaultRestrictedConnectivity() testutils.Test {
return testutils.TestFunc(func(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
f := func(argument string) {
httpPort, err := testutils.GetNextFreePort4()
if err != nil {
t.Fatalf("%v", err)
}
httpServeAddr := fmt.Sprintf("0.0.0.0:%v", httpPort)
iface := "eth0"
testImageArgs := []string{fmt.Sprintf("--exec=/inspect --print-ipv4=%v --serve-http=%v", iface, httpServeAddr)}
testImage := patchTestACI("rkt-inspect-networking.aci", testImageArgs...)
defer os.Remove(testImage)
cmd := fmt.Sprintf("%s --debug --insecure-options=image run %s --mds-register=false %s", ctx.Cmd(), argument, testImage)
child := spawnOrFail(t, cmd)
expectedRegex := `IPv4: (\d+\.\d+\.\d+\.\d+)`
result, out, err := expectRegexWithOutput(child, expectedRegex)
if err != nil {
t.Fatalf("Error: %v\nOutput: %v", err, out)
}
httpGetAddr := fmt.Sprintf("http://%v:%v", result[1], httpPort)
ga := testutils.NewGoroutineAssistant(t)
ga.Add(2)
// Child opens the server
go func() {
defer ga.Done()
ga.WaitOrFail(child)
}()
// Host connects to the child
go func() {
defer ga.Done()
expectedRegex := `serving on`
_, out, err := expectRegexWithOutput(child, expectedRegex)
if err != nil {
ga.Fatalf("Error: %v\nOutput: %v", err, out)
}
body, err := testutils.HTTPGet(httpGetAddr)
if err != nil {
ga.Fatalf("%v\n", err)
}
t.Logf("HTTP-Get received: %s", body)
}()
ga.Wait()
}
f("--net=default-restricted")
})
}
开发者ID:nhlfr,项目名称:rkt,代码行数:64,代码来源:rkt_net_test.go
示例2: NewNetHostConnectivityTest
/*
* Host networking
* ---
* Container launches http server which must be reachable by the host via the
* localhost address
*/
func NewNetHostConnectivityTest() testutils.Test {
return testutils.TestFunc(func(t *testing.T) {
logger.SetLogger(t)
httpPort, err := testutils.GetNextFreePort4()
if err != nil {
t.Fatalf("%v", err)
}
httpServeAddr := fmt.Sprintf("0.0.0.0:%v", httpPort)
httpGetAddr := fmt.Sprintf("http://127.0.0.1:%v", httpPort)
testImageArgs := []string{"--exec=/inspect --serve-http=" + httpServeAddr}
testImage := patchTestACI("rkt-inspect-networking.aci", testImageArgs...)
defer os.Remove(testImage)
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
cmd := fmt.Sprintf("%s --net=host --debug --insecure-options=image run --mds-register=false %s", ctx.Cmd(), testImage)
child := spawnOrFail(t, cmd)
ctx.RegisterChild(child)
ga := testutils.NewGoroutineAssistant(t)
ga.Add(2)
// Child opens the server
go func() {
defer ga.Done()
ga.WaitOrFail(child)
}()
// Host connects to the child
go func() {
defer ga.Done()
expectedRegex := `serving on`
_, out, err := expectRegexWithOutput(child, expectedRegex)
if err != nil {
ga.Fatalf("Error: %v\nOutput: %v", err, out)
}
body, err := testutils.HTTPGet(httpGetAddr)
if err != nil {
ga.Fatalf("%v\n", err)
}
t.Logf("HTTP-Get received: %s", body)
}()
ga.Wait()
})
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:55,代码来源:rkt_net_test.go
示例3: NewTestNetDefaultRestrictedConnectivity
/*
* Default-restricted net
* ---
* Container launches http server on all its interfaces
* Host must be able to connects to container's http server via container's
* eth0's IPv4
* TODO: verify that the container isn't NATed
*/
func NewTestNetDefaultRestrictedConnectivity() testutils.Test {
return testutils.TestFunc(func(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
f := func(argument string) {
httpPort := "8080"
iface := "eth0"
testImageArgs := []string{fmt.Sprintf("--exec=/inspect --print-ipv4=%v --serve-http=0.0.0.0:%v", iface, httpPort)}
testImage := patchTestACI("rkt-inspect-networking.aci", testImageArgs...)
defer os.Remove(testImage)
cmd := fmt.Sprintf("%s --insecure-options=image run %s --mds-register=false %s", ctx.Cmd(), argument, testImage)
child := spawnOrFail(t, cmd)
// Wait for the container to print out the IP address
expectedRegex := `IPv4: (\d+\.\d+\.\d+\.\d+)`
result, out, err := expectRegexWithOutput(child, expectedRegex)
if err != nil {
t.Fatalf("Error: %v\nOutput: %v", err, out)
}
httpGetAddr := fmt.Sprintf("http://%v:%v", result[1], httpPort)
// Wait for the container to open the port
expectedRegex = `serving on`
_, out, err = expectRegexWithOutput(child, expectedRegex)
if err != nil {
t.Fatalf("Error: %v\nOutput: %v", err, out)
}
body, err := testutils.HTTPGet(httpGetAddr)
if err != nil {
t.Fatalf("%v\n", err)
}
t.Logf("HTTP-Get received: %s", body)
waitOrFail(t, child, 0)
}
f("--net=default-restricted")
})
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:48,代码来源:rkt_net_test.go
示例4: Execute
func (ct PortFwdCase) Execute(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
prepareTestNet(t, ctx, portFwdBridge)
httpPort, err := testutils.GetNextFreePort4Banned(bannedPorts)
if err != nil {
t.Fatalf("%v", err)
}
bannedPorts[httpPort] = struct{}{}
httpServePort := ct.HttpServePort
if httpServePort == 0 {
httpServePort = httpPort
}
httpServeAddr := fmt.Sprintf("0.0.0.0:%d", httpServePort)
testImageArgs := []string{
fmt.Sprintf("--ports=http,protocol=tcp,port=%d", httpServePort),
fmt.Sprintf("--exec=/inspect --serve-http=%v", httpServeAddr),
}
t.Logf("testImageArgs: %v", testImageArgs)
testImage := patchTestACI("rkt-inspect-networking.aci", testImageArgs...)
defer os.Remove(testImage)
cmd := fmt.Sprintf(
"%s --debug --insecure-options=image run --port=http:%s%d %s --mds-register=false %s",
ctx.Cmd(), ct.ListenAddress, httpPort, ct.RktArg, testImage)
child := spawnOrFail(t, cmd)
httpGetAddr := fmt.Sprintf("http://%v:%v", ct.HttpGetIP, httpPort)
ga := testutils.NewGoroutineAssistant(t)
ga.Add(2)
// Child opens the server
go func() {
defer ga.Done()
ga.WaitOrFail(child)
}()
// Host connects to the child via the forward port on localhost
go func() {
defer ga.Done()
expectedRegex := `serving on`
_, out, err := expectRegexWithOutput(child, expectedRegex)
if err != nil {
ga.Fatalf("Error: %v\nOutput: %v", err, out)
}
body, err := testutils.HTTPGet(httpGetAddr)
switch {
case err != nil && ct.ShouldSucceed:
ga.Fatalf("%v\n", err)
case err == nil && !ct.ShouldSucceed:
ga.Fatalf("HTTP-Get to %q should have failed! But received %q", httpGetAddr, body)
case err != nil && !ct.ShouldSucceed:
t.Logf("HTTP-Get failed, as expected: %v", err)
default:
t.Logf("HTTP-Get received: %s", body)
}
}()
ga.Wait()
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:65,代码来源:rkt_net_test.go
示例5: main
//.........这里部分代码省略.........
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("DefaultGWv4: %s\n", gw)
}
if globalFlags.PrintDefaultGWv6 {
gw, err := testutils.GetDefaultGWv6()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("DefaultGWv6: %s\n", gw)
}
if globalFlags.PrintGWv4 != "" {
// TODO: GetGW not implemented yet
iface := globalFlags.PrintGWv4
gw, err := testutils.GetGWv4(iface)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("%v GWv4: %s\n", iface, gw)
}
if globalFlags.PrintIPv6 != "" {
// TODO
}
if globalFlags.PrintGWv6 != "" {
// TODO
}
if globalFlags.PrintHostname {
hostname, err := os.Hostname()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Hostname: %s\n", hostname)
}
if globalFlags.ServeHTTP != "" {
err := testutils.HTTPServe(globalFlags.ServeHTTP, globalFlags.ServeHTTPTimeout)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
if globalFlags.GetHTTP != "" {
body, err := testutils.HTTPGet(globalFlags.GetHTTP)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("HTTP-Get received: %s\n", body)
}
if globalFlags.PrintIfaceCount {
ifaceCount, err := testutils.GetIfaceCount()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Interface count: %d\n", ifaceCount)
}
if globalFlags.PrintAppAnnotation != "" {
mdsUrl, appName := os.Getenv("AC_METADATA_URL"), os.Getenv("AC_APP_NAME")
body, err := testutils.HTTPGet(fmt.Sprintf("%s/acMetadata/v1/apps/%s/annotations/%s", mdsUrl, appName, globalFlags.PrintAppAnnotation))
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Annotation %s=%s\n", globalFlags.PrintAppAnnotation, body)
}
if globalFlags.CheckMountNS {
appMountNS, err := os.Readlink("/proc/self/ns/mnt")
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
s1MountNS, err := os.Readlink("/proc/1/ns/mnt")
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
if appMountNS != s1MountNS {
fmt.Println("check-mountns: DIFFERENT")
} else {
fmt.Println("check-mountns: IDENTICAL")
os.Exit(1)
}
}
os.Exit(globalFlags.ExitCode)
}
开发者ID:nak3,项目名称:rkt,代码行数:101,代码来源:inspect.go
示例6: main
//.........这里部分代码省略.........
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("NetNS: %s\n", ns)
}
if globalFlags.PrintIPv4 != "" {
iface := globalFlags.PrintIPv4
ips, err := testutils.GetIPsv4(iface)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("%v IPv4: %s\n", iface, ips[0])
}
if globalFlags.PrintDefaultGWv4 {
gw, err := testutils.GetDefaultGWv4()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("DefaultGWv4: %s\n", gw)
}
if globalFlags.PrintDefaultGWv6 {
gw, err := testutils.GetDefaultGWv6()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("DefaultGWv6: %s\n", gw)
}
if globalFlags.PrintGWv4 != "" {
// TODO: GetGW not implemented yet
iface := globalFlags.PrintGWv4
gw, err := testutils.GetGWv4(iface)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("%v GWv4: %s\n", iface, gw)
}
if globalFlags.PrintIPv6 != "" {
// TODO
}
if globalFlags.PrintGWv6 != "" {
// TODO
}
if globalFlags.PrintHostname {
hostname, err := os.Hostname()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Hostname: %s\n", hostname)
}
if globalFlags.ServeHTTP != "" {
err := testutils.HTTPServe(globalFlags.ServeHTTP, globalFlags.ServeHTTPTimeout)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
if globalFlags.GetHTTP != "" {
body, err := testutils.HTTPGet(globalFlags.GetHTTP)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("HTTP-Get received: %s\n", body)
}
if globalFlags.PrintIfaceCount {
ifaceCount, err := testutils.GetIfaceCount()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Interface count: %d\n", ifaceCount)
}
if globalFlags.PrintAppAnnotation != "" {
mdsUrl, appName := os.Getenv("AC_METADATA_URL"), os.Getenv("AC_APP_NAME")
body, err := testutils.HTTPGet(fmt.Sprintf("%s/acMetadata/v1/apps/%s/annotations/%s", mdsUrl, appName, globalFlags.PrintAppAnnotation))
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Annotation %s=%s\n", globalFlags.PrintAppAnnotation, body)
}
os.Exit(globalFlags.ExitCode)
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:101,代码来源:inspect.go
示例7: TestNetDefaultPortFwdConnectivity
/*
* Default net port forwarding connectivity
* ---
* Container launches http server on all its interfaces
* Host must be able to connect to container's http server on it's own interfaces
*/
func TestNetDefaultPortFwdConnectivity(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
bannedPorts := make(map[int]struct{}, 0)
f := func(httpGetIP string, rktArg string, shouldSucceed bool) {
httpPort, err := testutils.GetNextFreePort4Banned(bannedPorts)
if err != nil {
t.Fatalf("%v", err)
}
bannedPorts[httpPort] = struct{}{}
httpServeAddr := fmt.Sprintf("0.0.0.0:%d", httpPort)
testImageArgs := []string{
fmt.Sprintf("--ports=http,protocol=tcp,port=%d", httpPort),
fmt.Sprintf("--exec=/inspect --serve-http=%v", httpServeAddr),
}
testImage := patchTestACI("rkt-inspect-networking.aci", testImageArgs...)
defer os.Remove(testImage)
cmd := fmt.Sprintf(
"%s --debug --insecure-options=image run --port=http:%d %s --mds-register=false %s",
ctx.Cmd(), httpPort, rktArg, testImage)
child := spawnOrFail(t, cmd)
httpGetAddr := fmt.Sprintf("http://%v:%v", httpGetIP, httpPort)
ga := testutils.NewGoroutineAssistant(t)
ga.Add(2)
// Child opens the server
go func() {
defer ga.Done()
ga.WaitOrFail(child)
}()
// Host connects to the child via the forward port on localhost
go func() {
defer ga.Done()
expectedRegex := `serving on`
_, out, err := expectRegexWithOutput(child, expectedRegex)
if err != nil {
ga.Fatalf("Error: %v\nOutput: %v", err, out)
}
body, err := testutils.HTTPGet(httpGetAddr)
switch {
case err != nil && shouldSucceed:
ga.Fatalf("%v\n", err)
case err == nil && !shouldSucceed:
ga.Fatalf("HTTP-Get to %q should have failed! But received %q", httpGetAddr, body)
case err != nil && !shouldSucceed:
child.Close()
fallthrough
default:
t.Logf("HTTP-Get received: %s", body)
}
}()
ga.Wait()
}
f("172.16.28.1", "--net=default", true)
f("127.0.0.1", "--net=default", true)
// TODO: ensure that default-restricted is not accessible from non-host
// f("172.16.28.1", "--net=default-restricted", true)
// f("127.0.0.1", "--net=default-restricted", true)
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:73,代码来源:rkt_net_test.go
注:本文中的github.com/coreos/rkt/tests/testutils.HTTPGet函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论