Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Write config to temp folder instead #21631

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions server/v2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ func TestServer(t *testing.T) {
require.Equal(t, serverCfgs[mockServer.Name()].(*mockServerConfig).MockFieldOne, MockServerDefaultConfig().MockFieldOne)

// write config
err = server.WriteConfig(configPath)
tempDir := t.TempDir()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test makes less sense now because, we read from testdata (see configPath) and eventually write to a temporary location and read it back and do more assertion.
So testdata would need to be manually updated if there is a change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the goal to not write to the testdata folder. Otherwise the file get's added to a PR by mistake easily and causes other tests to fail later due to concurrent access. I have run into this in a PR as well as Marko. The root cause was not easy to find.
The test still confirms that a pre-defined app.toml can be imported and that an exported app.toml can be imported again. I hope this adds more context and explains my motivation. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supersede by #21645.
The test was just missing a server, so this is why it wasn't rendering the same file.
I still think we should write it to disk.

require.NoError(t, server.WriteConfig(tempDir)) // writes app.toml
require.NoError(t, os.WriteFile(filepath.Join(tempDir, "config.toml"), []byte{}, 0o600)) // any config.toml
v, err = serverv2.ReadConfig(tempDir)
require.NoError(t, err)

v, err = serverv2.ReadConfig(configPath)
require.NoError(t, err)

require.Equal(t, v.GetString(grpcServer.Name()+".address"), grpc.DefaultConfig().Address)

// start empty
Expand Down
Loading