diff --git a/internal/agent/export_test.go b/internal/agent/export_test.go index a51841d4b..70b2a211c 100644 --- a/internal/agent/export_test.go +++ b/internal/agent/export_test.go @@ -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" @@ -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 { diff --git a/internal/agent/preflight_public_test.go b/internal/agent/preflight_public_test.go index 02cd94ab9..a9e140b07 100644 --- a/internal/agent/preflight_public_test.go +++ b/internal/agent/preflight_public_test.go @@ -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 diff --git a/internal/controller/api/file/export_test.go b/internal/controller/api/file/export_test.go index 47414a959..75a170967 100644 --- a/internal/controller/api/file/export_test.go +++ b/internal/controller/api/file/export_test.go @@ -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) -} diff --git a/internal/controller/api/file/validate_public_test.go b/internal/controller/api/file/validate_public_test.go deleted file mode 100644 index 15bb479d7..000000000 --- a/internal/controller/api/file/validate_public_test.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2026 John Dewey - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -package file_test - -import ( - "strings" - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/osapi-io/osapi/internal/controller/api/file" -) - -type ValidateFilePublicTestSuite struct { - suite.Suite -} - -func (suite *ValidateFilePublicTestSuite) TestValidateFileName() { - tests := []struct { - name string - input string - valid bool - }{ - { - name: "when valid name", - input: "nginx.conf", - valid: true, - }, - { - name: "when valid name with path chars", - input: "app.conf.tmpl", - valid: true, - }, - { - name: "when empty name", - input: "", - valid: false, - }, - { - name: "when name exceeds 255 chars", - input: strings.Repeat("a", 256), - valid: false, - }, - { - name: "when name at max 255 chars", - input: strings.Repeat("a", 255), - valid: true, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - errMsg, ok := file.ExportValidateFileName(tc.input) - - if tc.valid { - suite.True(ok) - suite.Empty(errMsg) - } else { - suite.False(ok) - suite.NotEmpty(errMsg) - } - }) - } -} - -func TestValidateFilePublicTestSuite(t *testing.T) { - suite.Run(t, new(ValidateFilePublicTestSuite)) -} diff --git a/internal/controller/api/node/docker/convert_public_test.go b/internal/controller/api/node/docker/convert_public_test.go index bda4b99b9..9dbe8ed1d 100644 --- a/internal/controller/api/node/docker/convert_public_test.go +++ b/internal/controller/api/node/docker/convert_public_test.go @@ -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 diff --git a/internal/controller/api/node/docker/export_test.go b/internal/controller/api/node/docker/export_test.go index e8f47abd9..86fef784e 100644 --- a/internal/controller/api/node/docker/export_test.go +++ b/internal/controller/api/node/docker/export_test.go @@ -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 { diff --git a/internal/controller/export_test.go b/internal/controller/export_test.go index 736bcefc0..6dba489cd 100644 --- a/internal/controller/export_test.go +++ b/internal/controller/export_test.go @@ -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, diff --git a/internal/controller/heartbeat_public_test.go b/internal/controller/heartbeat_public_test.go index d62e06c9d..dfd46083e 100644 --- a/internal/controller/heartbeat_public_test.go +++ b/internal/controller/heartbeat_public_test.go @@ -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)) } diff --git a/pkg/sdk/client/agent_types_public_test.go b/pkg/sdk/client/agent_types_public_test.go index 5483e4566..1c8df24d8 100644 --- a/pkg/sdk/client/agent_types_public_test.go +++ b/pkg/sdk/client/agent_types_public_test.go @@ -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)) } diff --git a/pkg/sdk/client/collection_public_test.go b/pkg/sdk/client/collection_public_test.go index 864634a17..278cb4963 100644 --- a/pkg/sdk/client/collection_public_test.go +++ b/pkg/sdk/client/collection_public_test.go @@ -23,7 +23,6 @@ package client_test import ( "testing" - openapi_types "github.com/oapi-codegen/runtime/types" "github.com/stretchr/testify/suite" "github.com/osapi-io/osapi/pkg/sdk/client" @@ -33,197 +32,6 @@ type CollectionPublicTestSuite struct { suite.Suite } -func (suite *CollectionPublicTestSuite) TestDerefString() { - s := "hello" - - tests := []struct { - name string - input *string - validateFunc func(string) - }{ - { - name: "when pointer is non-nil", - input: &s, - validateFunc: func(result string) { - suite.Equal("hello", result) - }, - }, - { - name: "when pointer is nil", - input: nil, - validateFunc: func(result string) { - suite.Empty(result) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - tc.validateFunc(client.ExportDerefString(tc.input)) - }) - } -} - -func (suite *CollectionPublicTestSuite) TestDerefInt() { - i := 42 - - tests := []struct { - name string - input *int - validateFunc func(int) - }{ - { - name: "when pointer is non-nil", - input: &i, - validateFunc: func(result int) { - suite.Equal(42, result) - }, - }, - { - name: "when pointer is nil", - input: nil, - validateFunc: func(result int) { - suite.Zero(result) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - tc.validateFunc(client.ExportDerefInt(tc.input)) - }) - } -} - -func (suite *CollectionPublicTestSuite) TestDerefInt64() { - i := int64(42) - - tests := []struct { - name string - input *int64 - validateFunc func(int64) - }{ - { - name: "when pointer is non-nil", - input: &i, - validateFunc: func(result int64) { - suite.Equal(int64(42), result) - }, - }, - { - name: "when pointer is nil", - input: nil, - validateFunc: func(result int64) { - suite.Zero(result) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - tc.validateFunc(client.ExportDerefInt64(tc.input)) - }) - } -} - -func (suite *CollectionPublicTestSuite) TestDerefFloat64() { - f := 3.14 - - tests := []struct { - name string - input *float64 - validateFunc func(float64) - }{ - { - name: "when pointer is non-nil", - input: &f, - validateFunc: func(result float64) { - suite.InDelta(3.14, result, 0.001) - }, - }, - { - name: "when pointer is nil", - input: nil, - validateFunc: func(result float64) { - suite.InDelta(0.0, result, 0.001) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - tc.validateFunc(client.ExportDerefFloat64(tc.input)) - }) - } -} - -func (suite *CollectionPublicTestSuite) TestDerefBool() { - b := true - - tests := []struct { - name string - input *bool - validateFunc func(bool) - }{ - { - name: "when pointer is non-nil", - input: &b, - validateFunc: func(result bool) { - suite.True(result) - }, - }, - { - name: "when pointer is nil", - input: nil, - validateFunc: func(result bool) { - suite.False(result) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - tc.validateFunc(client.ExportDerefBool(tc.input)) - }) - } -} - -func (suite *CollectionPublicTestSuite) TestJobIDFromGen() { - id := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *openapi_types.UUID - validateFunc func(string) - }{ - { - name: "when pointer is non-nil", - input: &id, - validateFunc: func(result string) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", result) - }, - }, - { - name: "when pointer is nil", - input: nil, - validateFunc: func(result string) { - suite.Empty(result) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - tc.validateFunc(client.ExportJobIDFromGen(tc.input)) - }) - } -} - func (suite *CollectionPublicTestSuite) TestCollectionFirst() { tests := []struct { name string diff --git a/pkg/sdk/client/command_types_public_test.go b/pkg/sdk/client/command_types_public_test.go deleted file mode 100644 index d3419e84e..000000000 --- a/pkg/sdk/client/command_types_public_test.go +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) 2026 John Dewey - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -package client_test - -import ( - "testing" - - openapi_types "github.com/oapi-codegen/runtime/types" - "github.com/stretchr/testify/suite" - - "github.com/osapi-io/osapi/pkg/sdk/client" - "github.com/osapi-io/osapi/pkg/sdk/client/gen" -) - -type CommandTypesPublicTestSuite struct { - suite.Suite -} - -func (suite *CommandTypesPublicTestSuite) TestCommandCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.CommandResultCollectionResponse - validateFunc func(client.Collection[client.CommandResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.CommandResultCollectionResponse { - stdout := "hello world\n" - stderr := "warning: something\n" - exitCode := 0 - changed := true - durationMs := int64(150) - - return &gen.CommandResultCollectionResponse{ - JobId: &testUUID, - Results: []gen.CommandResultItem{ - { - Hostname: "web-01", - Stdout: &stdout, - Stderr: &stderr, - ExitCode: &exitCode, - Changed: &changed, - DurationMs: &durationMs, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.CommandResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - cr := c.Results[0] - suite.Equal("web-01", cr.Hostname) - suite.Equal("hello world\n", cr.Stdout) - suite.Equal("warning: something\n", cr.Stderr) - suite.Empty(cr.Error) - suite.Equal(0, cr.ExitCode) - suite.True(cr.Changed) - suite.Equal(int64(150), cr.DurationMs) - }, - }, - { - name: "when minimal with error", - input: func() *gen.CommandResultCollectionResponse { - errMsg := "command not found" - exitCode := 127 - - return &gen.CommandResultCollectionResponse{ - Results: []gen.CommandResultItem{ - { - Hostname: "web-01", - Error: &errMsg, - ExitCode: &exitCode, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.CommandResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - - cr := c.Results[0] - suite.Equal("web-01", cr.Hostname) - suite.Equal("command not found", cr.Error) - suite.Equal(127, cr.ExitCode) - suite.Empty(cr.Stdout) - suite.Empty(cr.Stderr) - suite.False(cr.Changed) - suite.Zero(cr.DurationMs) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportCommandCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func TestCommandTypesPublicTestSuite(t *testing.T) { - suite.Run(t, new(CommandTypesPublicTestSuite)) -} diff --git a/pkg/sdk/client/disk_types_public_test.go b/pkg/sdk/client/disk_types_public_test.go index dba044c57..d71c6819c 100644 --- a/pkg/sdk/client/disk_types_public_test.go +++ b/pkg/sdk/client/disk_types_public_test.go @@ -23,7 +23,6 @@ package client_test import ( "testing" - openapi_types "github.com/oapi-codegen/runtime/types" "github.com/stretchr/testify/suite" "github.com/osapi-io/osapi/pkg/sdk/client" @@ -98,88 +97,6 @@ func (suite *DiskTypesPublicTestSuite) TestDisksFromGen() { } } -func (suite *DiskTypesPublicTestSuite) TestDiskCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.DiskCollectionResponse - validateFunc func(client.Collection[client.DiskResult]) - }{ - { - name: "when disks are populated", - input: func() *gen.DiskCollectionResponse { - changed := false - disks := gen.DisksResponse{ - { - Name: "/dev/sda1", - Total: 500000000000, - Used: 250000000000, - Free: 250000000000, - }, - { - Name: "/dev/sdb1", - Total: 1000000000000, - Used: 100000000000, - Free: 900000000000, - }, - } - - return &gen.DiskCollectionResponse{ - JobId: &testUUID, - Results: []gen.DiskResultItem{ - { - Hostname: "web-01", - Changed: &changed, - Disks: &disks, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DiskResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - dr := c.Results[0] - suite.Equal("web-01", dr.Hostname) - suite.Empty(dr.Error) - suite.False(dr.Changed) - suite.Require().Len(dr.Disks, 2) - suite.Equal("/dev/sda1", dr.Disks[0].Name) - suite.Equal(500000000000, dr.Disks[0].Total) - suite.Equal(250000000000, dr.Disks[0].Used) - suite.Equal(250000000000, dr.Disks[0].Free) - suite.Equal("/dev/sdb1", dr.Disks[1].Name) - }, - }, - { - name: "when empty", - input: &gen.DiskCollectionResponse{ - Results: []gen.DiskResultItem{ - {Hostname: "web-01"}, - }, - }, - validateFunc: func(c client.Collection[client.DiskResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - suite.Equal("web-01", c.Results[0].Hostname) - suite.False(c.Results[0].Changed) - suite.Nil(c.Results[0].Disks) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportDiskCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - func TestDiskTypesPublicTestSuite(t *testing.T) { suite.Run(t, new(DiskTypesPublicTestSuite)) } diff --git a/pkg/sdk/client/docker_types_public_test.go b/pkg/sdk/client/docker_types_public_test.go deleted file mode 100644 index 84152d491..000000000 --- a/pkg/sdk/client/docker_types_public_test.go +++ /dev/null @@ -1,570 +0,0 @@ -// Copyright (c) 2026 John Dewey - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -package client_test - -import ( - "testing" - - openapi_types "github.com/oapi-codegen/runtime/types" - "github.com/stretchr/testify/suite" - - "github.com/osapi-io/osapi/pkg/sdk/client" - "github.com/osapi-io/osapi/pkg/sdk/client/gen" -) - -type DockerTypesPublicTestSuite struct { - suite.Suite -} - -func (suite *DockerTypesPublicTestSuite) TestDockerResultCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.DockerResultCollectionResponse - validateFunc func(client.Collection[client.DockerResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.DockerResultCollectionResponse { - id := "abc123" - name := "my-nginx" - image := "nginx:latest" - state := "running" - created := "2026-01-01T00:00:00Z" - changed := true - - return &gen.DockerResultCollectionResponse{ - JobId: &testUUID, - Results: []gen.DockerResponse{ - { - Hostname: "web-01", - Id: &id, - Name: &name, - Image: &image, - State: &state, - Created: &created, - Changed: &changed, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("abc123", r.ID) - suite.Equal("my-nginx", r.Name) - suite.Equal("nginx:latest", r.Image) - suite.Equal("running", r.State) - suite.Equal("2026-01-01T00:00:00Z", r.Created) - suite.True(r.Changed) - suite.Empty(r.Error) - }, - }, - { - name: "when minimal with error", - input: func() *gen.DockerResultCollectionResponse { - errMsg := "image not found" - - return &gen.DockerResultCollectionResponse{ - Results: []gen.DockerResponse{ - { - Hostname: "web-01", - Error: &errMsg, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("image not found", r.Error) - suite.Empty(r.ID) - suite.Empty(r.Name) - suite.Empty(r.Image) - suite.Empty(r.State) - suite.Empty(r.Created) - suite.False(r.Changed) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportDockerResultCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *DockerTypesPublicTestSuite) TestDockerListCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.DockerListCollectionResponse - validateFunc func(client.Collection[client.DockerListResult]) - }{ - { - name: "when containers are populated", - input: func() *gen.DockerListCollectionResponse { - changed := false - id := "abc123" - name := "my-nginx" - image := "nginx:latest" - state := "running" - created := "2026-01-01T00:00:00Z" - containers := []gen.DockerSummary{ - { - Id: &id, - Name: &name, - Image: &image, - State: &state, - Created: &created, - }, - } - - return &gen.DockerListCollectionResponse{ - JobId: &testUUID, - Results: []gen.DockerListItem{ - { - Hostname: "web-01", - Changed: &changed, - Containers: &containers, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerListResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.False(r.Changed) - suite.Empty(r.Error) - suite.Require().Len(r.Containers, 1) - suite.Equal("abc123", r.Containers[0].ID) - suite.Equal("my-nginx", r.Containers[0].Name) - suite.Equal("nginx:latest", r.Containers[0].Image) - suite.Equal("running", r.Containers[0].State) - suite.Equal("2026-01-01T00:00:00Z", r.Containers[0].Created) - }, - }, - { - name: "when containers is nil", - input: &gen.DockerListCollectionResponse{ - Results: []gen.DockerListItem{ - {Hostname: "web-01"}, - }, - }, - validateFunc: func(c client.Collection[client.DockerListResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - suite.Equal("web-01", c.Results[0].Hostname) - suite.False(c.Results[0].Changed) - suite.Nil(c.Results[0].Containers) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportDockerListCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *DockerTypesPublicTestSuite) TestDockerDetailCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.DockerDetailCollectionResponse - validateFunc func(client.Collection[client.DockerDetailResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.DockerDetailCollectionResponse { - id := "abc123" - name := "my-nginx" - image := "nginx:latest" - state := "running" - created := "2026-01-01T00:00:00Z" - health := "healthy" - changed := false - ports := []string{"80/tcp", "443/tcp"} - mounts := []string{"/data:/data"} - env := []string{"FOO=bar", "BAZ=qux"} - networkSettings := map[string]string{"ip": "172.17.0.2"} - - return &gen.DockerDetailCollectionResponse{ - JobId: &testUUID, - Results: []gen.DockerDetailResponse{ - { - Hostname: "web-01", - Id: &id, - Name: &name, - Image: &image, - State: &state, - Created: &created, - Health: &health, - Changed: &changed, - Ports: &ports, - Mounts: &mounts, - Env: &env, - NetworkSettings: &networkSettings, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerDetailResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("abc123", r.ID) - suite.Equal("my-nginx", r.Name) - suite.Equal("nginx:latest", r.Image) - suite.Equal("running", r.State) - suite.Equal("2026-01-01T00:00:00Z", r.Created) - suite.Equal("healthy", r.Health) - suite.False(r.Changed) - suite.Empty(r.Error) - suite.Equal([]string{"80/tcp", "443/tcp"}, r.Ports) - suite.Equal([]string{"/data:/data"}, r.Mounts) - suite.Equal([]string{"FOO=bar", "BAZ=qux"}, r.Env) - suite.Equal(map[string]string{"ip": "172.17.0.2"}, r.NetworkSettings) - }, - }, - { - name: "when optional fields are nil", - input: &gen.DockerDetailCollectionResponse{ - Results: []gen.DockerDetailResponse{ - {Hostname: "web-01"}, - }, - }, - validateFunc: func(c client.Collection[client.DockerDetailResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Empty(r.ID) - suite.Empty(r.Name) - suite.Empty(r.Image) - suite.Empty(r.State) - suite.Empty(r.Created) - suite.Empty(r.Health) - suite.False(r.Changed) - suite.Empty(r.Error) - suite.Nil(r.Ports) - suite.Nil(r.Mounts) - suite.Nil(r.Env) - suite.Nil(r.NetworkSettings) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportDockerDetailCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *DockerTypesPublicTestSuite) TestDockerActionCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.DockerActionCollectionResponse - validateFunc func(client.Collection[client.DockerActionResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.DockerActionCollectionResponse { - id := "abc123" - message := "container started" - changed := true - - return &gen.DockerActionCollectionResponse{ - JobId: &testUUID, - Results: []gen.DockerActionResultItem{ - { - Hostname: "web-01", - Id: &id, - Message: &message, - Changed: &changed, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerActionResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("abc123", r.ID) - suite.Equal("container started", r.Message) - suite.True(r.Changed) - suite.Empty(r.Error) - }, - }, - { - name: "when minimal with error", - input: func() *gen.DockerActionCollectionResponse { - errMsg := "container not found" - - return &gen.DockerActionCollectionResponse{ - Results: []gen.DockerActionResultItem{ - { - Hostname: "web-01", - Error: &errMsg, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerActionResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("container not found", r.Error) - suite.Empty(r.ID) - suite.Empty(r.Message) - suite.False(r.Changed) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportDockerActionCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *DockerTypesPublicTestSuite) TestDockerExecCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.DockerExecCollectionResponse - validateFunc func(client.Collection[client.DockerExecResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.DockerExecCollectionResponse { - stdout := "hello world\n" - stderr := "warning: something\n" - exitCode := 0 - changed := true - - return &gen.DockerExecCollectionResponse{ - JobId: &testUUID, - Results: []gen.DockerExecResultItem{ - { - Hostname: "web-01", - Stdout: &stdout, - Stderr: &stderr, - ExitCode: &exitCode, - Changed: &changed, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerExecResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("hello world\n", r.Stdout) - suite.Equal("warning: something\n", r.Stderr) - suite.Equal(0, r.ExitCode) - suite.True(r.Changed) - suite.Empty(r.Error) - }, - }, - { - name: "when minimal with error", - input: func() *gen.DockerExecCollectionResponse { - errMsg := "exec failed" - exitCode := 1 - - return &gen.DockerExecCollectionResponse{ - Results: []gen.DockerExecResultItem{ - { - Hostname: "web-01", - Error: &errMsg, - ExitCode: &exitCode, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerExecResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("exec failed", r.Error) - suite.Equal(1, r.ExitCode) - suite.Empty(r.Stdout) - suite.Empty(r.Stderr) - suite.False(r.Changed) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportDockerExecCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *DockerTypesPublicTestSuite) TestDockerPullCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.DockerPullCollectionResponse - validateFunc func(client.Collection[client.DockerPullResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.DockerPullCollectionResponse { - imageID := "sha256:abc123" - tag := "latest" - size := int64(52428800) - changed := true - - return &gen.DockerPullCollectionResponse{ - JobId: &testUUID, - Results: []gen.DockerPullResultItem{ - { - Hostname: "web-01", - ImageId: &imageID, - Tag: &tag, - Size: &size, - Changed: &changed, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerPullResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("sha256:abc123", r.ImageID) - suite.Equal("latest", r.Tag) - suite.Equal(int64(52428800), r.Size) - suite.True(r.Changed) - suite.Empty(r.Error) - }, - }, - { - name: "when minimal with error", - input: func() *gen.DockerPullCollectionResponse { - errMsg := "pull failed: image not found" - - return &gen.DockerPullCollectionResponse{ - Results: []gen.DockerPullResultItem{ - { - Hostname: "web-01", - Error: &errMsg, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.DockerPullResult]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("pull failed: image not found", r.Error) - suite.Empty(r.ImageID) - suite.Empty(r.Tag) - suite.Zero(r.Size) - suite.False(r.Changed) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportDockerPullCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func TestDockerTypesPublicTestSuite(t *testing.T) { - suite.Run(t, new(DockerTypesPublicTestSuite)) -} diff --git a/pkg/sdk/client/export_test.go b/pkg/sdk/client/export_test.go index 7343aa78e..a7d03cbf1 100644 --- a/pkg/sdk/client/export_test.go +++ b/pkg/sdk/client/export_test.go @@ -24,8 +24,6 @@ import ( "log/slog" "net/http" - openapi_types "github.com/oapi-codegen/runtime/types" - "github.com/osapi-io/osapi/pkg/sdk/client/gen" ) @@ -79,82 +77,12 @@ func ExportDisksFromGen( return disksFromGen(input) } -// ExportDerefString exposes the private derefString for testing. -func ExportDerefString( - s *string, -) string { - return derefString(s) -} - -// ExportDerefInt exposes the private derefInt for testing. -func ExportDerefInt( - i *int, -) int { - return derefInt(i) -} - -// ExportDerefInt64 exposes the private derefInt64 for testing. -func ExportDerefInt64( - i *int64, -) int64 { - return derefInt64(i) -} - -// ExportDerefFloat64 exposes the private derefFloat64 for testing. -func ExportDerefFloat64( - f *float64, -) float64 { - return derefFloat64(f) -} - -// ExportDerefBool exposes the private derefBool for testing. -func ExportDerefBool( - b *bool, -) bool { - return derefBool(b) -} - -// ExportJobIDFromGen exposes the private jobIDFromGen for testing. -func ExportJobIDFromGen( - id *openapi_types.UUID, -) string { - return jobIDFromGen(id) -} - -// ExportHostnameCollectionFromGen exposes the private -// hostnameCollectionFromGen for testing. func ExportHostnameCollectionFromGen( input *gen.HostnameCollectionResponse, ) Collection[HostnameResult] { return hostnameCollectionFromGen(input) } -// ExportNodeStatusCollectionFromGen exposes the private -// nodeStatusCollectionFromGen for testing. -func ExportNodeStatusCollectionFromGen( - input *gen.NodeStatusCollectionResponse, -) Collection[NodeStatus] { - return nodeStatusCollectionFromGen(input) -} - -// ExportDiskCollectionFromGen exposes the private diskCollectionFromGen for -// testing. -func ExportDiskCollectionFromGen( - input *gen.DiskCollectionResponse, -) Collection[DiskResult] { - return diskCollectionFromGen(input) -} - -// ExportCommandCollectionFromGen exposes the private commandCollectionFromGen -// for testing. -func ExportCommandCollectionFromGen( - input *gen.CommandResultCollectionResponse, -) Collection[CommandResult] { - return commandCollectionFromGen(input) -} - -// ExportDNSConfigCollectionFromGen exposes the private -// dnsConfigCollectionFromGen for testing. func ExportDNSConfigCollectionFromGen( input *gen.DNSConfigCollectionResponse, ) Collection[DNSConfig] { @@ -169,71 +97,6 @@ func ExportDNSUpdateCollectionFromGen( return dnsUpdateCollectionFromGen(input) } -// ExportHostnameUpdateCollectionFromGen exposes the private -// hostnameUpdateCollectionFromGen for testing. -func ExportHostnameUpdateCollectionFromGen( - input *gen.HostnameUpdateCollectionResponse, -) Collection[HostnameUpdateResult] { - return hostnameUpdateCollectionFromGen(input) -} - -// ExportPingCollectionFromGen exposes the private pingCollectionFromGen for -// testing. -func ExportPingCollectionFromGen( - input *gen.PingCollectionResponse, -) Collection[PingResult] { - return pingCollectionFromGen(input) -} - -// ExportDockerResultCollectionFromGen exposes the private -// dockerResultCollectionFromGen for testing. -func ExportDockerResultCollectionFromGen( - input *gen.DockerResultCollectionResponse, -) Collection[DockerResult] { - return dockerResultCollectionFromGen(input) -} - -// ExportDockerListCollectionFromGen exposes the private -// dockerListCollectionFromGen for testing. -func ExportDockerListCollectionFromGen( - input *gen.DockerListCollectionResponse, -) Collection[DockerListResult] { - return dockerListCollectionFromGen(input) -} - -// ExportDockerDetailCollectionFromGen exposes the private -// dockerDetailCollectionFromGen for testing. -func ExportDockerDetailCollectionFromGen( - input *gen.DockerDetailCollectionResponse, -) Collection[DockerDetailResult] { - return dockerDetailCollectionFromGen(input) -} - -// ExportDockerActionCollectionFromGen exposes the private -// dockerActionCollectionFromGen for testing. -func ExportDockerActionCollectionFromGen( - input *gen.DockerActionCollectionResponse, -) Collection[DockerActionResult] { - return dockerActionCollectionFromGen(input) -} - -// ExportDockerExecCollectionFromGen exposes the private -// dockerExecCollectionFromGen for testing. -func ExportDockerExecCollectionFromGen( - input *gen.DockerExecCollectionResponse, -) Collection[DockerExecResult] { - return dockerExecCollectionFromGen(input) -} - -// ExportDockerPullCollectionFromGen exposes the private -// dockerPullCollectionFromGen for testing. -func ExportDockerPullCollectionFromGen( - input *gen.DockerPullCollectionResponse, -) Collection[DockerPullResult] { - return dockerPullCollectionFromGen(input) -} - -// ExportAuditEntryFromGen exposes the private auditEntryFromGen for testing. func ExportAuditEntryFromGen( input gen.AuditEntry, ) AuditEntry { @@ -268,92 +131,6 @@ func ExportJobListFromGen( return jobListFromGen(input) } -// ExportFileUploadFromGen exposes the private fileUploadFromGen for testing. -func ExportFileUploadFromGen( - input *gen.FileUploadResponse, -) FileUpload { - return fileUploadFromGen(input) -} - -// ExportFileListFromGen exposes the private fileListFromGen for testing. -func ExportFileListFromGen( - input *gen.FileListResponse, -) FileList { - return fileListFromGen(input) -} - -// ExportFileMetadataFromGen exposes the private fileMetadataFromGen for -// testing. -func ExportFileMetadataFromGen( - input *gen.FileInfoResponse, -) FileMetadata { - return fileMetadataFromGen(input) -} - -// ExportFileDeleteFromGen exposes the private fileDeleteFromGen for testing. -func ExportFileDeleteFromGen( - input *gen.FileDeleteResponse, -) FileDelete { - return fileDeleteFromGen(input) -} - -// ExportStaleDeploymentFromGen exposes the private staleDeploymentFromGen for -// testing. -func ExportStaleDeploymentFromGen( - input gen.StaleDeployment, -) StaleDeployment { - return staleDeploymentFromGen(input) -} - -// ExportStaleListFromGen exposes the private staleListFromGen for testing. -func ExportStaleListFromGen( - input *gen.StaleDeploymentsResponse, -) StaleList { - return staleListFromGen(input) -} - -// ExportFileDeployCollectionFromGen exposes the private -// fileDeployCollectionFromGen for testing. -func ExportFileDeployCollectionFromGen( - input *gen.FileDeployCollectionResponse, -) Collection[FileDeployResult] { - return fileDeployCollectionFromGen(input) -} - -// ExportFileUndeployCollectionFromGen exposes the private -// fileUndeployCollectionFromGen for testing. -func ExportFileUndeployCollectionFromGen( - input *gen.FileUndeployCollectionResponse, -) Collection[FileUndeployResult] { - return fileUndeployCollectionFromGen(input) -} - -// ExportFileStatusCollectionFromGen exposes the private -// fileStatusCollectionFromGen for testing. -func ExportFileStatusCollectionFromGen( - input *gen.FileStatusCollectionResponse, -) Collection[FileStatusResult] { - return fileStatusCollectionFromGen(input) -} - -// ExportHealthStatusFromGen exposes the private healthStatusFromGen for -// testing. -func ExportHealthStatusFromGen( - input *gen.HealthResponse, -) HealthStatus { - return healthStatusFromGen(input) -} - -// ExportReadyStatusFromGen exposes the private readyStatusFromGen for testing. -func ExportReadyStatusFromGen( - input *gen.ReadyResponse, - serviceUnavailable bool, -) ReadyStatus { - return readyStatusFromGen(input, serviceUnavailable) -} - -// ExportSystemStatusFromGen exposes the private systemStatusFromGen for -// testing. func ExportSystemStatusFromGen( input *gen.StatusResponse, serviceUnavailable bool, @@ -375,16 +152,6 @@ func ExportAgentListFromGen( return agentListFromGen(input) } -// ExportPendingAgentListFromGen exposes the private pendingAgentListFromGen -// for testing. -func ExportPendingAgentListFromGen( - input *gen.ListPendingAgentsResponse, -) PendingAgentList { - return pendingAgentListFromGen(input) -} - -// SysctlEntryCollectionFromGen exposes the private -// sysctlEntryCollectionFromGen for testing. func SysctlEntryCollectionFromGen( input *gen.SysctlCollectionResponse, ) Collection[SysctlEntryResult] { @@ -455,24 +222,6 @@ func NtpMutationCollectionFromDelete( return ntpMutationCollectionFromDelete(input) } -// ExportTimezoneCollectionFromGen exposes the private -// timezoneCollectionFromGen for testing. -func ExportTimezoneCollectionFromGen( - input *gen.TimezoneCollectionResponse, -) Collection[TimezoneResult] { - return timezoneCollectionFromGen(input) -} - -// ExportTimezoneMutationCollectionFromUpdate exposes the private -// timezoneMutationCollectionFromUpdate for testing. -func ExportTimezoneMutationCollectionFromUpdate( - input *gen.TimezoneUpdateResponse, -) Collection[TimezoneMutationResult] { - return timezoneMutationCollectionFromUpdate(input) -} - -// PowerCollectionFromReboot exposes the private -// powerCollectionFromReboot for testing. func PowerCollectionFromReboot( input *gen.PowerRebootResponse, ) Collection[PowerResult] { @@ -487,15 +236,6 @@ func PowerCollectionFromShutdown( return powerCollectionFromShutdown(input) } -// ExportDerefFloat32 exposes the private derefFloat32 for testing. -func ExportDerefFloat32( - f *float32, -) float32 { - return derefFloat32(f) -} - -// ProcessInfoCollectionFromList exposes the private -// processInfoCollectionFromList for testing. func ProcessInfoCollectionFromList( input *gen.ProcessCollectionResponse, ) Collection[ProcessInfoResult] { @@ -518,15 +258,6 @@ func ProcessSignalCollectionFromGen( return processSignalCollectionFromGen(input) } -// ExportDerefStringSlice exposes the private derefStringSlice for testing. -func ExportDerefStringSlice( - s *[]string, -) []string { - return derefStringSlice(s) -} - -// UserInfoCollectionFromList exposes the private -// userInfoCollectionFromList for testing. func UserInfoCollectionFromList( input *gen.UserCollectionResponse, ) Collection[UserInfoResult] { diff --git a/pkg/sdk/client/file_types_public_test.go b/pkg/sdk/client/file_types_public_test.go deleted file mode 100644 index 18f65f5cb..000000000 --- a/pkg/sdk/client/file_types_public_test.go +++ /dev/null @@ -1,433 +0,0 @@ -// Copyright (c) 2026 John Dewey - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -package client_test - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/osapi-io/osapi/pkg/sdk/client" - "github.com/osapi-io/osapi/pkg/sdk/client/gen" -) - -type FileTypesPublicTestSuite struct { - suite.Suite -} - -func (suite *FileTypesPublicTestSuite) TestFileUploadFromGen() { - tests := []struct { - name string - input *gen.FileUploadResponse - validateFunc func(client.FileUpload) - }{ - { - name: "when all fields populated returns FileUpload", - input: &gen.FileUploadResponse{ - Name: "nginx.conf", - Sha256: "abc123", - Size: 1024, - Changed: true, - ContentType: "raw", - }, - validateFunc: func(result client.FileUpload) { - suite.Equal("nginx.conf", result.Name) - suite.Equal("abc123", result.SHA256) - suite.Equal(1024, result.Size) - suite.True(result.Changed) - suite.Equal("raw", result.ContentType) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportFileUploadFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestFileListFromGen() { - tests := []struct { - name string - input *gen.FileListResponse - validateFunc func(client.FileList) - }{ - { - name: "when files exist returns FileList with items", - input: &gen.FileListResponse{ - Files: []gen.FileInfo{ - {Name: "file1.txt", Sha256: "aaa", Size: 100, ContentType: "raw"}, - {Name: "file2.txt", Sha256: "bbb", Size: 200, ContentType: "template"}, - }, - Total: 2, - }, - validateFunc: func(result client.FileList) { - suite.Len(result.Files, 2) - suite.Equal(2, result.Total) - suite.Equal("file1.txt", result.Files[0].Name) - suite.Equal("aaa", result.Files[0].SHA256) - suite.Equal(100, result.Files[0].Size) - suite.Equal("raw", result.Files[0].ContentType) - suite.Equal("file2.txt", result.Files[1].Name) - suite.Equal("template", result.Files[1].ContentType) - }, - }, - { - name: "when no files returns empty FileList", - input: &gen.FileListResponse{ - Files: []gen.FileInfo{}, - Total: 0, - }, - validateFunc: func(result client.FileList) { - suite.Empty(result.Files) - suite.Equal(0, result.Total) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportFileListFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestFileMetadataFromGen() { - tests := []struct { - name string - input *gen.FileInfoResponse - validateFunc func(client.FileMetadata) - }{ - { - name: "when all fields populated returns FileMetadata", - input: &gen.FileInfoResponse{ - Name: "config.yaml", - Sha256: "def456", - Size: 512, - ContentType: "template", - }, - validateFunc: func(result client.FileMetadata) { - suite.Equal("config.yaml", result.Name) - suite.Equal("def456", result.SHA256) - suite.Equal(512, result.Size) - suite.Equal("template", result.ContentType) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportFileMetadataFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestFileDeleteFromGen() { - tests := []struct { - name string - input *gen.FileDeleteResponse - validateFunc func(client.FileDelete) - }{ - { - name: "when deleted returns FileDelete with true", - input: &gen.FileDeleteResponse{ - Name: "old.conf", - Deleted: true, - }, - validateFunc: func(result client.FileDelete) { - suite.Equal("old.conf", result.Name) - suite.True(result.Deleted) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportFileDeleteFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestStaleDeploymentFromGen() { - tests := []struct { - name string - input gen.StaleDeployment - validateFunc func(client.StaleDeployment) - }{ - { - name: "when all fields populated returns StaleDeployment", - input: gen.StaleDeployment{ - ObjectName: "nginx.conf", - Hostname: "web-01", - Path: "/etc/nginx/nginx.conf", - DeployedSha: "aaa111", - CurrentSha: "bbb222", - DeployedAt: "2026-01-15T10:30:00Z", - }, - validateFunc: func(result client.StaleDeployment) { - suite.Equal("nginx.conf", result.ObjectName) - suite.Equal("web-01", result.Hostname) - suite.Equal("/etc/nginx/nginx.conf", result.Path) - suite.Equal("aaa111", result.DeployedSHA) - suite.Equal("bbb222", result.CurrentSHA) - suite.Equal("2026-01-15T10:30:00Z", result.DeployedAt) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportStaleDeploymentFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestStaleListFromGen() { - tests := []struct { - name string - input *gen.StaleDeploymentsResponse - validateFunc func(client.StaleList) - }{ - { - name: "when stale entries exist returns StaleList with items", - input: &gen.StaleDeploymentsResponse{ - Stale: []gen.StaleDeployment{ - { - ObjectName: "nginx.conf", - Hostname: "web-01", - Path: "/etc/nginx/nginx.conf", - DeployedSha: "aaa", - CurrentSha: "bbb", - DeployedAt: "2026-01-15T10:30:00Z", - }, - { - ObjectName: "app.conf", - Hostname: "web-02", - Path: "/etc/app/app.conf", - DeployedSha: "ccc", - CurrentSha: "ddd", - DeployedAt: "2026-01-16T11:00:00Z", - }, - }, - Total: 2, - }, - validateFunc: func(result client.StaleList) { - suite.Len(result.Stale, 2) - suite.Equal(2, result.Total) - suite.Equal("nginx.conf", result.Stale[0].ObjectName) - suite.Equal("web-01", result.Stale[0].Hostname) - suite.Equal("app.conf", result.Stale[1].ObjectName) - suite.Equal("web-02", result.Stale[1].Hostname) - }, - }, - { - name: "when no stale entries returns empty StaleList", - input: &gen.StaleDeploymentsResponse{ - Stale: []gen.StaleDeployment{}, - Total: 0, - }, - validateFunc: func(result client.StaleList) { - suite.Empty(result.Stale) - suite.Equal(0, result.Total) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportStaleListFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestFileDeployCollectionFromGen() { - trueVal := true - falseVal := false - errMsg := "deploy failed" - - tests := []struct { - name string - input *gen.FileDeployCollectionResponse - validateFunc func(client.Collection[client.FileDeployResult]) - }{ - { - name: "when results present returns collection with results", - input: &gen.FileDeployCollectionResponse{ - Results: []gen.FileDeployResult{ - {Hostname: "web-01", Changed: &trueVal}, - {Hostname: "web-02", Changed: &falseVal, Error: &errMsg}, - }, - }, - validateFunc: func(result client.Collection[client.FileDeployResult]) { - suite.Len(result.Results, 2) - suite.Equal("web-01", result.Results[0].Hostname) - suite.True(result.Results[0].Changed) - suite.Empty(result.Results[0].Error) - suite.Equal("web-02", result.Results[1].Hostname) - suite.False(result.Results[1].Changed) - suite.Equal("deploy failed", result.Results[1].Error) - }, - }, - { - name: "when empty results returns empty collection", - input: &gen.FileDeployCollectionResponse{ - Results: []gen.FileDeployResult{}, - }, - validateFunc: func(result client.Collection[client.FileDeployResult]) { - suite.Empty(result.Results) - suite.Empty(result.JobID) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportFileDeployCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestFileUndeployCollectionFromGen() { - trueVal := true - errMsg := "undeploy failed" - - tests := []struct { - name string - input *gen.FileUndeployCollectionResponse - validateFunc func(client.Collection[client.FileUndeployResult]) - }{ - { - name: "when results present returns collection with results", - input: &gen.FileUndeployCollectionResponse{ - Results: []gen.FileUndeployResult{ - {Hostname: "web-01", Changed: &trueVal}, - {Hostname: "web-02", Error: &errMsg}, - }, - }, - validateFunc: func(result client.Collection[client.FileUndeployResult]) { - suite.Len(result.Results, 2) - suite.Equal("web-01", result.Results[0].Hostname) - suite.True(result.Results[0].Changed) - suite.Equal("web-02", result.Results[1].Hostname) - suite.Equal("undeploy failed", result.Results[1].Error) - }, - }, - { - name: "when empty results returns empty collection", - input: &gen.FileUndeployCollectionResponse{ - Results: []gen.FileUndeployResult{}, - }, - validateFunc: func(result client.Collection[client.FileUndeployResult]) { - suite.Empty(result.Results) - suite.Empty(result.JobID) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportFileUndeployCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *FileTypesPublicTestSuite) TestFileStatusCollectionFromGen() { - sha := "abc123" - changed := false - errMsg := "status failed" - path := "/etc/nginx/nginx.conf" - status := "in-sync" - missingPath := "/etc/missing.conf" - missingStatus := "missing" - - tests := []struct { - name string - input *gen.FileStatusCollectionResponse - validateFunc func(client.Collection[client.FileStatusResult]) - }{ - { - name: "when all fields populated returns FileStatusResult", - input: &gen.FileStatusCollectionResponse{ - Results: []gen.FileStatusResult{ - { - Hostname: "web-03", - Path: &path, - Status: &status, - Sha256: &sha, - Changed: &changed, - Error: &errMsg, - }, - }, - }, - validateFunc: func(result client.Collection[client.FileStatusResult]) { - suite.Len(result.Results, 1) - r := result.Results[0] - suite.Equal("web-03", r.Hostname) - suite.Equal("/etc/nginx/nginx.conf", r.Path) - suite.Equal("in-sync", r.Status) - suite.Equal("abc123", r.SHA256) - suite.False(r.Changed) - suite.Equal("status failed", r.Error) - }, - }, - { - name: "when sha256 is nil returns empty string", - input: &gen.FileStatusCollectionResponse{ - Results: []gen.FileStatusResult{ - { - Hostname: "web-04", - Path: &missingPath, - Status: &missingStatus, - Sha256: nil, - }, - }, - }, - validateFunc: func(result client.Collection[client.FileStatusResult]) { - suite.Len(result.Results, 1) - r := result.Results[0] - suite.Equal("missing", r.Status) - suite.Empty(r.SHA256) - suite.False(r.Changed) - suite.Empty(r.Error) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportFileStatusCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func TestFileTypesPublicTestSuite(t *testing.T) { - suite.Run(t, new(FileTypesPublicTestSuite)) -} diff --git a/pkg/sdk/client/health_types_public_test.go b/pkg/sdk/client/health_types_public_test.go index 6e5e0229b..3333be7a5 100644 --- a/pkg/sdk/client/health_types_public_test.go +++ b/pkg/sdk/client/health_types_public_test.go @@ -33,77 +33,6 @@ type HealthTypesPublicTestSuite struct { suite.Suite } -func (suite *HealthTypesPublicTestSuite) TestHealthStatusFromGen() { - tests := []struct { - name string - input *gen.HealthResponse - validateFunc func(client.HealthStatus) - }{ - { - name: "when status is ok", - input: &gen.HealthResponse{ - Status: "ok", - }, - validateFunc: func(h client.HealthStatus) { - suite.Equal("ok", h.Status) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportHealthStatusFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *HealthTypesPublicTestSuite) TestReadyStatusFromGen() { - tests := []struct { - name string - input *gen.ReadyResponse - serviceUnavailable bool - validateFunc func(client.ReadyStatus) - }{ - { - name: "when ready with no error", - input: &gen.ReadyResponse{ - Status: "ready", - }, - serviceUnavailable: false, - validateFunc: func(r client.ReadyStatus) { - suite.Equal("ready", r.Status) - suite.Empty(r.Error) - suite.False(r.ServiceUnavailable) - }, - }, - { - name: "when not ready with error", - input: func() *gen.ReadyResponse { - errMsg := "NATS connection failed" - - return &gen.ReadyResponse{ - Status: "not_ready", - Error: &errMsg, - } - }(), - serviceUnavailable: true, - validateFunc: func(r client.ReadyStatus) { - suite.Equal("not_ready", r.Status) - suite.Equal("NATS connection failed", r.Error) - suite.True(r.ServiceUnavailable) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportReadyStatusFromGen(tc.input, tc.serviceUnavailable) - tc.validateFunc(result) - }) - } -} - func (suite *HealthTypesPublicTestSuite) TestSystemStatusFromGen() { tests := []struct { name string diff --git a/pkg/sdk/client/hostname_types_public_test.go b/pkg/sdk/client/hostname_types_public_test.go index ddab4b7d3..581f15a75 100644 --- a/pkg/sdk/client/hostname_types_public_test.go +++ b/pkg/sdk/client/hostname_types_public_test.go @@ -109,72 +109,6 @@ func (suite *HostnameTypesPublicTestSuite) TestHostnameCollectionFromGen() { } } -func (suite *HostnameTypesPublicTestSuite) TestHostnameUpdateCollectionFromGen() { - tests := []struct { - name string - input *gen.HostnameUpdateCollectionResponse - validateFunc func(client.Collection[client.HostnameUpdateResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.HostnameUpdateCollectionResponse { - changed := true - - return &gen.HostnameUpdateCollectionResponse{ - Results: []gen.HostnameUpdateResultItem{ - { - Hostname: "web-01", - Status: gen.HostnameUpdateResultItemStatusOk, - Changed: &changed, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.HostnameUpdateResult]) { - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-01", r.Hostname) - suite.Equal("ok", r.Status) - suite.True(r.Changed) - suite.Empty(r.Error) - }, - }, - { - name: "when error is set", - input: func() *gen.HostnameUpdateCollectionResponse { - errMsg := "unsupported" - - return &gen.HostnameUpdateCollectionResponse{ - Results: []gen.HostnameUpdateResultItem{ - { - Hostname: "web-02", - Status: gen.HostnameUpdateResultItemStatusFailed, - Error: &errMsg, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.HostnameUpdateResult]) { - suite.Require().Len(c.Results, 1) - - r := c.Results[0] - suite.Equal("web-02", r.Hostname) - suite.Equal("failed", r.Status) - suite.False(r.Changed) - suite.Equal("unsupported", r.Error) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportHostnameUpdateCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - func TestHostnameTypesPublicTestSuite(t *testing.T) { suite.Run(t, new(HostnameTypesPublicTestSuite)) } diff --git a/pkg/sdk/client/ping_types_public_test.go b/pkg/sdk/client/ping_types_public_test.go deleted file mode 100644 index c850a8575..000000000 --- a/pkg/sdk/client/ping_types_public_test.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2026 John Dewey - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -package client_test - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/osapi-io/osapi/pkg/sdk/client" - "github.com/osapi-io/osapi/pkg/sdk/client/gen" -) - -type PingTypesPublicTestSuite struct { - suite.Suite -} - -func (suite *PingTypesPublicTestSuite) TestPingCollectionFromGen() { - tests := []struct { - name string - input *gen.PingCollectionResponse - validateFunc func(client.Collection[client.PingResult]) - }{ - { - name: "when all fields are populated", - input: func() *gen.PingCollectionResponse { - packetsSent := 5 - packetsReceived := 5 - packetLoss := 0.0 - minRtt := "1.234ms" - avgRtt := "2.345ms" - maxRtt := "3.456ms" - changed := false - - return &gen.PingCollectionResponse{ - Results: []gen.PingResponse{ - { - Hostname: "web-01", - Changed: &changed, - PacketsSent: &packetsSent, - PacketsReceived: &packetsReceived, - PacketLoss: &packetLoss, - MinRtt: &minRtt, - AvgRtt: &avgRtt, - MaxRtt: &maxRtt, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.PingResult]) { - suite.Require().Len(c.Results, 1) - - pr := c.Results[0] - suite.Equal("web-01", pr.Hostname) - suite.Equal(5, pr.PacketsSent) - suite.Equal(5, pr.PacketsReceived) - suite.InDelta(0.0, pr.PacketLoss, 0.001) - suite.Equal("1.234ms", pr.MinRtt) - suite.Equal("2.345ms", pr.AvgRtt) - suite.Equal("3.456ms", pr.MaxRtt) - suite.Empty(pr.Error) - suite.False(pr.Changed) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportPingCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func TestPingTypesPublicTestSuite(t *testing.T) { - suite.Run(t, new(PingTypesPublicTestSuite)) -} diff --git a/pkg/sdk/client/status_types_public_test.go b/pkg/sdk/client/status_types_public_test.go deleted file mode 100644 index 2107e0a4c..000000000 --- a/pkg/sdk/client/status_types_public_test.go +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) 2026 John Dewey - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -package client_test - -import ( - "testing" - - openapi_types "github.com/oapi-codegen/runtime/types" - "github.com/stretchr/testify/suite" - - "github.com/osapi-io/osapi/pkg/sdk/client" - "github.com/osapi-io/osapi/pkg/sdk/client/gen" -) - -type StatusTypesPublicTestSuite struct { - suite.Suite -} - -func (suite *StatusTypesPublicTestSuite) TestNodeStatusCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.NodeStatusCollectionResponse - validateFunc func(client.Collection[client.NodeStatus]) - }{ - { - name: "when all sub-types are populated", - input: func() *gen.NodeStatusCollectionResponse { - uptime := "5d 3h 22m" - changed := false - disks := gen.DisksResponse{ - { - Name: "/dev/sda1", - Total: 500000000000, - Used: 250000000000, - Free: 250000000000, - }, - } - - return &gen.NodeStatusCollectionResponse{ - JobId: &testUUID, - Results: []gen.NodeStatusResponse{ - { - Hostname: "web-01", - Uptime: &uptime, - Changed: &changed, - Disks: &disks, - LoadAverage: &gen.LoadAverageResponse{ - N1min: 0.5, - N5min: 1.2, - N15min: 0.8, - }, - Memory: &gen.MemoryResponse{ - Total: 8589934592, - Used: 4294967296, - Free: 4294967296, - }, - OsInfo: &gen.OSInfoResponse{ - Distribution: "Ubuntu", - Version: "22.04", - }, - }, - }, - } - }(), - validateFunc: func(c client.Collection[client.NodeStatus]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - - ns := c.Results[0] - suite.Equal("web-01", ns.Hostname) - suite.Equal("5d 3h 22m", ns.Uptime) - suite.Empty(ns.Error) - suite.False(ns.Changed) - - suite.Require().Len(ns.Disks, 1) - suite.Equal("/dev/sda1", ns.Disks[0].Name) - suite.Equal(500000000000, ns.Disks[0].Total) - - suite.Require().NotNil(ns.LoadAverage) - suite.InDelta(0.5, float64(ns.LoadAverage.OneMin), 0.001) - suite.InDelta(1.2, float64(ns.LoadAverage.FiveMin), 0.001) - suite.InDelta(0.8, float64(ns.LoadAverage.FifteenMin), 0.001) - - suite.Require().NotNil(ns.Memory) - suite.Equal(8589934592, ns.Memory.Total) - suite.Equal(4294967296, ns.Memory.Used) - suite.Equal(4294967296, ns.Memory.Free) - - suite.Require().NotNil(ns.OSInfo) - suite.Equal("Ubuntu", ns.OSInfo.Distribution) - suite.Equal("22.04", ns.OSInfo.Version) - }, - }, - { - name: "when minimal", - input: &gen.NodeStatusCollectionResponse{ - Results: []gen.NodeStatusResponse{ - {Hostname: "minimal-host"}, - }, - }, - validateFunc: func(c client.Collection[client.NodeStatus]) { - suite.Empty(c.JobID) - suite.Require().Len(c.Results, 1) - - ns := c.Results[0] - suite.Equal("minimal-host", ns.Hostname) - suite.Empty(ns.Uptime) - suite.Empty(ns.Error) - suite.False(ns.Changed) - suite.Nil(ns.Disks) - suite.Nil(ns.LoadAverage) - suite.Nil(ns.Memory) - suite.Nil(ns.OSInfo) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportNodeStatusCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func TestStatusTypesPublicTestSuite(t *testing.T) { - suite.Run(t, new(StatusTypesPublicTestSuite)) -} diff --git a/pkg/sdk/client/timezone_types_public_test.go b/pkg/sdk/client/timezone_types_public_test.go deleted file mode 100644 index 4f9608b9c..000000000 --- a/pkg/sdk/client/timezone_types_public_test.go +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (c) 2026 John Dewey - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -package client_test - -import ( - "testing" - - openapi_types "github.com/oapi-codegen/runtime/types" - "github.com/stretchr/testify/suite" - - "github.com/osapi-io/osapi/pkg/sdk/client" - "github.com/osapi-io/osapi/pkg/sdk/client/gen" -) - -// strPtr returns a pointer to a string value. -func strPtr( - s string, -) *string { - return &s -} - -type TimezoneTypesPublicTestSuite struct { - suite.Suite -} - -func (suite *TimezoneTypesPublicTestSuite) TestTimezoneCollectionFromGen() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - - tests := []struct { - name string - input *gen.TimezoneCollectionResponse - validateFunc func(client.Collection[client.TimezoneResult]) - }{ - { - name: "converts full response", - input: &gen.TimezoneCollectionResponse{ - JobId: &testUUID, - Results: []gen.TimezoneEntry{ - { - Hostname: "agent1", - Status: gen.TimezoneEntryStatusOk, - Timezone: strPtr("America/New_York"), - UtcOffset: strPtr("-05:00"), - }, - }, - }, - validateFunc: func(c client.Collection[client.TimezoneResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - suite.Equal("agent1", c.Results[0].Hostname) - suite.Equal("ok", c.Results[0].Status) - suite.Equal("America/New_York", c.Results[0].Timezone) - suite.Equal("-05:00", c.Results[0].UTCOffset) - }, - }, - { - name: "converts response with nil optional fields", - input: &gen.TimezoneCollectionResponse{ - Results: []gen.TimezoneEntry{ - { - Hostname: "agent1", - Status: gen.TimezoneEntryStatusSkipped, - Error: strPtr("unsupported"), - }, - }, - }, - validateFunc: func(c client.Collection[client.TimezoneResult]) { - suite.Equal("", c.JobID) - suite.Require().Len(c.Results, 1) - suite.Equal("agent1", c.Results[0].Hostname) - suite.Equal("skipped", c.Results[0].Status) - suite.Equal("", c.Results[0].Timezone) - suite.Equal("unsupported", c.Results[0].Error) - }, - }, - { - name: "converts empty results", - input: &gen.TimezoneCollectionResponse{ - Results: []gen.TimezoneEntry{}, - }, - validateFunc: func(c client.Collection[client.TimezoneResult]) { - suite.Empty(c.Results) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - // Use the exported constructor to test via SDK client - result := client.ExportTimezoneCollectionFromGen(tc.input) - tc.validateFunc(result) - }) - } -} - -func (suite *TimezoneTypesPublicTestSuite) TestTimezoneMutationCollectionFromUpdate() { - testUUID := openapi_types.UUID{ - 0x55, 0x0e, 0x84, 0x00, - 0xe2, 0x9b, 0x41, 0xd4, - 0xa7, 0x16, 0x44, 0x66, - 0x55, 0x44, 0x00, 0x00, - } - changedTrue := true - - tests := []struct { - name string - input *gen.TimezoneUpdateResponse - validateFunc func(client.Collection[client.TimezoneMutationResult]) - }{ - { - name: "converts full response", - input: &gen.TimezoneUpdateResponse{ - JobId: &testUUID, - Results: []gen.TimezoneMutationResult{ - { - Hostname: "agent1", - Status: gen.TimezoneMutationResultStatusOk, - Timezone: strPtr("America/New_York"), - Changed: &changedTrue, - }, - }, - }, - validateFunc: func(c client.Collection[client.TimezoneMutationResult]) { - suite.Equal("550e8400-e29b-41d4-a716-446655440000", c.JobID) - suite.Require().Len(c.Results, 1) - suite.Equal("agent1", c.Results[0].Hostname) - suite.Equal("ok", c.Results[0].Status) - suite.Equal("America/New_York", c.Results[0].Timezone) - suite.True(c.Results[0].Changed) - }, - }, - { - name: "converts response with nil optional fields", - input: &gen.TimezoneUpdateResponse{ - Results: []gen.TimezoneMutationResult{ - { - Hostname: "agent1", - Status: gen.TimezoneMutationResultStatusSkipped, - Error: strPtr("unsupported"), - }, - }, - }, - validateFunc: func(c client.Collection[client.TimezoneMutationResult]) { - suite.Require().Len(c.Results, 1) - suite.Equal("skipped", c.Results[0].Status) - suite.False(c.Results[0].Changed) - suite.Equal("unsupported", c.Results[0].Error) - }, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - result := client.ExportTimezoneMutationCollectionFromUpdate(tc.input) - tc.validateFunc(result) - }) - } -} - -func TestTimezoneTypesPublicTestSuite(t *testing.T) { - suite.Run(t, new(TimezoneTypesPublicTestSuite)) -}