Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add Load Balancer Type e2e tests #954

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
75 changes: 75 additions & 0 deletions test/e2e/load_balancer_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//go:build e2e

package e2e

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestLoadBalancerType(t *testing.T) {
t.Parallel()

t.Run("list", func(t *testing.T) {
t.Run("table", func(t *testing.T) {
out, err := runCommand(t, "load-balancer-type", "list")
require.NoError(t, err)
assert.Regexp(t,
NewRegex().Start().
SeparatedByWhitespace("ID", "NAME", "DESCRIPTION", "MAX SERVICES", "MAX CONNECTIONS", "MAX TARGETS").Newline().
AnyTimes(NewRegex().
Int().Whitespace().
Identifier().Whitespace().
AnyString().Whitespace().
Int().Whitespace().
Int().Whitespace().
Int().Newline()).
End(),
out,
)
})

t.Run("json", func(t *testing.T) {
out, err := runCommand(t, "load-balancer-type", "list", "-o=json")
require.NoError(t, err)
assert.True(t, json.Valid([]byte(out)), "is valid JSON")
jooola marked this conversation as resolved.
Show resolved Hide resolved
})
})

t.Run("describe", func(t *testing.T) {
jooola marked this conversation as resolved.
Show resolved Hide resolved
t.Run("non-existing", func(t *testing.T) {
out, err := runCommand(t, "load-balancer-type", "describe", "non-existing")
require.EqualError(t, err, "Load Balancer Type not found: non-existing")
assert.Empty(t, out)
})

t.Run("normal", func(t *testing.T) {
out, err := runCommand(t, "load-balancer-type", "describe", TestLoadBalancerTypeName)
require.NoError(t, err)
assert.Regexp(t,
NewRegex().Start().
Lit("ID:").Whitespace().Int().Newline().
Lit("Name:").Whitespace().Identifier().Newline().
Lit("Description:").Whitespace().AnyString().Newline().
Lit("Max Services:").Whitespace().Int().Newline().
Lit("Max Connections:").Whitespace().Int().Newline().
Lit("Max Targets:").Whitespace().Int().Newline().
Lit("Max assigned Certificates:").Whitespace().Int().Newline().
Lit("Pricings per Location:").Newline().
AnyTimes(
NewRegex().
Lit(" - Location:").Whitespace().LocationName().Newline().
Lit(" Hourly:").Whitespace().Price().Newline().
Lit(" Monthly:").Whitespace().Price().Newline().
Lit(" Included Traffic:").Whitespace().IBytes().Newline().
Lit(" Additional Traffic:").Whitespace().Price().Lit(" per TB").Newline().
Newline(),
).End(),
out,
)
})
})
}
8 changes: 8 additions & 0 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func (r RegexBuilder) LocationName() RegexBuilder {
return r.Raw(`[a-z]{3}[0-9]*`)
}

func (r RegexBuilder) Price() RegexBuilder {
return r.Raw(`[€$] [0-9]+\.[0-9]+`)
}

func (r RegexBuilder) IBytes() RegexBuilder {
return r.Raw(`[0-9]+(?:\.[0-9]+)? (?:B|[KMGTPE]iB)`)
}

func (r RegexBuilder) CountryCode() RegexBuilder {
return r.Raw(`[A-Z]{2}`)
}
4 changes: 2 additions & 2 deletions test/e2e/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var (
// TestArchitecture is the default architecture used in end-to-end tests, should match the architecture of the TestServerType.
TestArchitecture = getEnv("TEST_ARCHITECTURE", string(hcloud.ArchitectureX86))

// TestLoadBalancerType is the default Load Balancer type used in end-to-end tests.
TestLoadBalancerType = "lb11"
// TestLoadBalancerTypeName is the default Load Balancer type used in end-to-end tests.
TestLoadBalancerTypeName = getEnv("TEST_LOAD_BALANCER_TYPE_NAME", "lb11")

// TestDatacenterName is the default datacenter name where we execute our end-to-end tests.
TestDatacenterName = getEnv("TEST_DATACENTER_NAME", "nbg1-dc3")
Expand Down
Loading