Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions internal/agent/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/osapi-io/osapi/internal/agent/identity"
"github.com/osapi-io/osapi/internal/agent/pki"
"github.com/osapi-io/osapi/internal/config"
"github.com/osapi-io/osapi/internal/exec"
"github.com/osapi-io/osapi/internal/job"
"github.com/osapi-io/osapi/internal/provider/command"
dockerProv "github.com/osapi-io/osapi/internal/provider/container/docker"
Expand Down Expand Up @@ -400,15 +399,6 @@ func ResetProcStatusPath() {
procStatusPath = "/proc/self/status"
}

// ExportCheckSudoAccess exposes the private checkSudoAccess function for testing.
func ExportCheckSudoAccess(
logger *slog.Logger,
execManager exec.Manager,
) []PreflightResult {
return checkSudoAccess(logger, execManager)
}

// ExportCheckCapabilities exposes the private checkCapabilities function for testing.
func ExportCheckCapabilities(
logger *slog.Logger,
) []PreflightResult {
Expand Down
61 changes: 0 additions & 61 deletions internal/agent/preflight_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,67 +62,6 @@ func (s *PreflightPublicTestSuite) TearDownSubTest() {
agent.ResetProcStatusPath()
}

func (s *PreflightPublicTestSuite) TestCheckSudoAccess() {
tests := []struct {
name string
setupMock func()
validateFunc func([]agent.PreflightResult)
}{
{
name: "when all commands pass",
setupMock: func() {
s.mockExecMgr.EXPECT().
RunCmd("sudo", gomock.Any()).
Return("/usr/bin/something", nil).
AnyTimes()
},
validateFunc: func(results []agent.PreflightResult) {
s.NotEmpty(results)
for _, r := range results {
s.True(r.Passed, "expected %s to pass", r.Name)
s.Empty(r.Error)
}
},
},
{
name: "when one command fails",
setupMock: func() {
s.mockExecMgr.EXPECT().
RunCmd("sudo", gomock.Any()).
DoAndReturn(func(_ string, args []string) (string, error) {
if len(args) == 3 && args[2] == "systemctl" {
return "", fmt.Errorf("sudo: a password is required")
}
return "/usr/bin/something", nil
}).
AnyTimes()
},
validateFunc: func(results []agent.PreflightResult) {
s.NotEmpty(results)

var failCount int
for _, r := range results {
if !r.Passed {
failCount++
s.Equal("sudo:systemctl", r.Name)
s.Contains(r.Error, "sudo -n which systemctl")
}
}

s.Equal(1, failCount, "expected exactly one failure")
},
},
}

for _, tc := range tests {
s.Run(tc.name, func() {
tc.setupMock()
results := agent.ExportCheckSudoAccess(s.logger, s.mockExecMgr)
tc.validateFunc(results)
})
}
}

func (s *PreflightPublicTestSuite) TestCheckCapabilities() {
tests := []struct {
name string
Expand Down
7 changes: 0 additions & 7 deletions internal/controller/api/file/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,3 @@
// DEALINGS IN THE SOFTWARE.

package file

// ExportValidateFileName exposes the private validateFileName for testing.
func ExportValidateFileName(
name string,
) (string, bool) {
return validateFileName(name)
}
86 changes: 0 additions & 86 deletions internal/controller/api/file/validate_public_test.go

This file was deleted.

31 changes: 0 additions & 31 deletions internal/controller/api/node/docker/convert_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,6 @@ type ConvertPublicTestSuite struct {
suite.Suite
}

func (s *ConvertPublicTestSuite) TestStringPtrOrNil() {
tests := []struct {
name string
input string
validateFunc func(result *string)
}{
{
name: "when empty string returns nil",
input: "",
validateFunc: func(result *string) {
s.Nil(result)
},
},
{
name: "when non-empty string returns pointer",
input: "hello",
validateFunc: func(result *string) {
s.Require().NotNil(result)
s.Equal("hello", *result)
},
},
}

for _, tt := range tests {
s.Run(tt.name, func() {
result := container.ExportStringPtrOrNil(tt.input)
tt.validateFunc(result)
})
}
}

func (s *ConvertPublicTestSuite) TestPtrToSlice() {
tests := []struct {
name string
Expand Down
8 changes: 0 additions & 8 deletions internal/controller/api/node/docker/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ package container

import "github.com/osapi-io/osapi/internal/job"

// ExportStringPtrOrNil exposes the private stringPtrOrNil for testing.
func ExportStringPtrOrNil(
s string,
) *string {
return stringPtrOrNil(s)
}

// ExportPtrToSlice exposes the private ptrToSlice for testing.
func ExportPtrToSlice(
s *[]string,
) []string {
Expand Down
8 changes: 0 additions & 8 deletions internal/controller/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ func ExportDeregister(
h.deregister()
}

// ExportRegistryKey exposes the private registryKey method for testing.
func ExportRegistryKey(
h *ComponentHeartbeat,
) string {
return h.registryKey()
}

// SetHeartbeatThresholds sets the thresholds field on ComponentHeartbeat for testing.
func SetHeartbeatThresholds(
h *ComponentHeartbeat,
thresholds process.ConditionThresholds,
Expand Down
45 changes: 0 additions & 45 deletions internal/controller/heartbeat_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,51 +366,6 @@ func (s *HeartbeatPublicTestSuite) TestStart() {
}
}

func (s *HeartbeatPublicTestSuite) TestRegistryKey() {
tests := []struct {
name string
componentType string
hostname string
expected string
}{
{
name: "simple hostname",
componentType: "api",
hostname: "web-01",
expected: "api.web_01",
},
{
name: "hostname with dots",
componentType: "api",
hostname: "Johns-MacBook-Pro.local",
expected: "api.Johns_MacBook_Pro_local",
},
{
name: "nats component type",
componentType: "nats",
hostname: "nats-server-01",
expected: "nats.nats_server_01",
},
}

for _, tt := range tests {
s.Run(tt.name, func() {
hb := controller.NewComponentHeartbeat(
slog.Default(),
s.mockKV,
tt.hostname,
"0.1.0",
tt.componentType,
s.mockProcess,
10*time.Second,
process.ConditionThresholds{},
nil,
)
s.Equal(tt.expected, controller.ExportRegistryKey(hb))
})
}
}

func TestHeartbeatPublicTestSuite(t *testing.T) {
suite.Run(t, new(HeartbeatPublicTestSuite))
}
63 changes: 0 additions & 63 deletions pkg/sdk/client/agent_types_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,69 +329,6 @@ func (suite *AgentTypesPublicTestSuite) TestAgentListFromGen() {
}
}

func (suite *AgentTypesPublicTestSuite) TestPendingAgentListFromGen() {
now := time.Now().UTC().Truncate(time.Second)

tests := []struct {
name string
input *gen.ListPendingAgentsResponse
validateFunc func(client.PendingAgentList)
}{
{
name: "when list contains pending agents",
input: &gen.ListPendingAgentsResponse{
Agents: []gen.PendingAgentInfo{
{
MachineId: "machine-001",
Hostname: "web-01",
Fingerprint: "SHA256:abc123",
RequestedAt: now,
},
{
MachineId: "machine-002",
Hostname: "web-02",
Fingerprint: "SHA256:def456",
RequestedAt: now.Add(-5 * time.Minute),
},
},
Total: 2,
},
validateFunc: func(pl client.PendingAgentList) {
suite.Equal(2, pl.Total)
suite.Require().Len(pl.Agents, 2)

suite.Equal("machine-001", pl.Agents[0].MachineID)
suite.Equal("web-01", pl.Agents[0].Hostname)
suite.Equal("SHA256:abc123", pl.Agents[0].Fingerprint)
suite.Equal(now, pl.Agents[0].RequestedAt)

suite.Equal("machine-002", pl.Agents[1].MachineID)
suite.Equal("web-02", pl.Agents[1].Hostname)
suite.Equal("SHA256:def456", pl.Agents[1].Fingerprint)
suite.Equal(now.Add(-5*time.Minute), pl.Agents[1].RequestedAt)
},
},
{
name: "when list is empty",
input: &gen.ListPendingAgentsResponse{
Agents: []gen.PendingAgentInfo{},
Total: 0,
},
validateFunc: func(pl client.PendingAgentList) {
suite.Equal(0, pl.Total)
suite.Empty(pl.Agents)
},
},
}

for _, tc := range tests {
suite.Run(tc.name, func() {
result := client.ExportPendingAgentListFromGen(tc.input)
tc.validateFunc(result)
})
}
}

func TestAgentTypesPublicTestSuite(t *testing.T) {
suite.Run(t, new(AgentTypesPublicTestSuite))
}
Loading
Loading