mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
6169766666
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
* Update attestationFromCert function to include ccPlatform parameter for enhanced attestation processing Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: migrate dependencies from supermq to magistrala and update build configurations Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: update project dependencies, repository source, and support TDX QuoteV5 attestation Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package logging
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
mglog "github.com/absmach/magistrala/logger"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/ultravioletrs/cocos/agent/events/mocks"
|
|
"github.com/ultravioletrs/cocos/pkg/manager"
|
|
)
|
|
|
|
func TestStdoutWrite(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "Single line",
|
|
input: "Hello, World!",
|
|
expected: []string{"Hello, World!"},
|
|
},
|
|
{
|
|
name: "Multiple lines",
|
|
input: "Line 1\nLine 2\nLine 3",
|
|
expected: []string{"Line 1\nLine 2\nLine 3"},
|
|
},
|
|
{
|
|
name: "Long input",
|
|
input: strings.Repeat("a", bufSize+100),
|
|
expected: []string{strings.Repeat("a", bufSize), strings.Repeat("a", 100)},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
stdout := &Stdout{Logger: mglog.NewMock()}
|
|
n, err := stdout.Write([]byte(tt.input))
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, len(tt.input), n)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestStderrWrite(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "Single line",
|
|
input: "Error: Something went wrong",
|
|
expected: []string{"Error: Something went wrong"},
|
|
},
|
|
{
|
|
name: "Multiple lines",
|
|
input: "Error 1\nError 2\nError 3",
|
|
expected: []string{"Error 1\nError 2\nError 3"},
|
|
},
|
|
{
|
|
name: "Long input",
|
|
input: strings.Repeat("e", bufSize+100),
|
|
expected: []string{strings.Repeat("e", bufSize), strings.Repeat("e", 100)},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
mockEventService := mocks.NewService(t)
|
|
mockEventService.On("SendEvent", mock.Anything, "AlgorithmRun", manager.Warning.String(), mock.Anything).Return(nil)
|
|
|
|
stderr := &Stderr{Logger: mglog.NewMock(), EventSvc: mockEventService}
|
|
n, err := stderr.Write([]byte(tt.input))
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, len(tt.input), n)
|
|
mockEventService.AssertExpectations(t)
|
|
})
|
|
}
|
|
}
|