nao1215 / spectest Goto Github PK
View Code? Open in Web Editor NEWA simple and extensible behavioural testing library for Go. You can use api test to simplify REST API, HTTP handler and e2e tests.
License: MIT License
A simple and extensible behavioural testing library for Go. You can use api test to simplify REST API, HTTP handler and e2e tests.
License: MIT License
Now, spectest support below method;
These method are defined in RFC 7231 section 4.3. The spectest is not supported them.
The spectest produces reports in Markdown format on a per-test-case basis. It is hard for us to find the desired report among many Markdowns.
Therefore, we will add a function to index markdowns located under the specified directory.
jbrown1618/markdown-index is close to the function we are looking for. However, some features are missing.
For example,
This feature will implement as cli command.
In addition, add the ability to generate indexes with go generate
.
The spectest is a package forked from steinfletcher/apitest. The apitest has the functionality to generate HTML documents from end-to-end test results, and the development of spectest was initiated to enhance this feature.
One month after the fork, spectest has added the capability to output documents in markdown format (I have also conducted refactoring). While there are several feature ideas, developing them alone would be time-consuming.
Therefore, I have decided to clearly outline spectest's roadmap and record feature ideas as issues. If you are interested in spectest, feel free to implement some of these issues.
I modify the code so that unit tests pass in a Windows environment.
I know that the difflib package is not compatible with windows. I think we should export for difflib package as an external repository.
A feature has been added to change the output of test results when using spectest ./... instead of go test ./.... For instance, successful tests will be displayed as green dots, while failed tests will be represented by red dots. This functionality is inspired by ideas from onsi/ginkgo and shellspec/shellspec.
WIP
WIP
WIP
The spectest package generates sequence diagrams.
This diagram has a hash as the file name. I want to store sequence diagrams in a document directory to share them with developers. However, using hash names for file titles is a bit inconvenient.
So, I wanted to give custom names to the sequence diagrams.
The solution is to add CustomeSequenceDiagramName().
(Method name may not be appropriate)
example
Report(spectest.SequenceDiagram()).
CustomeSequenceDiagramName("diagram_name_is_here").
// ...
End()
CustomSequenceDiagramName set APITest.meta["diagramName"]. If meta['diagramName'] is set, the hash name will not be used when outputting the sequence diagram.
The problem with this approach is that if you execute Meta() after executing CustomSequenceDiagramName(), the settings from CustomSequenceDiagramName() are lost.
The alternative way is implementing new ReportFormatter interface.
This method has a large modification scale. However, it has the advantage of being able to be implemented outside of the spectest package (I would adopt this idea if no additional features were added).
nothing
The apitest package, which is the source of the fork, provided an example at github.com/99designs/gqlgens. However, they were broken and did not work. We will re-create the examples again.
Currently, we are generating separate HTML files for each test case, but I would like to generate a single HTML document that consolidates documentation for each endpoint.
After generating the index markdown, spectest index does not output anything. I think it is difficult for the user to understand what happened with this specification. Therefore, the generated index file path will be outputted to the standard output.
If markdown.GenerateIndex() completes successfully, it will output the index file path to the standard output. If an error occurs, it will directly return the error to the higher-level function.
https://github.com/go-spectest/spectest/blob/26de85c47a740f596035376cf4b84e09ac9c7fc2/cmd/spectest/sub/index.go#L59-L62
To proceed with refactoring, it is necessary to ensure the current behavior through unit tests. First, create unit tests for functions that are not covered by test coverage. Since unit tests are created incrementally, it is expected that multiple pull requests will be made.
You can check the unit test coverage with the following command.
$ make test
$ open coverage.html
The spectest/x/db package is a wrapper for the database/sql package. However, there are wrappers for deprecated methods, and some parts do not work as wrappers for the current database/sql package.
So, update spectest/x/db.
We are implementing mocks for the official AWS package (SDK) in go-spectest/aws. The package was severely broken at the time of forking, and there was also an issue with the limited number of supported AWS resources.
Therefore, we believe it would be best to start fresh by adding AWS SDK mocks anew. With over 100 types of AWS resources, manually adding mocks would be daunting. We are considering adopting a method to automatically generate mocks from the interfaces exposed by the AWS SDK.
Eventually, go-spectest/aws is planned to be integrated into go-spectest/spectest.
I believe that the best way to improve the spectest package is to actually use it. Since spectest is a testing framework, it requires something to test. However, it doesn't make sense to use it in very small projects.
Therefore, I plan to develop a client-server application and test its server-side components using spectest. The goal is to reach a state where spectest is used for all unit tests (currently, spectest provides functionality only for E2E testing).
The server and client will be developed in separate repositories. The client is intended for Android (kotlin) or Web (elm) platforms.
Deciding on the application concept is the first step.
We plan to create an app for upscaling images and videos, but this application will require Deep Learning training. Additionally, we need to consider other app ideas that do not require as much development effort.
We often manually create expectations for response data. This process is very tedious. Therefore, we will add a function to generate the expected value data in a specified path when the test is executed with a specific procedure.
We would add the Golden() method. This method writes response body data to the specified file path. However, the write operation is performed only when certain flags are enabled.
The method to enable the flags is under consideration. For example, we can create a spectest cli command, and the Golden() method will generate a file if the --golden option of this command is enabled.
Introduce gosec. For example;
name: Gosec
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
tests:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v4
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
Related #10
We need to add the following HTTP method mock methods to the Mock structure.
Many projects managed by git submodule are tightly integrated with spectest. Therefore, whenever code refactoring is completed within each repository, it is incorporated into spectest.
"Spectest" has the functionality to create sequence diagrams. However, due to the coarse granularity of the generated sequence diagrams, I want to create sequence diagrams based on method calls.
When creating function/method-based sequence diagrams, it is straightforward to perform static analysis of the code. This method eliminates the need to execute it every time during testing, addressing concerns about slow performance.
Therefore, a command-based sequence diagram generation feature is developed to facilitate verification.
The apitest package, which is the source of the fork, provided an example at github.com/kataras/iris. However, they were broken and did not work. We will re-create the examples again.
It seems that "\n" is hard-coded as a newline code, so use "\n" on Linux and Mac, and "\r\n" on Windows.
Spectest has many fields within a single struct. I believe these fields can be encapsulated into smaller structs. By creating new structs and associating methods with them, the code readability and organization can be significantly improved.
In cases where you return random values like ULID, you can use a user-defined function to define custom Assert criteria and perform the Assert operation.
The spectest display response data in the document according to Content Type.
For example, spectest will display binary data in the document if the response data is an image. If possible, i would like to display images in the document.
Determine Content-Type from HTTP headers and create HTML template generation process according to Content-Type.
The method I suggested has the potential to significantly rewrite the HTML template.
nothing
Due to heavy use of method chaining, most of the error handling in apitest relies on panic(). However, even with method chaining, errors can be returned to the calling function or evaluated later.
In spectest, the error handling approach will be changed.
Some functions in spectest are hard to understand at a glance. To address this, I will add documentation. Additionally, due to the lengthy lines of code within the functions, I will refactor them into smaller, more manageable functions.
If the expected value does not match the obtained value, the following message appears. We want to display this message in red text to make it easier for users to understand the error content.
Error: Not equal:
expected: true
actual : false
Test: TestNewApp/Width_test
Messages: mismatched values for header 'Content-Type'. Expected image/png but received text/plain; charset=utf-8
Name: width,height is zero
Use fatih/color to change text color for cross-platform support.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.