Skip to content

Commit

Permalink
add JSON tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Jan 10, 2025
1 parent 6813f1f commit 0fabaa3
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/e2e/load_balancer_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
package e2e

import (
"context"
"encoding/json"
"testing"

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)

func TestLoadBalancerType(t *testing.T) {
Expand All @@ -33,9 +37,18 @@ func TestLoadBalancerType(t *testing.T) {
})

t.Run("json", func(t *testing.T) {
var schemas []schema.LoadBalancerType
lbts, err := client.LoadBalancerType.All(context.Background())
require.NoError(t, err)
for _, lbt := range lbts {
schemas = append(schemas, hcloud.SchemaFromLoadBalancerType(lbt))
}
expectedJson, err := json.Marshal(schemas)
require.NoError(t, err)

out, err := runCommand(t, "load-balancer-type", "list", "-o=json")
require.NoError(t, err)
assert.True(t, json.Valid([]byte(out)), "is valid JSON")
assert.JSONEq(t, string(expectedJson), out)
})
})

Expand Down Expand Up @@ -71,5 +84,16 @@ func TestLoadBalancerType(t *testing.T) {
out,
)
})

t.Run("json", func(t *testing.T) {
lbt, _, err := client.LoadBalancerType.GetByName(context.Background(), TestLoadBalancerTypeName)
require.NoError(t, err)
expectedJson, err := json.Marshal(hcloud.SchemaFromLoadBalancerType(lbt))
require.NoError(t, err)

out, err := runCommand(t, "load-balancer-type", "describe", TestLoadBalancerTypeName, "-o=json")
require.NoError(t, err)
assert.JSONEq(t, string(expectedJson), out)
})
})
}

0 comments on commit 0fabaa3

Please sign in to comment.