Skip to content

Instantly share code, notes, and snippets.

@pweil-
Last active July 31, 2020 20:41
Show Gist options
  • Save pweil-/f39563f211b76d4761646d72a56d4f1b to your computer and use it in GitHub Desktop.
Save pweil-/f39563f211b76d4761646d72a56d4f1b to your computer and use it in GitHub Desktop.
package e2e
import (
"context"
deploy "github.com/kube-reporting/metering-operator/pkg/deploy"
"github.com/kube-reporting/metering-operator/test/deployframework"
v1 "k8s.io/api/core/v1"
"k8s.io/api/storage/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)
func TestFoo(t *testing.T) {
var ctx *deployframework.DeployerCtx
type fixtures struct {
files map[string]string
pod *v1.Pod
service *v1.Service
storageClass *v1beta1.StorageClass
}
foo := fixtures{
files: map[string]string{
"pod": "/test/testhelpers/nfs_server.yaml",
"service": "/test/testhelpers/nfs_service.yaml",
"storageClass": "/test/testhelpers/nfs_storageclass.yaml",
},
pod: &v1.Pod{},
service: &v1.Service{},
storageClass: &v1beta1.StorageClass{},
}
for name, file := range foo.files {
switch name {
case "pod":
if err := deploy.DecodeYAMLManifestToObject(file, foo.pod); err != nil {
t.Log("got an error")
}
ctx.Client.CoreV1().Pods("ns").Create(context.TODO(), foo.pod, metav1.GetOptions{})
case "service":
if err := deploy.DecodeYAMLManifestToObject(file, foo.service); err != nil {
t.Log("got an error")
}
ctx.Client.CoreV1().Services("ns").Create(context.TODO(), foo.service, metav1.GetOptions{})
// get the IP
case "storageClass":
if err := deploy.DecodeYAMLManifestToObject(file, foo.storageClass); err != nil {
t.Log("got an error")
}
//create the storage class
}
}
}
func TestFoo2(t *testing.T) {
var ctx *deployframework.DeployerCtx
files := map[string]string{
"pod": "/test/testhelpers/nfs_server.yaml",
"service": "/test/testhelpers/nfs_service.yaml",
"storageClass": "/test/testhelpers/nfs_storageclass.yaml",
"theFourthThing": "",
}
pod := &v1.Pod{}
service := &v1.Service{}
storageClass := &v1beta1.StorageClass{}
// looping through, ignoring theFourthThing for now
for name, file := range files {
switch name {
case "pod":
if err := deploy.DecodeYAMLManifestToObject(file, pod); err != nil {
t.Log("got an error")
}
ctx.Client.CoreV1().Pods("ns").Create(context.TODO(), pod, metav1.GetOptions{})
case "service":
if err := deploy.DecodeYAMLManifestToObject(file, service); err != nil {
t.Log("got an error")
}
ctx.Client.CoreV1().Services("ns").Create(context.TODO(), service, metav1.GetOptions{})
// could get the IP here or you could get it just before you create theFourthThing below
case "storageClass":
if err := deploy.DecodeYAMLManifestToObject(file, storageClass); err != nil {
t.Log("got an error")
}
//create the storage class
}
}
// decode and create theFourthThing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment