Skip to content

Commit

Permalink
🔧 Annotation test + duplicate chartInfo
Browse files Browse the repository at this point in the history
Signed-off-by: afreyermuth98 <[email protected]>
  • Loading branch information
afreyermuth98 committed Sep 23, 2024
1 parent 741f7c2 commit 63549f4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
34 changes: 34 additions & 0 deletions charts/falco/tests/unit/chartInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 (
"testing"

"github.com/gruntwork-io/terratest/modules/helm"
"gopkg.in/yaml.v3"
)

func chartInfo(t *testing.T, chartPath string) (map[string]interface{}, error) {
// Get chart info.
output, err := helm.RunHelmCommandAndGetOutputE(t, &helm.Options{}, "show", "chart", chartPath)
if err != nil {
return nil, err
}
chartInfo := map[string]interface{}{}
err = yaml.Unmarshal([]byte(output), &chartInfo)
return chartInfo, err
}
31 changes: 29 additions & 2 deletions charts/falco/tests/unit/serviceTemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package unit

import (
"encoding/json"
"fmt"
"path/filepath"
"reflect"
"testing"

"github.com/gruntwork-io/terratest/modules/helm"
Expand Down Expand Up @@ -130,4 +129,32 @@ func (s *serviceTemplateTest) TestCustomLabelsValues() {
s.Equal(expectedVal, value)
}
s.Equal("falco-label", labels["custom-label"])
}


func (s *serviceTemplateTest) TestCustomAnnotationsValues() {
// Render the service and check that it has not been rendered.
options := &helm.Options{SetValues: map[string]string{"metrics.service.annotations" : {"custom-annotation": "falco-annotation"}}}
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())


cInfo, err := chartInfo(s.T(), s.chartPath)
s.NoError(err)
// Get app version.
appVersion, found := cInfo["appVersion"]
s.True(found, "should find app version in chart info")
appVersion = appVersion.(string)
// Get chart version.
chartVersion, found := cInfo["version"]
s.True(found, "should find chart version in chart info")
// Get chart name.
chartName, found := cInfo["name"]
s.True(found, "should find chart name in chart info")
chartName = chartName.(string)
var svc corev1.Service
helm.UnmarshalK8SYaml(s.T(), output, &svc)
annotations := svc.GetAnnotations()
s.Equal("falco-annotation", annotations["custom-annotation"])
}

0 comments on commit 63549f4

Please sign in to comment.