Fix comments and OpenFastTrace-ability
Go / lint (push) Failing after 6s Details
Go / build (push) Failing after 6s Details

This commit is contained in:
Marcel M. Otte 2023-11-10 13:48:47 +01:00
parent 680d64fc21
commit a89787613e
12 changed files with 30 additions and 19 deletions

View File

@ -71,9 +71,10 @@ func GetCOP() *ProtocolCollectionList {
return GlobalCOP return GlobalCOP
} }
// Read/WriteCache functions to fullfill [impl->dsn~protocol-collection-cache~0>>utest]
// WriteCache updates the cache file of the available protocols // WriteCache updates the cache file of the available protocols
func (pcl *ProtocolCollectionList) WriteCache() error { func (pcl *ProtocolCollectionList) WriteCache() error {
// [impl->dsn~protocol-collection-cache~0>>utest]
cops := []string{} cops := []string{}
for _, pc := range pcl.PCs { for _, pc := range pcl.PCs {
str, err := pc.ToJSON() str, err := pc.ToJSON()
@ -89,7 +90,6 @@ func (pcl *ProtocolCollectionList) WriteCache() error {
// ReadCache reads the cache for display // ReadCache reads the cache for display
func (pcl *ProtocolCollectionList) ReadCache() error { func (pcl *ProtocolCollectionList) ReadCache() error {
// [impl->dsn~protocol-collection-cache~0>>utest]
// TODO: Think about if it makes sense to have this function as a member of PCL, // TODO: Think about if it makes sense to have this function as a member of PCL,
// or if it makes more sense to make this function standalone and return a new PCL? // or if it makes more sense to make this function standalone and return a new PCL?
data, err := os.ReadFile(path.Join(globals.CollectionOfProtocolsDir, globals.COPCacheFileName)) data, err := os.ReadFile(path.Join(globals.CollectionOfProtocolsDir, globals.COPCacheFileName))

View File

@ -113,6 +113,7 @@ func TestGlobalCOP(t *testing.T) {
} }
func TestCOPCache(t *testing.T) { func TestCOPCache(t *testing.T) {
// [utest->impl~protocol-collection-cache~0]
td := setupSuite(t) td := setupSuite(t)
defer td(t) defer td(t)
gcop := cop.GlobalCOP gcop := cop.GlobalCOP

View File

@ -16,7 +16,7 @@ type COP struct {
// ProtocolCollectionEntry is a single entry in the file database, additionally to the meta data the path is required // ProtocolCollectionEntry is a single entry in the file database, additionally to the meta data the path is required
type ProtocolCollectionEntry struct { type ProtocolCollectionEntry struct {
Path string Path string
Protocol protocol.ProtocolMeta Protocol protocol.Meta
} }
// A collection entry has a path, which is meant to be a filesystem path, but doesn't necessarily have to be. // A collection entry has a path, which is meant to be a filesystem path, but doesn't necessarily have to be.

View File

@ -27,8 +27,9 @@ var CollectionOfProtocolsDir string
// COPCacheFileName is the filename for the cache // COPCacheFileName is the filename for the cache
var COPCacheFileName string = "cop-cache.json" var COPCacheFileName string = "cop-cache.json"
// Global Mockings ////////////// Global Mockings
// MockUserCurrent is a variable to be able to mock the function call to `user.Current`
var MockUserCurrent = user.Current var MockUserCurrent = user.Current
// Marshaler interface to enrich structs which can be exported/imported even with private fields // Marshaler interface to enrich structs which can be exported/imported even with private fields

View File

@ -42,7 +42,7 @@ type Layer struct {
// Packet contains all layers of a packet and the data in different formats // Packet contains all layers of a packet and the data in different formats
type Packet struct { type Packet struct {
MetaData Metadata MetaData Meta
data []byte data []byte
Hex string Hex string
B64 string B64 string

View File

@ -1,7 +1,7 @@
package packet package packet
// Metadata struct is the absolute minimum of metadata // Meta struct is the absolute minimum of metadata
type Metadata struct { type Meta struct {
Name string Name string
Revision int Revision int
} }

View File

@ -1,5 +1,6 @@
package protocol package protocol
// DefaultFieldValue represents a default value for a field identified in a protocol by its name.
type DefaultFieldValue struct { type DefaultFieldValue struct {
FieldRef string FieldRef string
Value string Value string

View File

@ -1,6 +1,7 @@
package protocol package protocol
type DefaultValue struct { // DefaultValues for protocols
type DefaultValues struct {
Desc string Desc string
FieldValues []DefaultFieldValue FieldValues []DefaultFieldValue
} }

View File

@ -2,6 +2,7 @@ package protocol
import "encoding/json" import "encoding/json"
// Field holds all necessary data for a field in a protocol
type Field struct { type Field struct {
Name string // Name of the Field Name string // Name of the Field
Desc string // Lengthy description Desc string // Lengthy description
@ -13,12 +14,14 @@ type Field struct {
JavaScript string JavaScript string
} }
type ProtocolFieldReferencer interface { // FieldReferencer interface
type FieldReferencer interface {
GetProtocolField() *Field GetProtocolField() *Field
SetProtocolField(f *Field) SetProtocolField(f *Field)
} }
func (f *Field) ToJson() string { // ToJSON converts a field to a JSON string
func (f *Field) ToJSON() string {
b, err := json.Marshal(*f) b, err := json.Marshal(*f)
if err != nil { if err != nil {
return "" return ""
@ -26,11 +29,13 @@ func (f *Field) ToJson() string {
return string(b) return string(b)
} }
// NewEmptyField just creates a new Field with no data
func NewEmptyField() *Field { func NewEmptyField() *Field {
f := Field{} f := Field{}
return &f return &f
} }
// NewField creates a new Field with all data possible
func NewField( func NewField(
name string, name string,
desc string, desc string,

View File

@ -9,9 +9,9 @@ import (
// Protocol structure // Protocol structure
type Protocol struct { type Protocol struct {
Metadata ProtocolMeta Metadata Meta
Structure []*Field Structure []*Field
DefaultValues []DefaultValue DefaultValues []DefaultValues
JavaScript string JavaScript string
} }
@ -95,7 +95,7 @@ func (prot *Protocol) RemoveFieldByElement(field int) {
ret := make([]*Field, 0) ret := make([]*Field, 0)
for i, f := range prot.Structure { for i, f := range prot.Structure {
if i != field { if i != field {
fmt.Printf("appending %d, %s\n", i, f.ToJson()) fmt.Printf("appending %d, %s\n", i, f.ToJSON())
ret = append(ret, f) ret = append(ret, f)
} }
} }

View File

@ -62,7 +62,7 @@ func GenerateStructure() *Protocol {
slc := GenerateFields() slc := GenerateFields()
p.AppendFields(slc...) p.AppendFields(slc...)
for i, e := range p.Structure { for i, e := range p.Structure {
fmt.Printf("%d %s\n", i, e.ToJson()) fmt.Printf("%d %s\n", i, e.ToJSON())
} }
fmt.Println("Generated Structure.") fmt.Println("Generated Structure.")
return p return p
@ -108,7 +108,7 @@ func TestUpdateFieldByName(t *testing.T) {
) )
p.UpdateFieldByName("testfield3", f) p.UpdateFieldByName("testfield3", f)
for i, e := range p.Structure { for i, e := range p.Structure {
fmt.Printf("%d %s\n", i, e.ToJson()) fmt.Printf("%d %s\n", i, e.ToJSON())
} }
if p.Structure[3].Desc != "" || p.Structure[3].Size != 42 { if p.Structure[3].Desc != "" || p.Structure[3].Size != 42 {
t.Log("Update field by Ref failed!") t.Log("Update field by Ref failed!")
@ -122,7 +122,7 @@ func TestUpdateFieldByElement(t *testing.T) {
) )
p.UpdateFieldByElement(5, f) p.UpdateFieldByElement(5, f)
for i, e := range p.Structure { for i, e := range p.Structure {
fmt.Printf("%d %s\n", i, e.ToJson()) fmt.Printf("%d %s\n", i, e.ToJSON())
} }
if p.Structure[5].Desc != "" || p.Structure[5].Size != 42 { if p.Structure[5].Desc != "" || p.Structure[5].Size != 42 {
t.Log("Update field by Ref failed!") t.Log("Update field by Ref failed!")
@ -134,7 +134,7 @@ func TestRemoveFieldByName(t *testing.T) {
p := GenerateStructure() p := GenerateStructure()
p.RemoveFieldByName("testfield3") p.RemoveFieldByName("testfield3")
for i, e := range p.Structure { for i, e := range p.Structure {
fmt.Printf("%d %s\n", i, e.ToJson()) fmt.Printf("%d %s\n", i, e.ToJSON())
} }
if p.Structure[3].Name != "testfield4" { if p.Structure[3].Name != "testfield4" {
t.Log("Remove by name failed!") t.Log("Remove by name failed!")
@ -146,7 +146,7 @@ func TestRemoveFieldByElement(t *testing.T) {
p := GenerateStructure() p := GenerateStructure()
p.RemoveFieldByElement(3) p.RemoveFieldByElement(3)
for i, e := range p.Structure { for i, e := range p.Structure {
fmt.Printf("%d %s\n", i, e.ToJson()) fmt.Printf("%d %s\n", i, e.ToJSON())
} }
if p.Structure[3].Name != "testfield4" { if p.Structure[3].Name != "testfield4" {
t.Log("Remove by element failed!") t.Log("Remove by element failed!")

View File

@ -1,6 +1,7 @@
package protocol package protocol
type ProtocolMeta struct { // Meta holds the metadata of a protocol
type Meta struct {
Name string Name string
Revision uint Revision uint
Version string Version string
@ -11,6 +12,7 @@ type ProtocolMeta struct {
LowerLayerIdentification map[string]string LowerLayerIdentification map[string]string
} }
// UpdateMetaData updates the full metadata of a protocol
func UpdateMetaData( func UpdateMetaData(
prot *Protocol, prot *Protocol,
name string, name string,