kairos-agent/internal/agent/agent_test.go
Itxaka fbb64f2a82
Run tests in parallel and output github formats on workflow (#543)
* Run tests in parallel and output github formats on workflow

Signed-off-by: Itxaka <itxaka@kairos.io>

* Fix broken parallel tests

We were using a fixed file for the tests which several tests could be
accessing at the same time.

This fixes it by setting a temp random file at the test start

Signed-off-by: Itxaka <itxaka@kairos.io>

* Fix the tests logging to stdout

Signed-off-by: Itxaka <itxaka@kairos.io>

* Drop the verbose

Signed-off-by: Itxaka <itxaka@kairos.io>

* Fix agent test

Signed-off-by: Itxaka <itxaka@kairos.io>

* Let the event consumer create the logfile or whatever

Signed-off-by: Itxaka <itxaka@kairos.io>

* Drop Focus

Signed-off-by: Itxaka <itxaka@kairos.io>

---------

Signed-off-by: Itxaka <itxaka@kairos.io>
2024-09-17 17:51:11 +02:00

53 lines
1.2 KiB
Go

package agent_test
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
. "github.com/kairos-io/kairos-agent/v2/internal/agent"
"github.com/kairos-io/kairos-agent/v2/internal/bus"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
const testProvider = `#!/bin/bash
event="$1"
payload=$(</dev/stdin)
echo "Received $event with $payload" >> exec.log
echo "{}"
`
var _ = Describe("Bootstrap provider", func() {
Context("Config", func() {
It("gets entire content", func() {
f, err := ioutil.TempDir("", "tests")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(f)
wd, _ := os.Getwd()
os.WriteFile(filepath.Join(wd, "agent-provider-test"), []byte(testProvider), 0777)
defer os.RemoveAll(filepath.Join(wd, "agent-provider-test"))
err = os.WriteFile(filepath.Join(f, "test.config.yaml"), []byte(`#cloud-config
doo: bar`), 0655)
Expect(err).ToNot(HaveOccurred())
bus.Manager.Initialize()
err = Run(WithDirectory(f))
Expect(err).ToNot(HaveOccurred())
dat, err := os.ReadFile(filepath.Join(wd, "exec.log"))
Expect(err).ToNot(HaveOccurred())
fmt.Println(string(dat))
Expect(string(dat)).To(ContainSubstring("Received"), string(dat))
Expect(string(dat)).To(ContainSubstring("doo: bar"), string(dat))
})
})
})