diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..8fd79a3 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,94 @@ +# Contributing to fern-reporter + +First off, thank you for considering contributing to fern-reporter! It's people like you that make the open source community such a great place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. + +## Code of Conduct + +While we are not a CNCF project, we fully support and endorse its general principles. As an extension, fern-reporter follows their [Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md) that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated. + +## How Can I Contribute? + +### Reporting Bugs + +Before creating bug reports, please check the [issue tracker](https://github.com/guidewire-oss/fern-junit-client/issues) as you might find out that you don't need to create one. When you are creating a bug report, please include as many details as possible by filling out the required template. Follow the "How to Report a Bug" guidelines. + +#### How to Report a Bug + +1. **Use a clear and descriptive title** for the issue to identify the problem. +2. **Describe the exact steps which reproduce the problem** in as many details as possible. +3. **Provide specific examples to demonstrate the steps.** +4. **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior. +5. **Explain which behavior you expected to see instead and why.** +6. **Include screenshots and animated GIFs** if possible. + +### Suggesting Enhancements + +This section guides you through submitting an enhancement suggestion for fern-reporter, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion. + +#### How to Suggest Enhancements + +1. **Use a clear and descriptive title** for the issue to identify the suggestion. +2. **Provide a step-by-step description of the suggested enhancement** in as many details as possible. +3. **Provide specific examples to demonstrate the steps**. Include copy/pasteable snippets which you use in those examples, as Markdown code blocks. +4. **Describe the current behavior** and **explain which behavior you expected to see instead** and why. +5. **Explain why this enhancement would be useful** to most fern-reporter users. +6. **List some other projects where this enhancement exists.** + +### Your First Code Contribution + +Unsure where to begin contributing to fern-junit-client? You can start by looking through 'beginner' and 'help-wanted' issues: + +* [Beginner issues](https://github.com/guidewire-oss/fern-junit-client//labels/good%20first%20issue) - issues which should only require a few lines of code, and a test or two. +* [Help wanted issues](https://github.com/guidewire-oss/fern-junit-client//labels/help%20wanted) - issues which should be a bit more involved than 'beginner' issues. + +### Pull Requests + +The process described here has several goals: + +- Maintain fern-reporter's quality. +- Fix problems that are important to users. +- Engage the community in working toward the best possible fern-reporter. + +Here are the steps for submitting a pull request: + +1. **Fork the repo and create your branch from `main`.** +2. **If you've added code that should be tested, add tests.** +3. **Ensure the test suite passes.** +4. **Make sure your code lints.** +5. **Issue that pull request!** + +#### Pull Request Checklist + +- [ ] I have read the contributing guidelines. +- [ ] I have performed a self-review of my own code or materials. +- [ ] I have commented my code or provided relevant documentation, particularly in hard-to-understand areas. +- [ ] I have made corresponding changes to the documentation. +- [ ] I have tested with both the fern client and fern server +- [ ] Any dependent changes have been merged and published in downstream modules. + + +### Pull Requests Process + +You will be asked to sign a [Developer Certificate of Origin or DCO](https://www.secondstate.io/articles/dco/) where you certify that you wrote or otherwise have the right to submit the code. +Once the pull request is opened, a fern-reporter maintainer will review your changes. +If all is good, your pull request will be merged into the main codebase. + +### Styleguides + +#### Git Commit Messages +- Follow conventional commit messages mentioned [here](https://www.conventionalcommits.org/en/v1.0.0/#specification) +- Use the present tense ("Add feature" not "Added feature"). +- Use the imperative mood ("Move cursor to..." not "Moves cursor to..."). +- Limit the first line to 72 characters or less. +- Reference issues and pull requests liberally after the first line. + +#### Coding Conventions + +- Write clean, manageable code and follow the coding conventions of the project. +- Keep it simple and readable. +- Make sure you follow the go style guide mentioned [here](https://google.github.io/styleguide/go/) + +### Questions? + +Feel free to contact the project maintainers, either through the issue tracker or directly. + diff --git a/README.md b/README.md index c4c58d8..1f8af2a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,28 @@ To install the CLI, use the following command: go install github.com/guidewire-oss/fern-junit-client@latest ``` + +## Registering Application with Fern-Reporter +```bash +curl -L -X POST http://localhost:8080/api/project \ + -H "Content-Type: application/json" \ + -d '{ + "name": "First Projects", + "team_name": "my team", + "comment": "This is the test project" + }' +``` + +Sample Response: +```json +{ + "uuid": "996ad860-2a9a-504f-8861-aeafd0b2ae29", + "name": "First Projects", + "team_name": "my team", + "comment": "This is the test project" +} +``` + ## Usage To see all available options, use `fern-junit-client help` @@ -23,13 +45,13 @@ To see all available options, use `fern-junit-client help` #### Send Single Report ```sh -fern-junit-client send -u "http://localhost:8080" -p "MyService" -f "report.xml" +fern-junit-client send -u "http://localhost:8080" -p "77b34e74-5631-5a71-b8ce-97b9d6bab10a" -f "report.xml" ``` #### Send Multiple Reports ```sh -fern-junit-client send -u "http://localhost:8080" -p "MyService" -f "tests/*.xml" +fern-junit-client send -u "http://localhost:8080" -p "77b34e74-5631-5a71-b8ce-97b9d6bab10a" -f "tests/*.xml" ``` ## See Also @@ -40,6 +62,18 @@ fern-junit-client send -u "http://localhost:8080" -p "MyService" -f "tests/*.xml ## Development +To install the CLI locally for testing use the following command: + +```sh +go build + +``` + +```sh +./fern-junit-client send -u "http://localhost:8080" -p "77b34e74-5631-5a71-b8ce-97b9d6bab10a" -f "report.xml" +``` + + ### Executing Tests To execute the tests, run `make test` diff --git a/cmd/send.go b/cmd/send.go index 0943e9d..c53ee9a 100644 --- a/cmd/send.go +++ b/cmd/send.go @@ -11,7 +11,7 @@ import ( var ( fernUrl string - projectName string + projectId string filePattern string tags string ) @@ -21,7 +21,7 @@ var sendCmd = &cobra.Command{ Short: "Send JUnit test reports to Fern", Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { - if err := client.SendReports(fernUrl, projectName, filePattern, tags, verbose); err != nil { + if err := client.SendReports(fernUrl, projectId, filePattern, tags, verbose); err != nil { _, _ = fmt.Fprintf(os.Stderr, "ERROR: %s\n", err) os.Exit(1) } @@ -30,14 +30,14 @@ var sendCmd = &cobra.Command{ func init() { sendCmd.PersistentFlags().StringVarP(&fernUrl, "fern-url", "u", "", "base URL of the Fern Reporter instance to send test reports to (required)") - sendCmd.PersistentFlags().StringVarP(&projectName, "project-name", "p", "", "name of the project to associate test reports with (required)") + sendCmd.PersistentFlags().StringVarP(&projectId, "project-id", "p", "", "Id of the project to associate test reports with (required). You must register the application first in fern-reporter") sendCmd.PersistentFlags().StringVarP(&filePattern, "file-pattern", "f", "", "file name pattern of test reports to send to Fern (required)") sendCmd.PersistentFlags().StringVarP(&tags, "tags", "t", "", "comma-separated tags to be included on runs") if err := sendCmd.MarkPersistentFlagRequired("fern-url"); err != nil { _, _ = fmt.Fprintf(os.Stderr, "ERROR: %s\n", err) os.Exit(1) } - if err := sendCmd.MarkPersistentFlagRequired("project-name"); err != nil { + if err := sendCmd.MarkPersistentFlagRequired("project-id"); err != nil { _, _ = fmt.Fprintf(os.Stderr, "ERROR: %s\n", err) os.Exit(1) } diff --git a/go.mod b/go.mod index a11d544..318570c 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/guidewire-oss/fern-junit-client go 1.23.3 -require github.com/spf13/cobra v1.8.1 +require github.com/spf13/cobra v1.9.1 require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/pflag v1.0.6 // indirect ) diff --git a/go.sum b/go.sum index 912390a..07b3c25 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,15 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= +github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/client/client.go b/pkg/client/client.go index ebc2f5b..41a6cd5 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -7,9 +7,9 @@ import ( "github.com/guidewire-oss/fern-junit-client/pkg/util" ) -func SendReports(fernUrl, projectName, filePattern string, tags string, verbose bool) error { +func SendReports(fernUrl, projectId, filePattern string, tags string, verbose bool) error { var testRun fern.TestRun - testRun.TestProjectName = projectName + testRun.TestProjectID = projectId testRun.TestSeed = uint64(util.GlobalClock.Now().Nanosecond()) log.Default().Println("Parsing reports...") diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 715c77f..927b60e 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -7,7 +7,7 @@ import ( func TestSendReports(t *testing.T) { type args struct { fernUrl string - projectName string + projectId string filePattern string tags string verbose bool @@ -21,7 +21,7 @@ func TestSendReports(t *testing.T) { name: "combined reports", args: args{ fernUrl: mockFernReporter.URL, - projectName: testProjectName, + projectId: testProjectId, filePattern: reportsCombinedPattern, tags: exampleTags, verbose: true, @@ -32,7 +32,7 @@ func TestSendReports(t *testing.T) { name: "failed report", args: args{ fernUrl: mockFernReporter.URL, - projectName: testProjectName, + projectId: testProjectId, filePattern: reportFailedPath, tags: exampleTags, verbose: true, @@ -43,7 +43,7 @@ func TestSendReports(t *testing.T) { name: "passed report", args: args{ fernUrl: mockFernReporter.URL, - projectName: testProjectName, + projectId: testProjectId, filePattern: reportPassedPath, tags: exampleTags, verbose: true, @@ -54,7 +54,7 @@ func TestSendReports(t *testing.T) { name: "no reports", args: args{ fernUrl: mockFernReporter.URL, - projectName: testProjectName, + projectId: testProjectId, filePattern: nonExistentFilePath, tags: exampleTags, verbose: true, @@ -64,7 +64,7 @@ func TestSendReports(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := SendReports(tt.args.fernUrl, tt.args.projectName, tt.args.filePattern, tt.args.tags, tt.args.verbose); (err != nil) != tt.wantErr { + if err := SendReports(tt.args.fernUrl, tt.args.projectId, tt.args.filePattern, tt.args.tags, tt.args.verbose); (err != nil) != tt.wantErr { t.Errorf("SendReports() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/pkg/client/suite_test.go b/pkg/client/suite_test.go index 27ac89c..6e699e7 100644 --- a/pkg/client/suite_test.go +++ b/pkg/client/suite_test.go @@ -16,8 +16,8 @@ import ( ) const ( - testProjectName = "TestProject" - exampleTags = "test,tagtest,9=-+_" + testProjectId = "77b34e74-5631-5a71-b8ce-97b9d6bab10a" + exampleTags = "test,tagtest,9=-+_" nonExistentFilePath = "this_file_does_not_exist" @@ -132,7 +132,7 @@ func TestGenerateStaticJsonFiles(t *testing.T) { })) defer mockFernReporter.Close() // Run SendReports with input - if err := SendReports(mockFernReporter.URL, testProjectName, filePattern, exampleTags, true); err != nil { + if err := SendReports(mockFernReporter.URL, testProjectId, filePattern, exampleTags, true); err != nil { panic(fmt.Errorf("failed to generate Fern test run JSON for '%s' test case (%s): %w", testCase, filePattern, err)) } } diff --git a/pkg/models/fern/types.go b/pkg/models/fern/types.go index 473c1f8..4126a14 100644 --- a/pkg/models/fern/types.go +++ b/pkg/models/fern/types.go @@ -5,12 +5,12 @@ import ( ) type TestRun struct { - ID uint64 `json:"id"` - TestProjectName string `json:"test_project_name"` - TestSeed uint64 `json:"test_seed"` - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - SuiteRuns []SuiteRun `json:"suite_runs"` + ID uint64 `json:"id"` + TestProjectID string `json:"test_project_id"` + TestSeed uint64 `json:"test_seed"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + SuiteRuns []SuiteRun `json:"suite_runs"` } type SuiteRun struct { diff --git a/test/static/fern_test_run_combined.json b/test/static/fern_test_run_combined.json index 3e71c93..d3a4939 100644 --- a/test/static/fern_test_run_combined.json +++ b/test/static/fern_test_run_combined.json @@ -1,6 +1,6 @@ { "id": 0, - "test_project_name": "TestProject", + "test_project_id": "77b34e74-5631-5a71-b8ce-97b9d6bab10a", "test_seed": 288470000, "start_time": "2024-11-01T18:23:56Z", "end_time": "2024-11-01T18:23:56.12Z", diff --git a/test/static/fern_test_run_failed.json b/test/static/fern_test_run_failed.json index 656841d..86790ff 100644 --- a/test/static/fern_test_run_failed.json +++ b/test/static/fern_test_run_failed.json @@ -1,6 +1,6 @@ { "id": 0, - "test_project_name": "TestProject", + "test_project_id": "77b34e74-5631-5a71-b8ce-97b9d6bab10a", "test_seed": 291359000, "start_time": "2024-11-01T18:23:56Z", "end_time": "2024-11-01T18:23:56.12Z", diff --git a/test/static/fern_test_run_passed.json b/test/static/fern_test_run_passed.json index 297ffde..a6d470b 100644 --- a/test/static/fern_test_run_passed.json +++ b/test/static/fern_test_run_passed.json @@ -1,6 +1,6 @@ { "id": 0, - "test_project_name": "TestProject", + "test_project_id": "77b34e74-5631-5a71-b8ce-97b9d6bab10a", "test_seed": 293550000, "start_time": "2024-11-01T18:23:56Z", "end_time": "2024-11-01T18:23:56.12Z",