Skip to content

Commit

Permalink
evetestkit : add error log function and more
Browse files Browse the repository at this point in the history
- add LogTimeErrorf
- add Ubuntu 20.04 app template

Signed-off-by: Shahriyar Jalayeri <[email protected]>
  • Loading branch information
shjala committed Oct 23, 2024
1 parent 35c7400 commit 1c66635
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/evetestkit/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const (
// AppDefaultCloudConfig is a default cloud-init configuration for the VM which just
// enables ssh password authentication and sets the password to "passw0rd".
AppDefaultCloudConfig = "#cloud-config\npassword: " + AppDefaultSSHPass + "\nchpasswd: { expire: False }\nssh_pwauth: True\n"
// Ubuntu2204 indicates the version of Ubuntu 22.04
Ubuntu2204 = "22.04"
// Ubuntu2004 indicates the version of Ubuntu 20.04
Ubuntu2004 = "20.04"
)

var (
Expand All @@ -46,6 +50,14 @@ var (
os: "ubuntu-server-cloudimg-amd64",
version: "22.04",
}
ubuntu2004 = fixedAppInstanceConfig{
appLink: "https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-amd64.img",
sshPort: "8027",
sshUser: AppDefaultSSHUser,
sshPass: AppDefaultSSHPass,
os: "ubuntu-server-cloudimg-amd64",
version: Ubuntu2004,
}
)

type fixedAppInstanceConfig struct {
Expand Down Expand Up @@ -578,6 +590,19 @@ func (node *EveNode) LogTimeInfof(format string, args ...interface{}) {
}
}

// LogTimeErrorf logs an error message with a timestamp, if it is called in the context
// of a test function it will call t.Fail and t.Logf, otherwise it will call fmt.Print
func (node *EveNode) LogTimeErrorf(format string, args ...interface{}) {
out := utils.AddTimestampf(format+"\n", args...)
if node.t != nil {
node.t.Fail()
node.t.Logf(out)
} else {
fmt.Print(out)
}
}

// SetTesting sets the testing.T object for the EveNode
func (node *EveNode) SetTesting(t *testing.T) {
node.t = t
}
Expand Down

0 comments on commit 1c66635

Please sign in to comment.