@@ -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"
@@ -1953,9 +1954,37 @@ var _ = Describe("Fake client", func() {
1953
1954
})
1954
1955
}
1955
1956
1956
- It ("should error when creating an eviction with the wrong type" , func () {
1957
+ It ("should create a ServiceAccount token through the token subresource" , func () {
1958
+ sa := & corev1.ServiceAccount {ObjectMeta : metav1.ObjectMeta {Name : "foo" }}
1959
+ cl := NewClientBuilder ().WithObjects (sa ).Build ()
1960
+
1961
+ tokenRequest := & authenticationv1.TokenRequest {}
1962
+ err := cl .SubResource ("token" ).Create (context .Background (), sa , tokenRequest )
1963
+ Expect (err ).NotTo (HaveOccurred ())
1964
+
1965
+ Expect (tokenRequest .Status .Token ).NotTo (Equal ("" ))
1966
+ Expect (tokenRequest .Status .ExpirationTimestamp ).NotTo (Equal (metav1.Time {}))
1967
+ })
1968
+
1969
+ It ("should return not found when creating a token for a ServiceAccount that doesn't exist" , func () {
1970
+ sa := & corev1.ServiceAccount {ObjectMeta : metav1.ObjectMeta {Name : "foo" }}
1971
+ cl := NewClientBuilder ().Build ()
1972
+
1973
+ tokenRequest := & authenticationv1.TokenRequest {}
1974
+ err := cl .SubResource ("token" ).Create (context .Background (), sa , tokenRequest )
1975
+ Expect (err ).To (HaveOccurred ())
1976
+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1977
+ })
1978
+
1979
+ It ("should error when creating a token with the wrong subresource type" , func () {
1980
+ cl := NewClientBuilder ().Build ()
1981
+ err := cl .SubResource ("token" ).Create (context .Background (), & corev1.ServiceAccount {}, & corev1.Namespace {})
1982
+ Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
1983
+ })
1984
+
1985
+ It ("should error when creating a token with the wrong type" , func () {
1957
1986
cl := NewClientBuilder ().Build ()
1958
- err := cl .SubResource ("eviction " ).Create (context .Background (), & corev1.Pod {}, & corev1.Namespace {})
1987
+ err := cl .SubResource ("token " ).Create (context .Background (), & corev1.Secret {}, & corev1.Namespace {})
1959
1988
Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
1960
1989
})
1961
1990
0 commit comments