@@ -27,6 +27,7 @@ import (
27
27
. "github.com/onsi/ginkgo/v2"
28
28
. "github.com/onsi/gomega"
29
29
appsv1 "k8s.io/api/apps/v1"
30
+ authenticationv1 "k8s.io/api/authentication/v1"
30
31
autoscalingv1 "k8s.io/api/autoscaling/v1"
31
32
coordinationv1 "k8s.io/api/coordination/v1"
32
33
corev1 "k8s.io/api/core/v1"
@@ -1959,6 +1960,42 @@ var _ = Describe("Fake client", func() {
1959
1960
Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
1960
1961
})
1961
1962
1963
+ It ("should create a ServiceAccount token through the token subresource" , func () {
1964
+ sa := & corev1.ServiceAccount {ObjectMeta : metav1.ObjectMeta {Name : "foo" }}
1965
+ cl := NewClientBuilder ().WithObjects (sa ).Build ()
1966
+
1967
+ tokenRequest := & authenticationv1.TokenRequest {}
1968
+ err := cl .SubResource ("token" ).Create (context .Background (), sa , tokenRequest )
1969
+ Expect (err ).NotTo (HaveOccurred ())
1970
+
1971
+ Expect (tokenRequest .Status .Token ).NotTo (Equal ("" ))
1972
+ Expect (tokenRequest .Status .ExpirationTimestamp ).NotTo (Equal (metav1.Time {}))
1973
+ })
1974
+
1975
+ It ("should return not found when creating a token for a ServiceAccount that doesn't exist" , func () {
1976
+ sa := & corev1.ServiceAccount {ObjectMeta : metav1.ObjectMeta {Name : "foo" }}
1977
+ cl := NewClientBuilder ().Build ()
1978
+
1979
+ tokenRequest := & authenticationv1.TokenRequest {}
1980
+ err := cl .SubResource ("token" ).Create (context .Background (), sa , tokenRequest )
1981
+ Expect (err ).To (HaveOccurred ())
1982
+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1983
+ })
1984
+
1985
+
1986
+
1987
+ It ("should error when creating a token with the wrong subresource type" , func () {
1988
+ cl := NewClientBuilder ().Build ()
1989
+ err := cl .SubResource ("token" ).Create (context .Background (), & corev1.ServiceAccount {}, & corev1.Namespace {})
1990
+ Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
1991
+ })
1992
+
1993
+ It ("should error when creating a token with the wrong type" , func () {
1994
+ cl := NewClientBuilder ().Build ()
1995
+ err := cl .SubResource ("token" ).Create (context .Background (), & corev1.Secret {}, & corev1.Namespace {})
1996
+ Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
1997
+ })
1998
+
1962
1999
It ("should leave typemeta empty on typed get" , func () {
1963
2000
cl := NewClientBuilder ().WithObjects (& corev1.Pod {ObjectMeta : metav1.ObjectMeta {
1964
2001
Namespace : "default" ,
0 commit comments