Skip to content

Commit

Permalink
ci: add tests for hcloud provider
Browse files Browse the repository at this point in the history
* add terraform files for hcloud server setup
* add tests for public IPv4, IPv6, and private IPv4
* add test to check for location filter
* add circleci entry for hcloud provider

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
  • Loading branch information
Thunderbottom committed Nov 24, 2022
1 parent 032f476 commit cddebf3
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ jobs:
- acctest:
provider-test-infra-dir: gce
provider-go-test-dir: gce
hcloud-provider:
executor: go
steps:
- acctest:
provider-test-infra-dir: hcloud
provider-go-test-dir: hcloud
k8s-provider:
executor: go
steps:
Expand Down Expand Up @@ -237,6 +243,10 @@ workflows:
requires:
- go-test
filters: *ignore_prs
- hcloud-provider:
requires:
- go-test
filters: *ignore_prs
- k8s-provider:
requires:
- go-test
Expand Down
47 changes: 47 additions & 0 deletions provider/hcloud/hcloud_discover_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package hcloud_test

import (
"log"
"os"
"testing"

discover "github.com/hashicorp/go-discover"
"github.com/hashicorp/go-discover/provider/hcloud"
)

var _ discover.Provider = (*hcloud.Provider)(nil)
var addrTests = map[string]struct {
addrType string
location string
outLen int
}{
"public ipv4 all locations": {"public_v4", "", 2},
"public ipv6 all locations": {"public_v6", "", 2},
"private ipv4 all locations": {"private_v4", "", 2},
"private ipv4 fsn1 datacenter": {"private_v4", "fsn1", 1},
"public ipv6 nbg1 datacenter": {"public_v6", "nbg1", 1},
"public ipv4 hel1 datacenter": {"public_v4", "hel1", 0},
}

func TestAddrs(t *testing.T) {
l := log.New(os.Stderr, "", log.LstdFlags)
for name, at := range addrTests {
t.Run(name, func(t *testing.T) {
args := discover.Config{
"provider": "hcloud",
"label_selector": "go-discover-test-tag",
"address_type": at.addrType,
}
p := &hcloud.Provider{}
addrs, err := p.Addrs(args, l)

if err != nil {
t.Fatal(err)
}

if len(addrs) != at.outLen {
t.Fatalf("expected: %d, got: %d", at.outLen, len(addrs))
}
})
}
}
19 changes: 19 additions & 0 deletions test/tf/hcloud/input.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "prefix" {
default = "go-discover"
}

variable "hcloud_image" {
default = "ubuntu-20.04"
}

variable "hcloud_location_nbg" {
default = "nbg1"
}

variable "hcloud_location_fsn" {
default = "fsn1"
}

variable "hcloud_size" {
default = "cx11"
}
46 changes: 46 additions & 0 deletions test/tf/hcloud/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
provider "hcloud" {
}

resource "hcloud_server" "test-01" {
count = 2
image = var.hcloud_image
name = "${var.prefix}-01-${count.index + 1}"
server_type = var.hcloud_size
location = var.hcloud_location_nbg
labels = {
"${var.prefix}-test-tag" : ""
}
}

resource "hcloud_server" "test-02" {
image = var.hcloud_image
name = "${var.prefix}-02"
server_type = var.hcloud_size
location = var.hcloud_location_fsn
}

resource "hcloud_network" "internal" {
name = "${var.prefix}-internal"
ip_range = "10.0.0.0/8"
labels = {
"${var.prefix}-test-tag" : ""
}
}

resource "hcloud_network_subnet" "subnet" {
network_id = hcloud_network.internal.id
type = "cloud"
network_zone = "eu-central"
ip_range = "10.0.1.0/24"
}

resource "hcloud_server_network" "test-01" {
count = 2
server_id = hcloud_server.test-01[count.index].id
subnet_id = hcloud_network_subnet.subnet.id
}

resource "hcloud_server_network" "test-02" {
server_id = hcloud_server.test-02.id
subnet_id = hcloud_network_subnet.subnet.id
}
10 changes: 10 additions & 0 deletions test/tf/hcloud/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "1.24.1"
}
}

required_version = ">=0.12"
}

0 comments on commit cddebf3

Please sign in to comment.