-
Notifications
You must be signed in to change notification settings - Fork 0
/
kube_gc_test.go
55 lines (46 loc) · 1.64 KB
/
kube_gc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package kubernetes_ctx_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
kubernetes_ctx "github.com/xunleii/godog-kubernetes"
)
func TestNaiveGC(t *testing.T) {
const (
rawService = `apiVersion: v1
kind: Service
metadata:
name: ownerService
namespace: default
spec:
clusterIP: None`
rawEndpoints = `apiVersion: v1
kind: Endpoints
metadata:
name: ownedEndpoints
namespace: default
ownerReferences:
- apiVersion: v1
kind: Service
name: ownerService
uid: %s`
)
ctx := initFakeScenarioWithNamespaces(t)
svc := yamlToUnstructured(t, rawService)
err := ctx.Create(svc.GroupVersionKind(), types.NamespacedName{Namespace: svc.GetNamespace(), Name: svc.GetName()}, svc)
require.NoError(t, err)
svc, err = ctx.Get(svc.GroupVersionKind(), types.NamespacedName{Namespace: svc.GetNamespace(), Name: svc.GetName()})
require.NoError(t, err)
endpoints := yamlToUnstructured(t, fmt.Sprintf(rawEndpoints, svc.GetUID()))
err = ctx.Create(endpoints.GroupVersionKind(), types.NamespacedName{Namespace: endpoints.GetNamespace(), Name: endpoints.GetName()}, endpoints)
require.NoError(t, err)
endpoints, err = ctx.Get(endpoints.GroupVersionKind(), types.NamespacedName{Namespace: endpoints.GetNamespace(), Name: endpoints.GetName()})
assert.False(t, errors.IsNotFound(err))
err = kubernetes_ctx.NaiveGC(ctx, svc)
require.NoError(t, err)
_, err = ctx.Get(endpoints.GroupVersionKind(), types.NamespacedName{Namespace: endpoints.GetNamespace(), Name: endpoints.GetName()})
assert.True(t, errors.IsNotFound(err))
}