(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestGetSecret(t *testing.T) { |
| 13 | // Setup |
| 14 | file, err := os.Create("/tmp/tinyauth_test_secret") |
| 15 | assert.NilError(t, err) |
| 16 | |
| 17 | _, err = file.WriteString(" secret \n") |
| 18 | assert.NilError(t, err) |
| 19 | |
| 20 | err = file.Close() |
| 21 | assert.NilError(t, err) |
| 22 | defer os.Remove("/tmp/tinyauth_test_secret") |
| 23 | |
| 24 | // Get from config |
| 25 | assert.Equal(t, "mysecret", utils.GetSecret("mysecret", "")) |
| 26 | |
| 27 | // Get from file |
| 28 | assert.Equal(t, "secret", utils.GetSecret("", "/tmp/tinyauth_test_secret")) |
| 29 | |
| 30 | // Get from both (config should take precedence) |
| 31 | assert.Equal(t, "mysecret", utils.GetSecret("mysecret", "/tmp/tinyauth_test_secret")) |
| 32 | |
| 33 | // Get from none |
| 34 | assert.Equal(t, "", utils.GetSecret("", "")) |
| 35 | |
| 36 | // Get from non-existing file |
| 37 | assert.Equal(t, "", utils.GetSecret("", "/tmp/non_existing_file")) |
| 38 | } |
| 39 | |
| 40 | func TestParseSecretFile(t *testing.T) { |
| 41 | // Normal case |
nothing calls this directly
no test coverage detected