kairos/internal/agent/agent_test.go
Dimitris Karakasilis 0f9270ac07
Change module path according to Go docs (#1220)
https://go.dev/doc/modules/major-version

This way we can bump the kairos dependency on the provider-kairos repo

which otherwise produced the error:

```
~/workspace/kairos/provider-kairos (main)*$ go get -u github.com/kairos-io/kairos@v2.0.0-alpha3
go: github.com/kairos-io/kairos@v2.0.0-alpha3: invalid version: module contains a go.mod file, so module path must match major version ("github.com/kairos-io/kairos/v2")
```

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
Co-authored-by: Itxaka <itxaka.garcia@spectrocloud.com>
2023-03-30 14:18:53 +03:00

53 lines
1.2 KiB
Go

package agent_test
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
. "github.com/kairos-io/kairos/v2/internal/agent"
"github.com/kairos-io/kairos/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), 0655)
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))
})
})
})