Commit 848e6be3 authored by Denis Arh's avatar Denis Arh
Browse files

Fix actionlog type codegen

parent 6154d369
package actionlog
// Hello! This file is auto-generated.
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
// pkg/actionlog/types.yaml
type (
......@@ -39,3 +45,29 @@ func (set ActionSet) Filter(f func(*Action) (bool, error)) (out ActionSet, err e
return
}
// FindByID finds items from slice by its ID property
//
// This function is auto-generated.
func (set ActionSet) FindByID(ID uint64) *Action {
for i := range set {
if set[i].ID == ID {
return set[i]
}
}
return nil
}
// IDs returns a slice of uint64s from all items in the set
//
// This function is auto-generated.
func (set ActionSet) IDs() (IDs []uint64) {
IDs = make([]uint64, len(set))
for i := range set {
IDs[i] = set[i].ID
}
return
}
package actionlog
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
// pkg/actionlog/types.yaml
import (
"fmt"
"github.com/stretchr/testify/require"
"testing"
)
func TestActionSetWalk(t *testing.T) {
var (
value = make(ActionSet, 3)
req = require.New(t)
)
// check walk with no errors
{
err := value.Walk(func(*Action) error {
return nil
})
req.NoError(err)
}
// check walk with error
req.Error(value.Walk(func(*Action) error { return fmt.Errorf("walk error") }))
}
func TestActionSetFilter(t *testing.T) {
var (
value = make(ActionSet, 3)
req = require.New(t)
)
// filter nothing
{
set, err := value.Filter(func(*Action) (bool, error) {
return true, nil
})
req.NoError(err)
req.Equal(len(set), len(value))
}
// filter one item
{
found := false
set, err := value.Filter(func(*Action) (bool, error) {
if !found {
found = true
return found, nil
}
return false, nil
})
req.NoError(err)
req.Len(set, 1)
}
// filter error
{
_, err := value.Filter(func(*Action) (bool, error) {
return false, fmt.Errorf("filter error")
})
req.Error(err)
}
}
func TestActionSetIDs(t *testing.T) {
var (
value = make(ActionSet, 3)
req = require.New(t)
)
// construct objects
value[0] = new(Action)
value[1] = new(Action)
value[2] = new(Action)
// set ids
value[0].ID = 1
value[1].ID = 2
value[2].ID = 3
// Find existing
{
val := value.FindByID(2)
req.Equal(uint64(2), val.ID)
}
// Find non-existing
{
val := value.FindByID(4)
req.Nil(val)
}
// List IDs from set
{
val := value.IDs()
req.Equal(len(val), len(value))
}
}
package: actionlog
types:
Action:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment