diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c928f6a..8122482 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,11 @@ jobs: # - name: Run golint # run: golint ./... - - name: Test - run: go test -v ./... - - # - name: Test - # run: go test -v -tags=integration ./... \ No newline at end of file + - 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" \ No newline at end of file diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 0000000..1129b27 --- /dev/null +++ b/.github/workflows/integration.yml @@ -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 diff --git a/go.mod b/go.mod index 654f56b..9c6c301 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/hcn/hcnloadbalancer_test.go b/hcn/hcnloadbalancer_test.go index 432b2cf..0c6fc5d 100644 --- a/hcn/hcnloadbalancer_test.go +++ b/hcn/hcnloadbalancer_test.go @@ -1,6 +1,8 @@ //go:build windows && integration // +build windows,integration +// TODO: https://github.com/microsoft/hnslib/issues/19 + package hcn import ( diff --git a/hcn/hcnnetwork_integration_test.go b/hcn/hcnnetwork_integration_test.go new file mode 100644 index 0000000..3bec4b4 --- /dev/null +++ b/hcn/hcnnetwork_integration_test.go @@ -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") + } +}