jx/cli_test.go
Matthew Rich 9f168cff85
Some checks failed
Lint / golangci-lint (push) Failing after 10m6s
Declarative Tests / test (push) Successful in 1m13s
fix lint errors
2024-04-21 23:24:38 -07:00

55 lines
1.2 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package main
import (
"github.com/stretchr/testify/assert"
"os"
"os/exec"
"testing"
"errors"
"log/slog"
"net/http"
"net/http/httptest"
"fmt"
)
func TestCli(t *testing.T) {
if _, e := os.Stat("./jx"); errors.Is(e, os.ErrNotExist) {
t.Skip("cli not built")
}
yaml, cliErr := exec.Command("./jx", "import", "--resource", "file://COPYRIGHT").Output()
slog.Info("TestCli", "err", cliErr)
assert.Nil(t, cliErr)
assert.NotEqual(t, "", string(yaml))
assert.Greater(t, len(yaml), 0)
}
func TestCliHTTPSource(t *testing.T) {
if _, e := os.Stat("./jx"); errors.Is(e, os.ErrNotExist) {
t.Skip("cli not built")
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `
resources:
- type: file
attributes:
path: foo.txt
owner: nobody
group: nobody
mode: 0644
content: |
test file
content
state: present
`)
}))
defer ts.Close()
yaml, cliErr := exec.Command("./jx", "import", "--resource", ts.URL).Output()
slog.Info("TestCliHTTPSource", "err", cliErr)
assert.Nil(t, cliErr)
assert.NotEqual(t, "", string(yaml))
assert.Greater(t, len(yaml), 0)
}