Skip to content

Commit

Permalink
Remove template function test to make bazel happy
Browse files Browse the repository at this point in the history
This test is sort of redundant when we have integration tests etc covering rendering of these templates
  • Loading branch information
Ole Markus With committed Sep 15, 2020
1 parent b8bc6d3 commit e5a3693
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 97 deletions.
25 changes: 0 additions & 25 deletions upup/models/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

1 change: 0 additions & 1 deletion upup/pkg/fi/cloudup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ go_test(
],
data = [
"//upup/pkg/fi/cloudup/tests:exported_testdata", # keep
"//upup/models/cloudup/resources/addons/openstack.addons.k8s.io:exported_testdata", # keep
],
embed = [":go_default_library"],
deps = [
Expand Down
66 changes: 0 additions & 66 deletions upup/pkg/fi/cloudup/template_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ limitations under the License.
package cloudup

import (
"bytes"
"fmt"
"io/ioutil"
"path/filepath"
"reflect"
"strings"
"testing"
"text/template"

"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
Expand Down Expand Up @@ -212,64 +207,3 @@ func Test_TemplateFunctions_CloudControllerConfigArgv(t *testing.T) {
})
}
}

func Test_executeTemplate(t *testing.T) {
tests := []struct {
desc string
cluster *kops.Cluster
templateFilename string
expectedManifestPath string
}{
{
desc: "test cloud controller template",
cluster: &kops.Cluster{Spec: kops.ClusterSpec{
CloudProvider: string(kops.CloudProviderOpenstack),
ExternalCloudControllerManager: &kops.CloudControllerManagerConfig{
ClusterName: "k8s",
Image: "docker.io/k8scloudprovider/openstack-cloud-controller-manager:1.13",
},
},
},
templateFilename: "../../../models/cloudup/resources/addons/openstack.addons.k8s.io/k8s-1.13.yaml.template",
expectedManifestPath: "./tests/manifests/k8s-1.13.yaml",
},
}

for _, testCase := range tests {
t.Run(testCase.desc, func(t *testing.T) {
templateFileAbsolutePath, filePathError := filepath.Abs(testCase.templateFilename)
if filePathError != nil {
t.Fatalf("error getting path to template: %v", filePathError)
}

tpl := template.New(filepath.Base(templateFileAbsolutePath))

funcMap := make(template.FuncMap)
templateFunctions := TemplateFunctions{}
templateFunctions.Cluster = testCase.cluster
templateFunctions.AddTo(funcMap, nil)

tpl.Funcs(funcMap)

tpl.Option("missingkey=zero")
_, err := tpl.ParseFiles(templateFileAbsolutePath)
if err != nil {
t.Fatalf("error parsing template %q: %v", "template", err)
}
var buffer bytes.Buffer
err = tpl.Execute(&buffer, testCase.cluster.Spec)
if err != nil {
t.Fatalf("error executing template %q: %v", "template", err)
}
actualManifest := buffer.Bytes()
expectedFileAbsolutePath, _ := filepath.Abs(testCase.expectedManifestPath)
expectedManifest, _ := ioutil.ReadFile(expectedFileAbsolutePath)

actualString := strings.TrimSpace(string(actualManifest))
expectedString := strings.TrimSpace(string(expectedManifest))
if !reflect.DeepEqual(actualString, expectedString) {
t.Fatalf("Manifests differs: %+v instead of %+v", actualString, expectedString)
}
})
}
}

0 comments on commit e5a3693

Please sign in to comment.