@@ -26,20 +26,21 @@ import (
2626
2727// Publish a key, retrieve it again and check listing of all keys.
2828func TestPublishListLookup (t * testing.T ) {
29+ ctx := context .Background ()
2930 cs := fake .NewSimpleClientset ()
30- kcl , err := NewK8sRepository (context . TODO () , cs , "default" )
31+ kcl , err := NewK8sRepository (ctx , cs , "default" )
3132 if err != nil {
3233 t .Fatal (err )
3334 }
3435 const id = "testdevice"
3536 const key = "testkey"
36- if err = kcl .PublishKey (context . TODO () , id , key ); err != nil {
37+ if err = kcl .PublishKey (ctx , id , key ); err != nil {
3738 t .Fatal (err )
3839 }
39- if _ , err = kcl .LookupKey (context . TODO () , id ); err != nil {
40+ if _ , err = kcl .LookupKey (ctx , id ); err != nil {
4041 t .Fatal (err )
4142 }
42- devices , err := kcl .ListAllDeviceIDs (context . TODO () )
43+ devices , err := kcl .ListAllDeviceIDs (ctx )
4344 if err != nil {
4445 t .Fatal (err )
4546 }
@@ -50,20 +51,21 @@ func TestPublishListLookup(t *testing.T) {
5051
5152// Publish a key and override it with another one.
5253func TestPublishKeyUpdate (t * testing.T ) {
54+ ctx := context .Background ()
5355 cs := fake .NewSimpleClientset ()
54- kcl , err := NewK8sRepository (context . TODO () , cs , "default" )
56+ kcl , err := NewK8sRepository (ctx , cs , "default" )
5557 if err != nil {
5658 t .Fatal (err )
5759 }
5860 const id = "testdevice"
5961 const key2 = "testkey2"
60- if err = kcl .PublishKey (context . TODO () , id , "testkey" ); err != nil {
62+ if err = kcl .PublishKey (ctx , id , "testkey" ); err != nil {
6163 t .Fatal (err )
6264 }
63- if err = kcl .PublishKey (context . TODO () , id , key2 ); err != nil {
65+ if err = kcl .PublishKey (ctx , id , key2 ); err != nil {
6466 t .Fatal (err )
6567 }
66- k , err := kcl .LookupKey (context . TODO () , id )
68+ k , err := kcl .LookupKey (ctx , id )
6769 if err != nil {
6870 t .Fatal (err )
6971 }
@@ -72,18 +74,43 @@ func TestPublishKeyUpdate(t *testing.T) {
7274 }
7375}
7476
75- // Test if Lookup returns an empty key string in case the configmap is not found.
7677func TestLookupDoesNotExist (t * testing.T ) {
78+ ctx := context .Background ()
7779 cs := fake .NewSimpleClientset ()
78- kcl , err := NewK8sRepository (context . TODO () , cs , "default" )
80+ kcl , err := NewK8sRepository (ctx , cs , "default" )
7981 if err != nil {
8082 t .Fatal (err )
8183 }
82- k , err := kcl .LookupKey (context . TODO () , "testdevice" )
84+ k , err := kcl .LookupKey (ctx , "testdevice" )
8385 if ! errors .Is (err , repository .ErrNotFound ) {
8486 t .Fatalf ("LookupKey produced wrong error: got %v, want %v" , err , repository .ErrNotFound )
8587 }
8688 if k != nil {
8789 t .Fatalf ("LookupKey(..) = %q, want nil" , k )
8890 }
8991}
92+
93+ func TestConfigure (t * testing.T ) {
94+ ctx := context .Background ()
95+ cs := fake .NewSimpleClientset ()
96+ kcl , err := NewK8sRepository (ctx , cs , "default" )
97+ if err != nil {
98+ t .Fatal (err )
99+ }
100+ const id = "testdevice"
101+ const key = "testkey"
102+ if err = kcl .PublishKey (ctx , id , key ); err != nil {
103+ t .Fatal (err )
104+ }
105+ opts := repository.KeyOptions {"svc@example.com" , "" }
106+ if err := kcl .ConfigureKey (ctx , id , opts ); err != nil {
107+ t .Fatal (err )
108+ }
109+ k , err := kcl .LookupKey (ctx , id )
110+ if err != nil {
111+ t .Fatal (err )
112+ }
113+ if k .SAName != "svc@example.com" {
114+ t .Fatalf ("LookupKey: got %q, expected %q" , k .SAName , "svc@example.com" )
115+ }
116+ }
0 commit comments