forked from tilt-dev/tilt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource_test.go
58 lines (51 loc) · 1.3 KB
/
resource_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
56
57
58
package k8s
import (
"context"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"helm.sh/helm/v3/pkg/kube"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// This tests a race condition where if there were two Build()s
// happening in parallel, they would overwrite each other's configs
// due to a race condition.
func TestRESTClientBuilder(t *testing.T) {
config := &rest.Config{}
loader, err := clientcmd.NewClientConfigFromBytes(nil)
require.NoError(t, err)
client := &K8sClient{
restConfig: config,
clientLoader: loader,
drm: fakeRESTMapper{},
}
rClient := newResourceClient(client)
g, _ := errgroup.WithContext(context.Background())
var list1, list2 kube.ResourceList
g.Go(func() error {
var err error
list1, err = rClient.Build(strings.NewReader(`
apiVersion: v1
kind: Pod
metadata:
name: fe
`), false)
return err
})
g.Go(func() error {
var err error
list2, err = rClient.Build(strings.NewReader(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: fe
`), false)
return err
})
require.NoError(t, g.Wait())
assert.Equal(t, "v1", list1[0].Client.(*rest.RESTClient).APIVersion().String())
assert.Equal(t, "apps/v1", list2[0].Client.(*rest.RESTClient).APIVersion().String())
}