diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2023-05-24 05:57:53 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-24 05:57:53 +1000 |
| commit | f724818c44ffc5fa104529e658f4c2985b425847 (patch) | |
| tree | 62d8919d5add711178d55e71bad381155549f928 /internal/authentication/file_user_provider_database_test.go | |
| parent | 3131aa77d4ed18adf6f30f62e3482b9d05d88f03 (diff) | |
test(authentication): file provider (#5473)
Add additional tests to the file provider.
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/authentication/file_user_provider_database_test.go')
| -rw-r--r-- | internal/authentication/file_user_provider_database_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/authentication/file_user_provider_database_test.go b/internal/authentication/file_user_provider_database_test.go new file mode 100644 index 000000000..f8bb21d78 --- /dev/null +++ b/internal/authentication/file_user_provider_database_test.go @@ -0,0 +1,39 @@ +package authentication + +import ( + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDatabaseModel_Read(t *testing.T) { + model := &DatabaseModel{} + + dir := t.TempDir() + + _, err := os.Create(filepath.Join(dir, "users_database.yml")) + + assert.NoError(t, err) + + assert.EqualError(t, model.Read(filepath.Join(dir, "users_database.yml")), "no file content") + + assert.NoError(t, os.Mkdir(filepath.Join(dir, "x"), 0000)) + + f := filepath.Join(dir, "x", "users_database.yml") + + assert.EqualError(t, model.Read(f), fmt.Sprintf("failed to read the '%s' file: open %s: permission denied", f, f)) + + f = filepath.Join(dir, "schema.yml") + + file, err := os.Create(f) + assert.NoError(t, err) + + _, err = file.WriteString("users:\n\tjohn: {}") + + assert.NoError(t, err) + + assert.EqualError(t, model.Read(f), "could not parse the YAML database: yaml: line 2: found character that cannot start any token") +} |
