-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add test for plugin scaffold
command
#613
Conversation
Overview
Packages and Vulnerabilities (5 package changes and 0 vulnerability changes)
Changes for packages of type
|
Package | Versionghcr.io/gatewayd-io/gatewayd:efc8668 |
Versiongatewaydio/gatewayd:latest |
|
---|---|---|---|
➖ | ca-certificates | 20240705-r0 |
|
➖ | openssl | 3.3.2-r0 |
|
➖ | pax-utils | 1.3.7-r2 |
Changes for packages of type golang
(2 changes)
Package | Versionghcr.io/gatewayd-io/gatewayd:efc8668 |
Versiongatewaydio/gatewayd:latest |
|
---|---|---|---|
♾️ | github.com/gatewayd-io/gatewayd | (devel) |
0.9.8 |
♾️ | stdlib | go1.23.2 |
1.23.1 |
6dd9adb
to
07f1338
Compare
require.NoError(t, err, "plugin scaffold should not return an error") | ||
assert.Contains(t, output, "scaffold done") | ||
assert.Contains(t, output, "created files:") | ||
assert.Contains(t, output, "test-gatewayd-plugin/.github/issue_template.md") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use test-gateway-plugin
multiple times, we can have a valuable for it like
pluginDir := filepath.Join(t.TempDir(), "test-gatewayd-plugin")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use t.TempDir() to avoid polluting the working directory - https://pkg.go.dev/testing#B.TempDir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d7cf221.
cmd/plugin_scaffold_test.go
Outdated
err = yamlv3.Unmarshal(pluginsConfig, &localPluginsConfig) | ||
require.NoError(t, err, "unmarshalling yaml file should not return error") | ||
|
||
tidy := exec.Command("go", "mod", "tidy") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now, we use the same structure twice; we can create a separate function for it
func runCommand(command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Dir = args[len(args)-1]
return cmd.Run()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d7cf221.
cmd/plugin_scaffold_test.go
Outdated
err = build.Run() | ||
assert.NoError(t, err) | ||
|
||
_, err = os.ReadFile(filepath.Join("plugins", "test-gatewayd-plugin", "test-gatewayd-plugin")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we want to verify that file exist we can use os.stat without reading the binary
_, err = os.ReadFile(filepath.Join("plugins", "test-gatewayd-plugin", "test-gatewayd-plugin")) | |
_, err = os.Stat(filepath.Join("plugins", "test-gatewayd-plugin", "test-gatewayd-plugin")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d7cf221.
cmd/plugin_scaffold_test.go
Outdated
assert.NoError(t, err) | ||
|
||
_, err = os.ReadFile(filepath.Join("plugins", "test-gatewayd-plugin", "test-gatewayd-plugin")) | ||
require.NoError(t, err, "reading plugin binary file should not return an error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.NoError(t, err, "reading plugin binary file should not return an error") | |
require.NoError(t, err, "plugin binary file should exist") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d7cf221.
cmd/plugin_scaffold_test.go
Outdated
|
||
pluginsList := cast.ToSlice(localPluginsConfig["plugins"]) | ||
plugin := cast.ToStringMap(pluginsList[0]) | ||
pluginsList[0] = plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary, we do the same later
pluginsList[0] = plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d7cf221.
cmd/plugin_scaffold_test.go
Outdated
|
||
waitGroup.Wait() | ||
|
||
assert.NoError(t, os.RemoveAll("plugins")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we use t.TempDir() we dont need this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d7cf221.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
Ticket(s)
Closes #475.
Description
Add test for
plugin scaffold
command. Thanks to @zeina1i for implementing the feature and writing the original test.Related PRs
N/A
Development Checklist
make gen-docs
command.Legal Checklist