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
}
// Read/WriteCache functions to fullfill [impl->dsn~protocol-collection-cache~0>>utest]
// WriteCache updates the cache file of the available protocols
func (pcl *ProtocolCollectionList) WriteCache() error {
// [impl->dsn~protocol-collection-cache~0>>utest]
cops := []string{}
for _, pc := range pcl.PCs {
str, err := pc.ToJSON()
@ -89,7 +90,6 @@ func (pcl *ProtocolCollectionList) WriteCache() error {
// ReadCache reads the cache for display
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,
// 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))

View File

@ -113,6 +113,7 @@ func TestGlobalCOP(t *testing.T) {
}
func TestCOPCache(t *testing.T) {
// [utest->impl~protocol-collection-cache~0]
td := setupSuite(t)
defer td(t)
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
type ProtocolCollectionEntry struct {
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.

View File

@ -27,8 +27,9 @@ var CollectionOfProtocolsDir string
// COPCacheFileName is the filename for the cache
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
// 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
type Packet struct {
MetaData Metadata
MetaData Meta
data []byte
Hex string
B64 string

View File

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

View File

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

View File

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

View File

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

View File

@ -9,9 +9,9 @@ import (
// Protocol structure
type Protocol struct {
Metadata ProtocolMeta
Metadata Meta
Structure []*Field
DefaultValues []DefaultValue
DefaultValues []DefaultValues
JavaScript string
}
@ -95,7 +95,7 @@ func (prot *Protocol) RemoveFieldByElement(field int) {
ret := make([]*Field, 0)
for i, f := range prot.Structure {
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)
}
}

View File

@ -62,7 +62,7 @@ func GenerateStructure() *Protocol {
slc := GenerateFields()
p.AppendFields(slc...)
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.")
return p
@ -108,7 +108,7 @@ func TestUpdateFieldByName(t *testing.T) {
)
p.UpdateFieldByName("testfield3", f)
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 {
t.Log("Update field by Ref failed!")
@ -122,7 +122,7 @@ func TestUpdateFieldByElement(t *testing.T) {
)
p.UpdateFieldByElement(5, f)
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 {
t.Log("Update field by Ref failed!")
@ -134,7 +134,7 @@ func TestRemoveFieldByName(t *testing.T) {
p := GenerateStructure()
p.RemoveFieldByName("testfield3")
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" {
t.Log("Remove by name failed!")
@ -146,7 +146,7 @@ func TestRemoveFieldByElement(t *testing.T) {
p := GenerateStructure()
p.RemoveFieldByElement(3)
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" {
t.Log("Remove by element failed!")

View File

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