Skip to content

Commit

Permalink
added test options
Browse files Browse the repository at this point in the history
  • Loading branch information
deemount committed Mar 16, 2024
1 parent a1cea55 commit 2fc99d2
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 7 deletions.
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "TestInject",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}",
"showLog": true,
"args": [
"-test.v",
"^TestInject$"
]
},
{
"name": "TestEmbeddedInject",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}",
"showLog": true,
"args": [
"-test.v",
"^TestEmbeddedInject$"
]
}
]
}
42 changes: 42 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* MIT License
*
* Copyright (c) 2024 Salvatore Gonda
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/*
Module gobpmnHash is a simple implementation of the BPMN 2.0 hash algorithm.
Hash values are used to generate unique IDs for each element of a process.
* The hash value is generated using the crypto/rand package and the hash/fnv package to generate a 32-bit FNV-1a hash.
* The suffix is used to generate a unique ID for each element of a process.
Injections are used to inject hash values into the fields of a struct.
* The injectConfig method sets the bool type.
* The injectCurrentField method injects the current field with a hash value.
* The injectNextField method injects the next field with a hash value.
*/

package gobpmn_hash
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ module github.com/deemount/gobpmnHash

go 1.21.7

require github.com/deemount/gobpmnReflection v0.0.0-20240312074456-8746db163823
require (
github.com/deemount/gobpmnModels v0.0.0-20240316085912-7831ff39ffa4
github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d
)

require github.com/deemount/gobpmnTypes v0.0.0-20240315111519-43046016ad9f // indirect
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
github.com/deemount/gobpmnReflection v0.0.0-20240312074456-8746db163823 h1:I9O9SXz0sHqwDdZOso8frhpw2wPaiAG+SioKn/jLXFY=
github.com/deemount/gobpmnReflection v0.0.0-20240312074456-8746db163823/go.mod h1:NhbSOQE5lfqYvNkZXsm6xWTq3Wpy5xBPaERNqM/0OgI=
github.com/deemount/gobpmnModels v0.0.0-20240316085912-7831ff39ffa4 h1:xAqg4ZIeMDxME0O8O4UpwpcS3AeXB+3IspauNX2G2AA=
github.com/deemount/gobpmnModels v0.0.0-20240316085912-7831ff39ffa4/go.mod h1:bv2zkkqCzzaGV5gYP3gDQfMXuqjxMBjSl9GjHFo2mY8=
github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d h1:yQY4ikw/HuvVlPu3hGc0X8gntQnSbLqMnUw/nHRRCKU=
github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d/go.mod h1:j8WCmdzEkTq/FVsWJAdoPtjTiRryLZp/WjOLcIqtt5c=
github.com/deemount/gobpmnTypes v0.0.0-20240315111519-43046016ad9f h1:0gux6KtY8XgrN/L9tiZ7B+wx3th7x4hBYu1+wtUkHYY=
github.com/deemount/gobpmnTypes v0.0.0-20240315111519-43046016ad9f/go.mod h1:Dw7Jo8/vr0DzNHNMnbwQu0JSMWm2klNdo00rcxHCzJs=
6 changes: 2 additions & 4 deletions inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ import (
gobpmn_reflection "github.com/deemount/gobpmnReflection"
)

// Injection ...
// Injection contains the field Suffix, which holds the hash value for each field
type Injection struct {
Suffix string
}

// Inject itself reflects a given struct and inject
// signed fields with hash values.
// There are two conditions to assign fields of a struct:
// a) The struct has anonymous fields
// a) The struct has anonymous fields or
// b) The struct has no anymous fields
// It also counts the element in their specification to know
// how much elements of each package needs to be mapped later then.
func (injection *Injection) Inject(p interface{}) interface{} {

ref := gobpmn_reflection.New(p)
Expand Down
72 changes: 72 additions & 0 deletions inject_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package gobpmn_hash_test

import (
"testing"

gobpmn_hash "github.com/deemount/gobpmnHash"
"github.com/deemount/gobpmnModels/pkg/core"
)

type Injection struct {
Suffix string
}

type TestProcess struct {
Def core.DefinitionsRepository
IsExecutable bool
Process gobpmn_hash.Injection
StartEvent gobpmn_hash.Injection
FromStartEvent gobpmn_hash.Injection
Task gobpmn_hash.Injection
FromTask gobpmn_hash.Injection
EndEvent gobpmn_hash.Injection
}

type TestEmbeddedProcess struct {
Def core.DefinitionsRepository
TestEmbeddedPool
TestEmbeddedTenant
}

type TestEmbeddedPool struct {
XYZIsExecutable bool
XYZProcess gobpmn_hash.Injection
}

type TestEmbeddedTenant struct {
XYZStartEvent gobpmn_hash.Injection
}

func TestInject(t *testing.T) {
t.Log("TestInjectEmbedded")
var hash gobpmn_hash.Injection
p := hash.Inject(TestProcess{}).(TestProcess)
p.Def = core.NewDefinitions()
t.Logf("p: %#+v", p)
}

func TestInjectEmbedded(t *testing.T) {
t.Log("TestInjectEmbedded")
var hash gobpmn_hash.Injection
p := hash.Inject(TestEmbeddedProcess{}).(TestEmbeddedProcess)
p.Def = core.NewDefinitions()
t.Logf("p: %#+v", p)
}

func BenchmarkInject(b *testing.B) {
var hash gobpmn_hash.Injection
for n := 0; n < b.N; n++ {
p := hash.Inject(TestProcess{}).(TestProcess)
p.Def = core.NewDefinitions()
b.Logf("p: %#+v", p)
}
}

func BenchmarkInjectEmbedded(b *testing.B) {
var hash gobpmn_hash.Injection
for n := 0; n < b.N; n++ {
p := hash.Inject(TestEmbeddedProcess{}).(TestEmbeddedProcess)
p.Def = core.NewDefinitions()
b.Logf("p: %#+v", p)
}
}

0 comments on commit 2fc99d2

Please sign in to comment.