From 939a2e1b65f4d60899f65ae2842fee70aace36e4 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Mon, 25 Apr 2022 09:49:18 +0000 Subject: [PATCH] Add test for common.Replicas function --- install/installer/pkg/common/render_test.go | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/install/installer/pkg/common/render_test.go b/install/installer/pkg/common/render_test.go index 2dcf60283d82bb..5b622431a1b401 100644 --- a/install/installer/pkg/common/render_test.go +++ b/install/installer/pkg/common/render_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/gitpod-io/gitpod/installer/pkg/config/v1" + "github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental" "github.com/gitpod-io/gitpod/installer/pkg/config/versions" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" @@ -28,6 +29,46 @@ func TestCompositeRenderFunc_NilObjectsNilError(t *testing.T) { require.Len(t, objects, 0) } +func TestReplicas(t *testing.T) { + testCases := []struct { + Component string + ExpectedReplicas int32 + }{ + { + Component: "server", + ExpectedReplicas: 123, + }, + { + Component: "dashboard", + ExpectedReplicas: 456, + }, + { + Component: "content-service", + ExpectedReplicas: 1, + }, + } + ctx, err := NewRenderContext(config.Config{ + Experimental: &experimental.Config{ + Common: &experimental.CommonConfig{ + PodConfig: map[string]*experimental.PodConfig{ + "server": {Replicas: pointer.Int32(123)}, + "dashboard": {Replicas: pointer.Int32(456)}, + }, + }, + }, + }, versions.Manifest{}, "test_namespace") + require.NoError(t, err) + + for _, testCase := range testCases { + actualReplicas := Replicas(ctx, testCase.Component) + + if *actualReplicas != testCase.ExpectedReplicas { + t.Errorf("expected %d replicas for %q component, but got %d", + testCase.ExpectedReplicas, testCase.Component, *actualReplicas) + } + } +} + func TestRepoName(t *testing.T) { type Expectation struct { Result string