Skip to content

Commit

Permalink
feat: add tests for SOFT_SERVE_CONFIG_LOCATION
Browse files Browse the repository at this point in the history
  • Loading branch information
fire833 committed Aug 30, 2024
1 parent 0ad3d29 commit 3e1b73b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,26 @@ func TestValidateInitAdminKeys(t *testing.T) {
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH",
})
}

func TestCustomConfigLocation(t *testing.T) {
is := is.New(t)
td := t.TempDir()
t.Cleanup(func() {
is.NoErr(os.Unsetenv("SOFT_SERVE_CONFIG_LOCATION"))
})

// Test that we get data from the custom file location, and not from the data dir.
is.NoErr(os.Setenv("SOFT_SERVE_CONFIG_LOCATION", "testdata/config.yaml"))
is.NoErr(os.Setenv("SOFT_SERVE_DATA_PATH", td))
cfg := DefaultConfig()
is.NoErr(cfg.Parse())
is.Equal(cfg.Name, "Test server name")
// If we unset the custom location, then use the default location.
is.NoErr(os.Unsetenv("SOFT_SERVE_CONFIG_LOCATION"))
cfg = DefaultConfig()
is.Equal(cfg.Name, "Soft Serve")
// Test that if the custom config location doesn't exist, default to datapath config.
is.NoErr(os.Setenv("SOFT_SERVE_CONFIG_LOCATION", "testdata/config_nonexistent.yaml"))
cfg = DefaultConfig()
is.Equal(cfg.Name, "Soft Serve")
}
3 changes: 3 additions & 0 deletions pkg/config/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Soft Serve Server configurations

name: "Test server name"

0 comments on commit 3e1b73b

Please sign in to comment.