Skip to content

Commit e248217

Browse files
Fix command handling in test
1 parent cc75e7f commit e248217

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

pkg/cmd/agent/test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ func NewTestCmd(logger *log.Logger) *cobra.Command {
3838
nargs = len(args)
3939
manifest *client.Manifest
4040
)
41-
if nargs > 0 {
42-
submissionConfig.Image = args[0]
43-
}
44-
if nargs > 1 {
45-
submissionConfig.Command = args[1:]
46-
}
41+
4742
switch {
4843
case submissionConfig.SubmissionID != 0:
4944
cl, err := client.NewClient(logger, c.CredPath)
@@ -64,21 +59,30 @@ func NewTestCmd(logger *log.Logger) *cobra.Command {
6459
os.Exit(1)
6560
}
6661
default:
67-
if submissionConfig.Image == "" {
62+
if nargs == 0 {
6863
level.Error(logger).Log("msg", "either image, manifest path or submission id must be provided")
6964
os.Exit(1)
7065
}
7166
}
67+
68+
// If we have a manifest, args are commands, otherwise args are image and commands
69+
if manifest != nil {
70+
submissionConfig.Command = args
71+
} else {
72+
submissionConfig.Image = args[0]
73+
if nargs > 1 {
74+
submissionConfig.Command = args[1:]
75+
}
76+
}
7277
submission, err := submissionConfig.Submission(manifest)
7378
if err != nil {
7479
level.Error(logger).Log("msg", "failed to configure manifest", "err", err.Error())
7580
os.Exit(1)
7681
}
7782
if err := TestFn(logger, c, submission); err != nil {
78-
level.Error(logger).Log("msg", "failed to run agent", "err", err.Error())
83+
level.Error(logger).Log("msg", "failed to run agent", "err", err.Error(), "manifest", fmt.Sprintf("%#v", submission.Manifest))
7984
os.Exit(1)
8085
}
81-
8286
},
8387
}
8488
c.AddFlags(cmd.Flags())
@@ -87,7 +91,7 @@ func NewTestCmd(logger *log.Logger) *cobra.Command {
8791
}
8892

8993
func TestFn(logger *log.Logger, c *diambra.EnvConfig, submission *client.Submission) error {
90-
level.Debug(logger).Log("config", fmt.Sprintf("%#v", c))
94+
level.Debug(logger).Log("manifest", fmt.Sprintf("%#v", submission.Manifest), "config", fmt.Sprintf("%#v", c))
9195

9296
client, err := dclient.NewClientWithOpts(dclient.FromEnv, dclient.WithAPIVersionNegotiation())
9397
if err != nil {
@@ -101,7 +105,11 @@ func TestFn(logger *log.Logger, c *diambra.EnvConfig, submission *client.Submiss
101105
if err != nil {
102106
return fmt.Errorf("couldn't create DIAMBRA Env: %w", err)
103107
}
104-
108+
defer func() {
109+
if err := d.Cleanup(); err != nil {
110+
level.Error(logger).Log("msg", "Couldn't cleanup DIAMBRA Env", "err", err.Error())
111+
}
112+
}()
105113
level.Debug(logger).Log("msg", "starting DIAMBRA env")
106114
if err := d.Start(); err != nil {
107115
return fmt.Errorf("could't start DIAMBRA Env: %w", err)

pkg/diambra/agents/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewConfig(logger log.Logger) (*Config, error) {
6363
return nil, err
6464
}
6565
}
66-
level.Debug(logger).Log("msg", "using diambra-arena version", "version", strings.Join(parts, "."))
66+
level.Debug(logger).Log("msg", "using diambra-engine version", "version", strings.Join(parts, "."))
6767
return &Config{
6868
Arena: ArenaConfig{
6969
Version: strings.Join(parts, "."),

0 commit comments

Comments
 (0)