1
0
mirror of https://github.com/kairos-io/kairos-agent.git synced 2025-05-10 09:24:47 +00:00

robot: Add agent config bootstrap test

Signed-off-by: mudler <mudler@kairos.io>
This commit is contained in:
mudler 2022-11-27 14:34:36 +01:00 committed by Itxaka
parent c868bbaf9e
commit 836a039e6b
2 changed files with 66 additions and 0 deletions

View 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")
}

View 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))
})
})
})