mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-18 16:27:02 +00:00
robot: Add agent config bootstrap test
Signed-off-by: mudler <mudler@kairos.io>
This commit is contained in:
parent
c868bbaf9e
commit
836a039e6b
13
internal/agent/agent_suite_test.go
Normal file
13
internal/agent/agent_suite_test.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package agent_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfig(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "Agent Suite")
|
||||||
|
}
|
53
internal/agent/agent_test.go
Normal file
53
internal/agent/agent_test.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package agent_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
. "github.com/kairos-io/kairos/internal/agent"
|
||||||
|
"github.com/kairos-io/kairos/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()
|
||||||
|
fmt.Println(wd)
|
||||||
|
os.WriteFile(filepath.Join(wd, "agent-provider-test"), []byte(testProvider), 0655)
|
||||||
|
|
||||||
|
defer os.RemoveAll(filepath.Join(wd, "agent-provider-test"))
|
||||||
|
|
||||||
|
err = os.WriteFile(filepath.Join(f, "test.config.yaml"), []byte(`
|
||||||
|
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))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user