(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func TestAuthPluginPersist(t *testing.T) { |
| 98 | // register pluginA by a different name so we don't collide across tests. |
| 99 | if err := RegisterAuthProviderPlugin("pluginA2", pluginAProvider); err != nil { |
| 100 | t.Errorf("Unexpected error: failed to register pluginA: %v", err) |
| 101 | } |
| 102 | if err := RegisterAuthProviderPlugin("pluginPersist", pluginPersistProvider); err != nil { |
| 103 | t.Errorf("Unexpected error: failed to register pluginPersist: %v", err) |
| 104 | } |
| 105 | fooBarConfig := map[string]string{"foo": "bar"} |
| 106 | testCases := []struct { |
| 107 | plugin string |
| 108 | startingConfig map[string]string |
| 109 | expectedConfigAfterLogin map[string]string |
| 110 | expectedConfigAfterRoundTrip map[string]string |
| 111 | }{ |
| 112 | // non-persisting plugins should work fine without modifying config. |
| 113 | {"pluginA2", map[string]string{}, map[string]string{}, map[string]string{}}, |
| 114 | {"pluginA2", fooBarConfig, fooBarConfig, fooBarConfig}, |
| 115 | // plugins that persist config should be able to persist when they want. |
| 116 | { |
| 117 | "pluginPersist", |
| 118 | map[string]string{}, |
| 119 | map[string]string{ |
| 120 | "login": "Y", |
| 121 | }, |
| 122 | map[string]string{ |
| 123 | "login": "Y", |
| 124 | "roundTrips": "1", |
| 125 | }, |
| 126 | }, |
| 127 | { |
| 128 | "pluginPersist", |
| 129 | map[string]string{ |
| 130 | "login": "Y", |
| 131 | "roundTrips": "123", |
| 132 | }, |
| 133 | map[string]string{ |
| 134 | "login": "Y", |
| 135 | "roundTrips": "123", |
| 136 | }, |
| 137 | map[string]string{ |
| 138 | "login": "Y", |
| 139 | "roundTrips": "124", |
| 140 | }, |
| 141 | }, |
| 142 | } |
| 143 | for i, tc := range testCases { |
| 144 | cfg := &clientcmdapi.AuthProviderConfig{ |
| 145 | Name: tc.plugin, |
| 146 | Config: tc.startingConfig, |
| 147 | } |
| 148 | persister := &inMemoryPersister{make(map[string]string)} |
| 149 | persister.Persist(tc.startingConfig) |
| 150 | plugin, err := GetAuthProvider("127.0.0.1", cfg, persister) |
| 151 | if err != nil { |
| 152 | t.Errorf("%d. Unexpected error: failed to get plugin %q: %v", i, tc.plugin, err) |
| 153 | } |
| 154 | if err := plugin.Login(); err != nil { |
nothing calls this directly
no test coverage detected