Skip to content

Commit

Permalink
Make bulid-tests work with newer testing lib
Browse files Browse the repository at this point in the history
We are using stubs for tests in escript, this will be not needed
once NeoEden is merged

Signed-off-by: Pavel Abramov <[email protected]>
  • Loading branch information
uncleDecart committed Oct 28, 2024
1 parent 96517df commit f5a82a5
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 67 deletions.
7 changes: 7 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ runs:
./eden setup -v debug --grub-options='set_global dom0_extra_args "$dom0_extra_args eve_install_zfs_with_raid_level "'
shell: bash
working-directory: "./eden"

- name: Start and Onboard
run: |
./eden start -v debug
./eden eve onboard -v debug
shell: bash
working-directory: "./eden"
3 changes: 1 addition & 2 deletions cmd/edenTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/lf-edge/eden/pkg/defaults"
"github.com/lf-edge/eden/pkg/openevec"
"github.com/lf-edge/eden/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -42,7 +41,7 @@ test <test_dir> -r <regexp> [-t <timewait>] [-v <level>]
}
}

vars, err := utils.InitVars()
vars, err := openevec.InitVarsFromConfig(cfg)

if err != nil {
return fmt.Errorf("error reading config: %s\n", err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/adam/adam.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ func (adam *Ctx) DeviceGetByOnboardUUID(onboardUUID string) (devUUID uuid.UUID,
if err != nil {
return uuid.Nil, err
}
fmt.Printf("LOOKING FOR %v\n", onboardUUID)
for _, devID := range devIDs {
fmt.Printf("DEVICE %v\n", devID)
devUUID, err := uuid.FromString(devID)
if err != nil {
return uuid.Nil, err
Expand Down
44 changes: 31 additions & 13 deletions pkg/openevec/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type EdenConfig struct {
EdenBin string `mapstructure:"eden-bin"`
TestBin string `mapstructure:"test-bin"`
TestScenario string `mapstructure:"test-scenario"`
Tests string `mapstructure:"tests" resolvepath:""`
Tests string `mapstructure:"tests"`

EServer EServerConfig `mapstructure:"eserver"`

Expand Down Expand Up @@ -134,8 +134,8 @@ type EveConfig struct {
Remote bool `mapstructure:"remote"`
RemoteAddr string `mapstructure:"remote-addr"`
ModelFile string `mapstructure:"devmodelfile" cobraflag:"devmodel-file"`
Cert string `mapstructure:"cert"`
DeviceCert string `mapstructure:"device-cert"`
Cert string `mapstructure:"cert" resolvepath:""`
DeviceCert string `mapstructure:"device-cert" resolvepath:""`
Name string `mapstructure:"name"`
AdamLogLevel string `mapstructure:"adam-log-level"`
LogLevel string `mapstructure:"log-level"`
Expand Down Expand Up @@ -376,35 +376,53 @@ func getValStrRepr(v reflect.Value) string {
}
}

func WriteConfig(dst reflect.Value, writer io.Writer, nestLevel int) {
func WriteConfig(dst reflect.Value, root string, writer io.Writer, nestLevel int) {

Check failure on line 379 in pkg/openevec/config.go

View workflow job for this annotation

GitHub Actions / yetus

revive: exported function WriteConfig should have comment or be unexported https://revive.run/r#exported
if dst.Kind() == reflect.Ptr {
dst = dst.Elem()
}

for i := 0; i < dst.NumField(); i++ {
if structTag := dst.Type().Field(i).Tag.Get("mapstructure"); structTag != "" {
io.WriteString(writer, strings.Repeat(" ", nestLevel))
switch dst.Field(i).Kind() {
f := dst.Field(i)
fieldType := dst.Type().Field(i)

switch f.Kind() {
case reflect.Struct:
io.WriteString(writer, structTag+":\n")
WriteConfig(dst.Field(i), writer, nestLevel+1)
// Pass the addressable value of the struct if it can be set, else create a pointer and pass
if f.CanAddr() {
WriteConfig(f.Addr(), root, writer, nestLevel+1)
} else {
WriteConfig(f, root, writer, nestLevel+1)
}
case reflect.Map:
io.WriteString(writer, structTag+":\n")
iter := dst.Field(i).MapRange()
iter := f.MapRange()
for iter.Next() {
k := iter.Key()
v := iter.Value()
io.WriteString(writer, strings.Repeat(" ", nestLevel+1))
// We assume that map cannot have structure as value
io.WriteString(writer, fmt.Sprintf("%v: %s\n", k.Interface(), getValStrRepr(v)))
}
case reflect.Slice:
io.WriteString(writer, structTag+":\n")
for j := 0; j < dst.Field(i).Len(); j++ {
for j := 0; j < f.Len(); j++ {
io.WriteString(writer, strings.Repeat(" ", nestLevel+1))
elem := dst.Field(i).Index(j)
elem := f.Index(j)
io.WriteString(writer, fmt.Sprintf("- %v\n", getValStrRepr(elem)))
}
case reflect.String: // we need to wrap string in quotes
io.WriteString(writer, fmt.Sprintf("%s: '%v'\n", structTag, dst.Field(i)))
case reflect.String:
if _, ok := fieldType.Tag.Lookup("resolvepath"); ok {
val := f.String()
// Check if field is addressable and can be set
trimmed := strings.TrimPrefix(val, root+"/")
fmt.Printf("Setting: %v for %v\n", val, trimmed)
f.SetString(trimmed) // Update the field value
}
io.WriteString(writer, fmt.Sprintf("%s: '%v'\n", structTag, f.Interface()))
default:
io.WriteString(writer, fmt.Sprintf("%s: %v\n", structTag, dst.Field(i)))
io.WriteString(writer, fmt.Sprintf("%s: %v\n", structTag, f.Interface()))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/openevec/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestViperSerializeFromWriteConfig(t *testing.T) {
}

var buf bytes.Buffer
openevec.WriteConfig(reflect.ValueOf(cfg), &buf, 0)
openevec.WriteConfig(reflect.ValueOf(cfg), "", &buf, 0)

v := viper.New()
v.SetConfigType("yaml")
Expand All @@ -80,7 +80,7 @@ func TestConfigSliceType(t *testing.T) {
}

var buf bytes.Buffer
openevec.WriteConfig(reflect.ValueOf(cfg), &buf, 0)
openevec.WriteConfig(reflect.ValueOf(cfg), "", &buf, 0)

v := viper.New()
v.SetConfigType("yaml")
Expand Down
33 changes: 3 additions & 30 deletions pkg/openevec/edenConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,6 @@ func ConfigAdd(cfg *EdenSetupArgs, currentContext, contextFile string, force boo
log.Debugf("current config already exists: %s", cfg.ConfigFile)
}
}
// if _, err = os.Stat(cfg.ConfigFile); os.IsNotExist(err) {

// dir := filepath.Dir(cfg.ConfigFile)
// if err = os.MkdirAll(dir, os.ModePerm); err != nil {
// return fmt.Errorf("Error creating folders %v", err)
// }

// file, err := os.Create(cfg.ConfigFile)
// if err != nil {
// return fmt.Errorf("Error creating file 111 %v", err)
// }
// defer file.Close()

// WriteConfig(reflect.ValueOf(*cfg), file, 0)

// log.Infof("Config file generated: %s", cfg.ConfigFile)
// }
// if err := ReloadConfigDetails(cfg); err != nil {
// return err
// }

context, err := utils.ContextLoad()
if err != nil {
Expand Down Expand Up @@ -124,12 +104,6 @@ func ConfigAdd(cfg *EdenSetupArgs, currentContext, contextFile string, force boo
}
}
context.SetContext(context.Current)
// if err := ReloadConfigDetails(cfg); err != nil {
// return err
// }

// we prepare viper config here from EdenSetupArgs
// to feed into GenerateConfigFileFromViper

if cfg.Eve.Arch != "" {
viper.Set("eve.arch", cfg.Eve.Arch)
Expand Down Expand Up @@ -161,11 +135,9 @@ func ConfigAdd(cfg *EdenSetupArgs, currentContext, contextFile string, force boo
}
defer file.Close()

WriteConfig(reflect.ValueOf(*cfg), file, 0)
fmt.Println("AAAAAA")
WriteConfig(reflect.ValueOf(cfg), cfg.Eden.Root, file, 0)

// if err = utils.GenerateConfigFileFromViper(); err != nil {
// return fmt.Errorf("error writing config: %w", err)
// }
context.SetContext(currentContextName)

return nil
Expand Down Expand Up @@ -341,6 +313,7 @@ func ConfigGet(target string, contextKeyGet string, contextAllGet bool) error {
fmt.Println(item)
}
case contextAllGet:
fmt.Println("OMAGAAAD")
if err = viper.WriteConfigAs(defaults.DefaultConfigHidden); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/openevec/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func InitVarsFromConfig(cfg *EdenSetupArgs) (*utils.ConfigVars, error) {
}

func Test(tstCfg *TestArgs) error {

fmt.Println("SOME TEST")
switch {
case tstCfg.TestList != "":
tests.RunTest(tstCfg.TestProg, []string{"-test.list", tstCfg.TestList}, "", tstCfg.TestTimeout, tstCfg.FailScenario, tstCfg.ConfigFile, tstCfg.Verbosity)
Expand Down
45 changes: 26 additions & 19 deletions tests/escript/go-internal/testscript/testing_1.18.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,31 @@ type corpusEntry = struct {
IsSeed bool
}

func (d nopTestDeps) CoordinateFuzzing(_ time.Duration, _ int64, _ time.Duration, _ int64, _ int, _ []corpusEntry, _ []reflect.Type, _ string, _ string) error {
func (nopTestDeps) SetPanicOnExit0(_ bool) {}

func (nopTestDeps) MatchString(_, _ string) (result bool, err error) {
return false, nil
}

func (nopTestDeps) StartCPUProfile(_ io.Writer) error {
return nil
}

func (nopTestDeps) StopCPUProfile() {}

func (nopTestDeps) StartTestLog(_ io.Writer) {}

func (nopTestDeps) StopTestLog() error {
return nil
}

func (nopTestDeps) WriteProfileTo(_ string, _ io.Writer, _ int) error {
return nil
}

func (d nopTestDeps) CoordinateFuzzing(_ time.Duration, _ int64, _ time.Duration, _ int64, _ int, _ []corpusEntry, _ []reflect.Type, _ string, _ string) error {
return nil
}
func (d nopTestDeps) RunFuzzWorker(_ func(corpusEntry) error) error {
return nil
}
Expand All @@ -48,29 +69,15 @@ func (d nopTestDeps) SnapshotCoverage() {
return
}

func (nopTestDeps) SetPanicOnExit0(_ bool) {}

func (nopTestDeps) MatchString(_, _ string) (result bool, err error) {
return false, nil
}

func (nopTestDeps) StartCPUProfile(_ io.Writer) error {
return nil
func (d nopTestDeps) InitRuntimeCoverage() (mode string, tearDown func(coverprofile string, gocoverdir string) (string, error), snapcov func() float64) {
tmp := func(_, _ string) (string, error) { return "", nil }
snapc := func() float64 { return 0 }
return "", tmp, snapc
}

func (nopTestDeps) StopCPUProfile() {}

func (nopTestDeps) WriteProfileTo(_ string, _ io.Writer, _ int) error {
return nil
}
func (nopTestDeps) ImportPath() string {
return ""
}
func (nopTestDeps) StartTestLog(_ io.Writer) {}

func (nopTestDeps) StopTestLog() error {
return nil
}

func getTestingMain() *testing.M {
return testing.MainStart(nopTestDeps{}, nil, nil, nil, nil)
Expand Down

0 comments on commit f5a82a5

Please sign in to comment.