-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ServerToAgent_RequestRestart flag to request agent restart
- Loading branch information
Showing
8 changed files
with
501 additions
and
424 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/open-telemetry/opamp-go/client/types" | ||
"github.com/open-telemetry/opamp-go/protobufs" | ||
) | ||
|
||
type TestLogger struct { | ||
*testing.T | ||
} | ||
|
||
func (logger TestLogger) Debugf(format string, v ...interface{}) { | ||
logger.Logf(format, v...) | ||
} | ||
|
||
func TestRequestRestart(t *testing.T) { | ||
called := false | ||
|
||
callbacks := types.CallbacksStruct{ | ||
OnRestartRequestedFunc: func() error { | ||
called = true | ||
return nil | ||
}, | ||
} | ||
receiver := NewReceiver(TestLogger{t}, callbacks, nil, nil) | ||
receiver.processReceivedMessage(context.Background(), &protobufs.ServerToAgent{ | ||
Flags: protobufs.ServerToAgent_RequestRestart, | ||
}) | ||
assert.Equal(t, true, called, "requestRestart flag should trigger the OnRestartRequested callback") | ||
} | ||
|
||
func TestNoRequestRestart(t *testing.T) { | ||
called := false | ||
callbacks := types.CallbacksStruct{ | ||
OnRestartRequestedFunc: func() error { | ||
called = true | ||
return nil | ||
}, | ||
} | ||
receiver := NewReceiver(TestLogger{t}, callbacks, nil, nil) | ||
receiver.processReceivedMessage(context.Background(), &protobufs.ServerToAgent{ | ||
Flags: 0, | ||
}) | ||
assert.Equal(t, false, called, "without RequestRestart flag, do not trigger the OnRestartRequested callback") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.