-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM-54314: Return the error correctly from config parse failure (#649)
https://mattermost.atlassian.net/browse/MM-54314 Co-authored-by: Alejandro García Montoro <[email protected]>
- Loading branch information
1 parent
30a3c75
commit b616ffa
Showing
3 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package defaults | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testCFG struct { | ||
Setting string `default:"hi"` | ||
Another int `default:"1"` | ||
} | ||
|
||
func TestReadFromJSON(t *testing.T) { | ||
cfg := testCFG{} | ||
f, err := os.CreateTemp("", "loadtest") | ||
require.NoError(t, err) | ||
defer os.Remove(f.Name()) // clean up | ||
|
||
// Ensuring that a bad config throws an error | ||
_, err = f.Write([]byte(`{"setting": "hello" "another": 1}`)) | ||
require.NoError(t, err) | ||
require.NoError(t, f.Close()) | ||
|
||
require.Error(t, ReadFromJSON("", f.Name(), &cfg)) | ||
|
||
cfg = testCFG{} | ||
f1, err := os.CreateTemp("", "loadtest") | ||
require.NoError(t, err) | ||
defer os.Remove(f1.Name()) // clean up | ||
|
||
// Ensuring default values get correctly overridden | ||
_, err = f1.Write([]byte(`{"setting": "hello"}`)) | ||
require.NoError(t, err) | ||
require.NoError(t, f1.Close()) | ||
|
||
require.NoError(t, ReadFromJSON("", f1.Name(), &cfg)) | ||
assert.Equal(t, 1, cfg.Another) | ||
assert.Equal(t, "hello", cfg.Setting) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,50 @@ import ( | |
|
||
"github.com/mattermost/mattermost-load-test-ng/defaults" | ||
"github.com/mattermost/mattermost-load-test-ng/loadtest/store/memstore" | ||
"github.com/mattermost/mattermost-load-test-ng/logger" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type ratesDistribution struct { | ||
Rate float64 `default:"1.0" validate:"range:[0,)"` | ||
Percentage float64 `default:"1.0" validate:"range:[0,1]"` | ||
} | ||
type userControllerType string | ||
|
||
type config struct { | ||
ConnectionConfiguration struct { | ||
ServerURL string `default:"http://localhost:8065" validate:"url"` | ||
WebSocketURL string `default:"ws://localhost:8065" validate:"url"` | ||
AdminEmail string `default:"[email protected]" validate:"email"` | ||
AdminPassword string `default:"Sys@dmin-sample1" validate:"notempty"` | ||
} | ||
UserControllerConfiguration struct { | ||
Type userControllerType `default:"simulative" validate:"oneof:{simple,simulative,noop,cluster,generative}"` | ||
RatesDistribution []ratesDistribution `default_len:"1"` | ||
ServerVersion string | ||
} | ||
InstanceConfiguration struct { | ||
NumTeams int64 `default:"2" validate:"range:[0,]"` | ||
NumChannels int64 `default:"10" validate:"range:[0,]"` | ||
NumPosts int64 `default:"0" validate:"range:[0,]"` | ||
NumReactions int64 `default:"0" validate:"range:[0,]"` | ||
NumAdmins int64 `default:"0" validate:"range:[0,]"` | ||
PercentReplies float64 `default:"0.5" validate:"range:[0,1]"` | ||
PercentRepliesInLongThreads float64 `default:"0.05" validate:"range:[0,1]"` | ||
PercentUrgentPosts float64 `default:"0.001" validate:"range:[0,1]"` | ||
PercentPublicChannels float64 `default:"0.2" validate:"range:[0,1]"` | ||
PercentPrivateChannels float64 `default:"0.1" validate:"range:[0,1]"` | ||
PercentDirectChannels float64 `default:"0.6" validate:"range:[0,1]"` | ||
PercentGroupChannels float64 `default:"0.1" validate:"range:[0,1]"` | ||
} | ||
UsersConfiguration struct { | ||
UsersFilePath string | ||
InitialActiveUsers int `default:"0" validate:"range:[0,$MaxActiveUsers]"` | ||
MaxActiveUsers int `default:"2000" validate:"range:(0,]"` | ||
AvgSessionsPerUser int `default:"1" validate:"range:[1,]"` | ||
} | ||
LogSettings logger.Settings | ||
} | ||
|
||
type TestHelper struct { | ||
|