Skip to content

Commit

Permalink
🔧 Working on tests
Browse files Browse the repository at this point in the history
Signed-off-by: afreyermuth98 <[email protected]>
  • Loading branch information
afreyermuth98 committed Sep 13, 2024
1 parent d4dc38c commit ab43d47
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions charts/falco/tests/unit/serviceTemplate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 The Falco Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package unit

import (
"encoding/json"

Check failure on line 19 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

"encoding/json" imported and not used
"path/filepath"
"reflect"

Check failure on line 21 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

"reflect" imported and not used
"testing"

"github.com/gruntwork-io/terratest/modules/helm"
corev1 "k8s.io/api/core/v1"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

type serviceTemplateTest struct {
suite.Suite
chartPath string
releaseName string
namespace string
templates []string
}

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

chartFullPath, err := filepath.Abs(chartPath)
require.NoError(t, err)

suite.Run(t, &serviceTemplateTest{
Suite: suite.Suite{},
chartPath: chartFullPath,
releaseName: "falco-test",
namespace: "falco-namespace-test",
templates: []string{"templates/service.yaml"},
})
}

func (s *serviceTemplateTest) TestCreationDefaultValues() {
// Render the service and check that it has not been rendered.
_, err := helm.RenderTemplateE(s.T(), &helm.Options{}, s.chartPath, s.releaseName, s.templates)
s.Error(err, "should error")
s.Equal("error while running command: exit status 1; Error: could not find template templates/service.yaml in chart", err.Error())
}


func (s *serviceTemplateTest) TestDefaultLabelsValues() {
// Render the service and check that it has not been rendered.
output, err := helm.RenderTemplateE(s.T(), &helm.Options{}, s.chartPath, s.releaseName, s.templates)
s.Error(err, "should error")
s.Equal("error while running command: exit status 1; Error: could not find template templates/service.yaml in chart", err.Error())

var svc corev1.Service
helm.UnmarshalK8SYaml(s.T(), output, &svc)
s.Equal("falco", svc.Metadata.Labels["app.kubernetes.io/name"])

Check failure on line 69 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

svc.Metadata undefined (type "k8s.io/api/core/v1".Service has no field or method Metadata)
s.Equal("Helm", svc.Metadata.Labels["app.kubernetes.io/managed-by"])

Check failure on line 70 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

svc.Metadata undefined (type "k8s.io/api/core/v1".Service has no field or method Metadata)
s.Equal("0.38.2", svc.Metadata.Labels["app.kubernetes.io/version"])

Check failure on line 71 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

svc.Metadata undefined (type "k8s.io/api/core/v1".Service has no field or method Metadata)
s.Equal("falco-4.8.1", svc.Metadata.Labels["helm.sh/chart"])

Check failure on line 72 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

svc.Metadata undefined (type "k8s.io/api/core/v1".Service has no field or method Metadata)
s.Equal("falco-metrics", svc.Metadata.Labels["type"])

Check failure on line 73 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

svc.Metadata undefined (type "k8s.io/api/core/v1".Service has no field or method Metadata)
}

0 comments on commit ab43d47

Please sign in to comment.