Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ jobs:
# - name: Run golint
# run: golint ./...

- name: Test
run: go test -v ./...

# - name: Test
# run: go test -v -tags=integration ./...
- name: Test
run: go test -v ./...

- name: Test HNS Loadbalancer Integration
run: go test -v -tags=integration ./hcn -run="TestCreateDeleteLoadBalancer|TestGetLoadBalancerById|TestListLoadBalancer|TestAddLoadBalancer"

- name: Test HNS Loadbalancer Advanced Features
run: go test -v -tags=integration ./hcn -run="TestAddDSRLoadBalancer|TestAddILBLoadBalancer|TestLoadBalancerAddRemoveEndpoint"
22 changes: 22 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Windows HNS Integration Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
integration:
runs-on: windows-2022
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Run integration tests
run: |
go test -v -tags=integration ./hcn
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ require (

require github.com/stretchr/testify v1.9.0 // indirect

retract (
v0.0.15 // Retract v0.0.15 because it's not a valid version
)
retract v0.0.15 // Retract v0.0.15 because it's not a valid version
2 changes: 2 additions & 0 deletions hcn/hcnloadbalancer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:build windows && integration
// +build windows,integration

// TODO: https://github.com/microsoft/hnslib/issues/19

package hcn

import (
Expand Down
72 changes: 72 additions & 0 deletions hcn/hcnnetwork_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//go:build windows && integration
// +build windows,integration

package hcn

import (
"testing"
"time"
)

func cleanNetworks() {
// This function can be used to clean up any networks created during tests.
networks, err := ListNetworks()
if err != nil {
return
}
for _, network := range networks {
network.Delete()
}
}

func TestIntegration_CreateAndDeleteNetwork(t *testing.T) {
cleanNetworks()
networkName := "integration-test-network"
network := &HostComputeNetwork{
Type: NAT,
Name: networkName,
Ipams: []Ipam{{
Type: "Static",
Subnets: []Subnet{{
IpAddressPrefix: "192.168.250.0/24",
Routes: []Route{{
NextHop: "192.168.250.1",
DestinationPrefix: "0.0.0.0/0",
}},
}},
}},
SchemaVersion: SchemaVersion{Major: 2, Minor: 0},
}

// Create network
created, err := network.Create()
if err != nil {
t.Fatalf("Failed to create network: %v", err)
}
if created == nil {
t.Fatal("Create() returned nil network")
}

// Verify network exists
found, err := GetNetworkByID(created.Id)
if err != nil {
t.Fatalf("Failed to get network by ID: %v", err)
}
if found == nil || found.Name != networkName {
t.Fatalf("Network not found after creation")
}

// Delete network
if err := created.Delete(); err != nil {
t.Fatalf("Failed to delete network: %v", err)
}

// Give HNS a moment to update
time.Sleep(2 * time.Second)

// Verify network is gone
_, err = GetNetworkByID(created.Id)
if err == nil {
t.Fatalf("Network still exists after deletion")
}
}