60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
/*
|
|
Copyright 2020 The KubeSphere 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 v1alpha2
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/onsi/gomega"
|
|
"golang.org/x/net/context"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
)
|
|
|
|
func TestStorageGroupBinding(t *testing.T) {
|
|
key := types.NamespacedName{
|
|
Name: "foo",
|
|
}
|
|
created := &GroupBinding{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "foo",
|
|
},
|
|
GroupRef: GroupRef{Name: "bar"},
|
|
Users: []string{"user"},
|
|
}
|
|
g := gomega.NewGomegaWithT(t)
|
|
|
|
// Test Create
|
|
fetched := &GroupBinding{}
|
|
g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed())
|
|
|
|
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed())
|
|
g.Expect(fetched).To(gomega.Equal(created))
|
|
|
|
// Test Updating the Labels
|
|
updated := fetched.DeepCopy()
|
|
updated.Labels = map[string]string{"hello": "world"}
|
|
g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed())
|
|
|
|
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed())
|
|
g.Expect(fetched).To(gomega.Equal(updated))
|
|
|
|
// Test Delete
|
|
g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed())
|
|
g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed())
|
|
}
|