From e300b0dffbf8fd26696c282f6897760aba053472 Mon Sep 17 00:00:00 2001 From: David Allen Date: Mon, 15 Jul 2024 11:28:56 -0600 Subject: [PATCH 1/5] Updated README.md adding a test section --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 54b511a..298aad4 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,17 @@ targets: # targets to call with --target flag The `server` section sets the properties for running the `configurator` tool as a service and is not required if you're only using the CLI. Also note that the `jwks-uri` parameter is only needs for protecting endpoints. If it is not set, then the API is entirely public. The `smd` section tells the `configurator` tool where to find SMD to pull state management data used by the internal client. The `templates` section is where the paths are mapped to each generator plugin by its name (see the [`Creating Generator Plugins`](#creating-generator-plugins) section for details). The `plugins` is a list of paths to load generator plugins. +## Running the Tests + +The `configurator` project includes a collection of tests focused on verifying plugin behavior and generating files. The tests do not currently test fetching information from SMD (or whatever remote source). The tests can be ran with either of the following commands: + +```bash +go test ./tests/generate_test.go --tags=all +# ...or alternatively with GNU make... +make tests +``` + + ## Known Issues - Adds a new `OAuthClient` with every token request From 71a7c8d5b96644609516d080785869690713622b Mon Sep 17 00:00:00 2001 From: David Allen Date: Mon, 15 Jul 2024 11:44:32 -0600 Subject: [PATCH 2/5] Fixed typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 298aad4..3fe72a3 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ The `configurator` project includes a collection of tests focused on verifying p ```bash go test ./tests/generate_test.go --tags=all # ...or alternatively with GNU make... -make tests +make test ``` From 2d367df02d755b8bae21a7a6b79cfa6173416097 Mon Sep 17 00:00:00 2001 From: David Allen Date: Mon, 15 Jul 2024 16:15:45 -0600 Subject: [PATCH 3/5] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f9bc65d..e848d1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -**configurator** +**configurator **.yaml **.yml **.so From f12b0056b71c6c973ad838e584fd8e301cd6d7f6 Mon Sep 17 00:00:00 2001 From: David Allen Date: Mon, 15 Jul 2024 16:16:29 -0600 Subject: [PATCH 4/5] Updated example plugin imports --- pkg/generator/plugins/example/example.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/generator/plugins/example/example.go b/pkg/generator/plugins/example/example.go index 05b9fa0..64cd3bc 100644 --- a/pkg/generator/plugins/example/example.go +++ b/pkg/generator/plugins/example/example.go @@ -3,9 +3,9 @@ package main import ( "fmt" - configurator "github.com/OpenCHAMI/configurator/internal" - "github.com/OpenCHAMI/configurator/internal/generator" - "github.com/OpenCHAMI/configurator/internal/util" + configurator "github.com/OpenCHAMI/configurator/pkg" + "github.com/OpenCHAMI/configurator/pkg/generator" + "github.com/OpenCHAMI/configurator/pkg/util" ) type Example struct { From e84ed01fa83e0b369109f3b5476e427d71868f97 Mon Sep 17 00:00:00 2001 From: David Allen Date: Mon, 15 Jul 2024 16:16:53 -0600 Subject: [PATCH 5/5] Fixed (mostly) issues with tests failing --- tests/generate_test.go | 59 ++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/tests/generate_test.go b/tests/generate_test.go index 31e6e04..39ba06e 100644 --- a/tests/generate_test.go +++ b/tests/generate_test.go @@ -90,8 +90,6 @@ func TestPlugin(t *testing.T) { package main import ( - "fmt" - configurator "github.com/OpenCHAMI/configurator/pkg" "github.com/OpenCHAMI/configurator/pkg/generator" "github.com/OpenCHAMI/configurator/pkg/util" @@ -121,7 +119,7 @@ var Generator TestGenerator fmt.Printf("(TestPlugin) plugin source path: %v\n", testPluginSourcePath) // make temporary directory to test plugin - err = os.MkdirAll(testPluginDir, os.ModeDir) + err = os.MkdirAll(testPluginDir, 0o777) if err != nil { t.Fatalf("failed to make temporary directory: %v", err) } @@ -147,9 +145,21 @@ var Generator TestGenerator t.Fatalf("failed to 'cd' to temporary directory: %v", err) } + // initialize the plugin directory as a Go project + cmd := exec.Command("bash", "-c", "go mod init github.com/OpenCHAMI/configurator-test-plugin") + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("failed to execute command: %v\n%s", err, string(output)) + } + + // run `go mod tidy` for dependencies + cmd = exec.Command("bash", "-c", "go mod tidy") + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("failed to execute command: %v\n%s", err, string(output)) + } + // execute command to build the plugin - cmd := exec.Command("go", "build", "-buildmode=plugin", fmt.Sprintf("-o=%s", testPluginPath), testPluginSourcePath) - if output, err := cmd.Output(); err != nil { + cmd = exec.Command("bash", "-c", "go build -buildmode=plugin -o=test-plugin.so test-plugin.go") + if output, err := cmd.CombinedOutput(); err != nil { t.Fatalf("failed to execute command: %v\n%s", err, string(output)) } @@ -166,7 +176,7 @@ var Generator TestGenerator } // test loading plugins both individually and in a dir - gen, err := generator.LoadPlugin(testPluginSourcePath) + gen, err := generator.LoadPlugin("test-plugin.so") if err != nil { t.Fatalf("failed to load the test plugin: %v", err) } @@ -215,18 +225,11 @@ func TestPluginWithInvalidOrNoSymbol(t *testing.T) { testPluginSource = []byte(` package main -import ( - "fmt" - - configurator "github.com/OpenCHAMI/configurator/pkg" - "github.com/OpenCHAMI/configurator/pkg/generator" - "github.com/OpenCHAMI/configurator/pkg/util" -) - // An invalid generator that does not or partially implements // the "Generator" interface. type InvalidGenerator struct{} -var Generator TestGenerator +func (g *InvalidGenerator) GetName() string { return "invalid" } +var Generator InvalidGenerator `) ) @@ -236,7 +239,7 @@ var Generator TestGenerator } // show all paths to make sure we're using the correct ones fmt.Printf("(TestPluginWithInvalidOrNoSymbol) working directory: %v\n", wd) - fmt.Printf("(TestPluginWithInvalidOrNoSymbol) plugin directory: %v\n", testPluginDir) + fmt.Printf("(TestPluginWithInvalidOrNoSymbol) plugin directory: %v\n", testPluginDir) fmt.Printf("(TestPluginWithInvalidOrNoSymbol) plugin path: %v\n", testPluginPath) fmt.Printf("(TestPluginWithInvalidOrNoSymbol) plugin source path: %v\n", testPluginSourcePath) @@ -267,9 +270,21 @@ var Generator TestGenerator t.Fatalf("failed to 'cd' to temporary directory: %v", err) } + // initialize the plugin directory as a Go project + cmd := exec.Command("bash", "-c", "go mod init github.com/OpenCHAMI/configurator-test-plugin") + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("failed to execute command: %v\n%s", err, string(output)) + } + + // run `go mod tidy` for dependencies + cmd = exec.Command("bash", "-c", "go mod tidy") + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("failed to execute command: %v\n%s", err, string(output)) + } + // execute command to build the plugin - cmd := exec.Command("go", "build", "-buildmode=plugin", fmt.Sprintf("-o=%s", testPluginPath), testPluginSourcePath) - if output, err := cmd.Output(); err != nil { + cmd = exec.Command("bash", "-c", "go build -buildmode=plugin -o=invalid-plugin.so invalid-plugin.go") + if output, err := cmd.CombinedOutput(); err != nil { t.Fatalf("failed to execute command: %v\n%s", err, string(output)) } @@ -312,7 +327,7 @@ func TestGenerateExample(t *testing.T) { if gen.GetVersion() != "v1.0.0" { t.Error("test generator return unexpected version") } - if gen.GetDescription() != "This is a plugin creating for running tests." { + if gen.GetDescription() != "This is a plugin created for running tests." { t.Error("test generator return unexpected description") } }) @@ -355,12 +370,6 @@ func TestGenerateExampleWithServer(t *testing.T) { FilePaths: []string{}, } - // show which targets are availabe in the config - fmt.Printf("targets:\n") - for target, _ := range config.Targets { - fmt.Printf("\t- %s\n", target) - } - // create new server, add test generator, and start in background server := server.New(&config) server.GeneratorParams.Generators = map[string]generator.Generator{