Все проверки выполнены успешно
CI / test (push) Successful in 2m32s
Docker / Build and publish worker image (push) Successful in 18m17s
- reconnect safely after token rotation and retry leased results - reject malformed tasks and remove production cluster debug mutation - validate environment files and require immutable container images BREAKING CHANGE: Docker install, deploy, and Compose now require an immutable repository@sha256 image reference.
79 строки
2.1 KiB
Go
79 строки
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDispatchManagementCommand(t *testing.T) {
|
|
if handled, _ := dispatchManagementCommand(nil); handled {
|
|
t.Fatal("empty arguments were handled")
|
|
}
|
|
if handled, code := dispatchManagementCommand([]string{"install", "--help"}); !handled || code != 0 {
|
|
t.Fatalf("install help = handled %t code %d", handled, code)
|
|
}
|
|
}
|
|
|
|
func TestSecretValue(t *testing.T) {
|
|
path := t.TempDir() + "/secret"
|
|
if err := os.WriteFile(path, []byte("value\n"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := secretValue("", path)
|
|
if err != nil || got != "value" {
|
|
t.Fatalf("secretValue() = %q, %v", got, err)
|
|
}
|
|
}
|
|
|
|
func TestProbeLiveness(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
code int
|
|
want int
|
|
}{
|
|
{name: "healthy", code: http.StatusOK, want: 0},
|
|
{name: "unhealthy", code: http.StatusServiceUnavailable, want: 1},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
w.WriteHeader(tt.code)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
if got := probeLiveness(srv.URL); got != tt.want {
|
|
t.Fatalf("probeLiveness() = %d, want %d", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRemovedClusterDebugApplyTestConfigFlagIsRejected(t *testing.T) {
|
|
binary := filepath.Join(t.TempDir(), "rsmon-worker")
|
|
build := exec.Command("go", "build", "-o", binary, ".")
|
|
if output, err := build.CombinedOutput(); err != nil {
|
|
t.Fatalf("build worker binary: %v\n%s", err, output)
|
|
}
|
|
|
|
output, err := exec.Command(binary, "--cluster-debug-apply-test-config").CombinedOutput()
|
|
var exitErr *exec.ExitError
|
|
if !errors.As(err, &exitErr) {
|
|
t.Fatalf("removed flag error = %v, want parser exit\n%s", err, output)
|
|
}
|
|
if exitErr.ExitCode() != 2 {
|
|
t.Fatalf("removed flag exit code = %d, want 2\n%s", exitErr.ExitCode(), output)
|
|
}
|
|
if !strings.Contains(string(output), "flag provided but not defined: -cluster-debug-apply-test-config") {
|
|
t.Fatalf("removed flag output = %q, want undefined-flag error", output)
|
|
}
|
|
}
|