Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqixu committed Aug 23, 2024
1 parent 52d2bef commit fe827f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions client/internal/httpsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ func TestHTTPSenderRetryForStatusTooManyRequests(t *testing.T) {
srv.Close()
}

func TestHTTPSenderSetHeartbeatInterval(t *testing.T) {
sender := NewHTTPSender(&sharedinternal.NopLogger{})

// Default interval should be 30s as per OpAMP Specification
assert.Equal(t, (30 * time.Second).Milliseconds(), sender.pollingIntervalMs)

// zero is invalid for http sender
sender.SetHeartbeatInterval(0)
assert.Equal(t, (30 * time.Second).Milliseconds(), sender.pollingIntervalMs)

// zero should be valid for http sender
expected := 10 * time.Second
sender.SetHeartbeatInterval(expected)
assert.Equal(t, expected.Milliseconds(), sender.pollingIntervalMs)
}

func TestAddTLSConfig(t *testing.T) {
sender := NewHTTPSender(&sharedinternal.NopLogger{})

Expand Down
24 changes: 24 additions & 0 deletions client/internal/wssender_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package internal

import (
"testing"
"time"

sharedinternal "github.com/open-telemetry/opamp-go/internal"
"github.com/stretchr/testify/assert"
)

func TestWSSenderSetHeartbeatInterval(t *testing.T) {
sender := NewSender(&sharedinternal.NopLogger{})

// Default interval should be 30s as per OpAMP Specification
assert.Equal(t, int64((30 * time.Second).Seconds()), sender.heartbeatIntervalSeconds.Load())

// zero is valid for ws sender
sender.SetHeartbeatInterval(0)
assert.Equal(t, int64(0), sender.heartbeatIntervalSeconds.Load())

var expected int64 = 10
sender.SetHeartbeatInterval(time.Duration(expected) * time.Second)
assert.Equal(t, expected, sender.heartbeatIntervalSeconds.Load())
}

0 comments on commit fe827f5

Please sign in to comment.