forked from rook/rook
Avoid using global values that are not used anywhere in the code. Split the object used to express the ceph csi templates into two so only values that are set globally need to be managed globally, all other values can be stored in the temporary local struct. Signed-off-by: John Mulligan <jmulligan@redhat.com>
117 lines
2.5 KiB
Go
117 lines
2.5 KiB
Go
/*
|
|
Copyright 2019 The Rook Authors. All rights reserved.
|
|
|
|
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 csi
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var (
|
|
testDSTemplate = []byte(`
|
|
kind: DaemonSet
|
|
apiVersion: apps/v1
|
|
metadata:
|
|
name: test-label
|
|
namespace: {{ .Namespace }}
|
|
spec:
|
|
selector:
|
|
matchLabels:
|
|
app: test-label
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: test-label
|
|
spec:
|
|
serviceAccount: test-sa
|
|
containers:
|
|
- name: registrar
|
|
image: {{ .RegistrarImage }}
|
|
- name: rbdplugin
|
|
image: {{ .CSIPluginImage }}
|
|
- name: cephfsplugin
|
|
image: {{ .CSIPluginImage }}
|
|
`)
|
|
testSSTemplate = []byte(`
|
|
kind: StatefulSet
|
|
apiVersion: apps/v1
|
|
metadata:
|
|
name: test-label
|
|
namespace: {{ .Namespace }}
|
|
spec:
|
|
selector:
|
|
matchLabels:
|
|
app: test-label
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: test-label
|
|
spec:
|
|
serviceAccount: test-sa
|
|
containers:
|
|
- name: csi-rbdplugin-attacher
|
|
image: {{ .AttacherImage }}
|
|
- name: provisioner
|
|
image: {{ .ProvisionerImage }}
|
|
- name: rbdplugin
|
|
image: {{ .CSIPluginImage }}
|
|
- name: cephfsplugin
|
|
image: {{ .CSIPluginImage }}
|
|
`)
|
|
)
|
|
|
|
func TestDaemonSetTemplate(t *testing.T) {
|
|
tmp, err := ioutil.TempFile("", "yaml")
|
|
assert.Nil(t, err)
|
|
|
|
defer os.Remove(tmp.Name())
|
|
|
|
_, err = tmp.Write(testDSTemplate)
|
|
assert.Nil(t, err)
|
|
err = tmp.Close()
|
|
assert.Nil(t, err)
|
|
|
|
tp := templateParam{
|
|
Param: CSIParam,
|
|
Namespace: "foo",
|
|
}
|
|
_, err = templateToDaemonSet("test-ds", tmp.Name(), tp)
|
|
assert.Nil(t, err)
|
|
}
|
|
|
|
func TestStatefulSetTemplate(t *testing.T) {
|
|
tmp, err := ioutil.TempFile("", "yaml")
|
|
assert.Nil(t, err)
|
|
|
|
defer os.Remove(tmp.Name())
|
|
|
|
_, err = tmp.Write(testSSTemplate)
|
|
assert.Nil(t, err)
|
|
err = tmp.Close()
|
|
assert.Nil(t, err)
|
|
|
|
tp := templateParam{
|
|
Param: CSIParam,
|
|
Namespace: "foo",
|
|
}
|
|
_, err = templateToStatefulSet("test-ss", tmp.Name(), tp)
|
|
assert.Nil(t, err)
|
|
}
|