Documentation
¶
Overview ¶
Package shared contains common shared information, and utilities.
Index ¶
- Constants
- Variables
- func CreateHTTPTestServer(statusCode int, headers map[string]string, queryParams map[string]string, ...) *httptest.Server
- func Decode(r io.Reader, v any) error
- func Encode(w io.Writer, v any) error
- func ErrorContains(err error, text ...string) bool
- func GenerateID(ct string) string
- func GenerateUUID() string
- func IsEnvironment(environments ...string) bool
- func Marshal(v any) ([]byte, error)
- func MarshalIndent(v any, prefix, indent string) ([]byte, error)
- func PrintErrorMessages(errors ...error) string
- func Process(v any) error
- func ReadAll(r io.Reader) ([]byte, error)
- func SliceContains(source []string, text string) bool
- func Unmarshal(data []byte, v any) error
- type TestDataS
- type TestDataWithIDS
Constants ¶
const ( // Development is the development environment. Development = "development" // Integration is the integration environment. Integration = "integration" // Production is the production environment. Production = "production" // Staging is the staging environment. Staging = "staging" // Testing is the testing environment. Testing = "testing" )
const ( // DatabaseName is the database name. DatabaseName = Test // TableName is the table/collection/index/etc name. TableName = Test // DefaultTimeout is the default timeout. DefaultTimeout = 30 * time.Second // DocumentID is the document ID. DocumentID = "VFzrpYMBXu5BQSZxo0qX" // DocumentIDInvalid is an invalid document ID. DocumentIDInvalid = "VFzrpYMBXu5BQSZxo0qY" // DocumentName is the document name. DocumentName = Test // DocumentNameUpdated is the updated document name. DocumentNameUpdated = "Test2" // DocumentVersion is the document version. DocumentVersion = "1.0.0" RoleName = "test" // Test name. Test = "test" )
Variables ¶
var ( // TestData is the test data. TestData = &TestDataS{ Name: DocumentName, Version: DocumentVersion, } // TestDataWithID is the test data. TestDataWithID = &TestDataWithIDS{ ID: DocumentID, Name: DocumentName, Version: DocumentVersion, } // UpdatedTestData is the updated test data. UpdatedTestData = &TestDataS{ Name: DocumentNameUpdated, Version: DocumentVersion, } // UpdatedTestDataID is the updated test data with ID. UpdatedTestDataID = &TestDataWithIDS{ ID: DocumentID, Name: DocumentNameUpdated, Version: DocumentVersion, } )
Functions ¶
func CreateHTTPTestServer ¶
func CreateHTTPTestServer( statusCode int, headers map[string]string, queryParams map[string]string, body string, ) *httptest.Server
CreateHTTPTestServer creates a mocked HTTP server. Don't forget to defer close it!
SEE: Test for usage.
func ErrorContains ¶
ErrorContains checks if an error contains a string.
func GenerateID ¶
GenerateID generates MD5 hash (content-based) based on content. Good to be used to avoid duplicated messages.
func GenerateUUID ¶
func GenerateUUID() string
GenerateUUID generates a RFC4122 UUID and DCE 1.1: Authentication and Security Services.
func IsEnvironment ¶
IsEnvironment determines if the current environment is one of the provided.
func MarshalIndent ¶
MarshalIndent will marshal `v` with `prefix` and `indent` and returns an error if any.
func PrintErrorMessages ¶
PrintErrorMessages prints the concatenated error messages.
func Process ¶ added in v1.0.24
Process will process `v` with the following steps: 1. Set default values. 2. Set environment variables. 3. Set ID.
func SliceContains ¶
SliceContains returns true if the slice contains the string.
NOTE: It's case insensitive.
NOTE: @andres moved to here.
Types ¶
type TestDataS ¶
type TestDataS struct { Name string `db:"name" dbType:"varchar(255)" json:"name,omitempty" query:"name"` Version string `db:"version" dbType:"varchar(255)" json:"version,omitempty" query:"version"` }
TestDataS is the test data definition.
type TestDataWithIDS ¶
type TestDataWithIDS struct { ID string `bson:"_id" db:"id" dbType:"varchar(255)" json:"id,omitempty" query:"id"` Name string `db:"name" dbType:"varchar(255)" json:"name,omitempty" query:"name"` Version string `db:"version" dbType:"varchar(255)" json:"version,omitempty" query:"version"` }
TestDataWithIDS is the test data definition.