vitess.io/vitess@v0.16.2/go/mysql/vault/auth_server_vault_test.go (about) 1 /* 2 copyright 2020 The Vitess Authors. 3 4 licensed under the apache license, version 2.0 (the "license"); 5 you may not use this file except in compliance with the license. 6 you may obtain a copy of the license at 7 8 http://www.apache.org/licenses/license-2.0 9 10 unless required by applicable law or agreed to in writing, software 11 distributed under the license is distributed on an "as is" basis, 12 without warranties or conditions of any kind, either express or implied. 13 see the license for the specific language governing permissions and 14 limitations under the license. 15 */ 16 17 package vault 18 19 import ( 20 "testing" 21 "time" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestErrorConditions(t *testing.T) { 27 // Bad token file path 28 _, err := newAuthServerVault("localhost", 1*time.Second, "", "/path/to/secret/in/vault", 10*time.Second, "/tmp/this_file_does_not_exist", "", "", "") 29 assert.Contains(t, err.Error(), "No Vault token in provided filename") 30 31 // Bad secretID file path 32 _, err = newAuthServerVault("localhost", 1*time.Second, "", "/path/to/secret/in/vault", 10*time.Second, "", "", "/tmp/this_file_does_not_exist", "") 33 assert.Contains(t, err.Error(), "No Vault secret_id in provided filename") 34 35 // Bad init ; but we should just retry 36 a, err := newAuthServerVault("https://localhost:828", 1*time.Second, "", "/path/to/secret/in/vault", 10*time.Second, "", "", "", "") 37 assert.NotEqual(t, a, nil) 38 assert.Equal(t, err, nil) 39 40 // Test reload, should surface error, since we don't have a Vault 41 // instance on port 828 42 err = a.reloadVault() 43 assert.Contains(t, err.Error(), "Error in vtgate Vault auth server params") 44 assert.Contains(t, err.Error(), "connection refused") 45 46 a.close() 47 }