-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add consistent snippets for network creation
- Loading branch information
1 parent
81007d6
commit 67e4b4d
Showing
3 changed files
with
88 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package network_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
dockernetwork "github.com/docker/docker/api/types/network" | ||
Check failure on line 8 in network/examples_test.go GitHub Actions / test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x
Check failure on line 8 in network/examples_test.go GitHub Actions / test (1.21.x, ubuntu-latest) / ./ubuntu-latest/1.21.x
Check failure on line 8 in network/examples_test.go GitHub Actions / Test with reaper off (1.x) / ./ubuntu-latest/1.x
Check failure on line 8 in network/examples_test.go GitHub Actions / Test with reaper off (1.21.x) / ./ubuntu-latest/1.21.x
Check failure on line 8 in network/examples_test.go GitHub Actions / Test with Rootless Docker (1.21.x, ubuntu-latest) / ./ubuntu-latest/1.21.x
|
||
"github.com/testcontainers/testcontainers-go/network" | ||
) | ||
|
||
func ExampleNew() { | ||
// createNetwork { | ||
ctx := context.Background() | ||
|
||
net, err := network.New(ctx) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
defer func() { | ||
if err := net.Remove(ctx); err != nil { | ||
log.Fatalf("failed to remove network: %s", err) | ||
} | ||
}() | ||
// } | ||
|
||
fmt.Println(net.ID != "") | ||
fmt.Println(net.Driver) | ||
|
||
// Output: | ||
// true | ||
// bridge | ||
} | ||
|
||
func ExampleNew_withOptions() { | ||
// newNetworkWithOptions { | ||
ctx := context.Background() | ||
|
||
// dockernetwork is the alias used for github.com/docker/docker/api/types/network | ||
ipamConfig := dockernetwork.IPAM{ | ||
Driver: "default", | ||
Config: []dockernetwork.IPAMConfig{ | ||
{ | ||
Subnet: "10.1.1.0/24", | ||
Gateway: "10.1.1.254", | ||
}, | ||
}, | ||
Options: map[string]string{ | ||
"driver": "host-local", | ||
}, | ||
} | ||
net, err := network.New(ctx, | ||
network.WithIPAM(&ipamConfig), | ||
network.WithAttachable(), | ||
network.WithDriver("bridge"), | ||
) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
defer func() { | ||
if err := net.Remove(ctx); err != nil { | ||
log.Fatalf("failed to remove network: %s", err) | ||
} | ||
}() | ||
// } | ||
|
||
fmt.Println(net.ID != "") | ||
fmt.Println(net.Driver) | ||
|
||
// Output: | ||
// true | ||
// bridge | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters