mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
88 lines
1.9 KiB
Go
88 lines
1.9 KiB
Go
/*
|
|
Copyright 2019 The Kubernetes 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 plugins_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"sigs.k8s.io/kustomize/internal/loadertest"
|
|
"sigs.k8s.io/kustomize/internal/plugintest"
|
|
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
|
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
"sigs.k8s.io/kustomize/pkg/plugins"
|
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
|
"sigs.k8s.io/kustomize/pkg/resource"
|
|
)
|
|
|
|
const (
|
|
secretGenerator = `
|
|
apiVersion: builtin
|
|
kind: SecretGenerator
|
|
metadata:
|
|
name: secretGenerator
|
|
name: mySecret
|
|
behavior: merge
|
|
envFiles:
|
|
- a.env
|
|
- b.env
|
|
valueFiles:
|
|
- longsecret.txt
|
|
literals:
|
|
- FRUIT=apple
|
|
- VEGETABLE=carrot
|
|
`
|
|
serviceGenerator = `
|
|
apiVersion: someteam.example.com/v1
|
|
kind: ServiceGenerator
|
|
metadata:
|
|
name: myServiceGenerator
|
|
service: my-service
|
|
port: "12345"
|
|
`
|
|
)
|
|
|
|
func TestLoader(t *testing.T) {
|
|
tc := plugintest_test.NewPluginTestEnv(t).Set()
|
|
defer tc.Reset()
|
|
|
|
tc.BuildGoPlugin(
|
|
"builtin", "", "SecretGenerator")
|
|
tc.BuildGoPlugin(
|
|
"someteam.example.com", "v1", "ServiceGenerator")
|
|
|
|
rmF := resmap.NewFactory(resource.NewFactory(
|
|
kunstruct.NewKunstructuredFactoryImpl()))
|
|
|
|
l := plugins.NewLoader(plugin.ActivePluginConfig(), rmF)
|
|
if l == nil {
|
|
t.Fatal("expect non-nil loader")
|
|
}
|
|
|
|
ldr := loadertest.NewFakeLoader("/foo")
|
|
|
|
m, err := rmF.NewResMapFromBytes([]byte(
|
|
serviceGenerator + "---\n" + secretGenerator))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, err = l.LoadGenerators(ldr, m)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|