Files
threshold/internal/session/connection_closed_with_test.go
T
Hugo Vieira d206635d74 fix(connection): Make bytes up and down a signed 64-bit integer
This fixes a theoretical issue with database interaction. Because the
fields in the database are signed 64-bit integers, it's theoretically
possible to overflow them if we're using unsigned 64-bit integers in the
application code.
2022-10-26 17:44:28 +01:00

69 lines
1.5 KiB
Go

package session
import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/iam"
)
func TestClosedWith_validate(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
wrapper := db.TestWrapper(t)
iamRepo := iam.TestRepo(t, conn, wrapper)
session := TestDefaultSession(t, conn, wrapper, iamRepo)
sessionConnection := TestConnection(t, conn, session.PublicId, "127.0.0.1", 22, "127.0.0.1", 2222, "127.0.0.1")
type fields struct {
ConnectionId string
BytesUp int64
BytesDown int64
ClosedReason ClosedReason
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "valid",
fields: fields{
ConnectionId: sessionConnection.PublicId,
BytesUp: 1,
BytesDown: 2,
ClosedReason: ConnectionClosedByUser,
},
},
{
name: "missing-ConnectionId",
fields: fields{
BytesUp: 1,
BytesDown: 2,
ClosedReason: ConnectionClosedByUser,
},
wantErr: true,
},
{
name: "missing-ClosedReason",
fields: fields{
ConnectionId: sessionConnection.PublicId,
BytesUp: 1,
BytesDown: 2,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := CloseWith{
ConnectionId: tt.fields.ConnectionId,
BytesUp: tt.fields.BytesUp,
BytesDown: tt.fields.BytesDown,
ClosedReason: tt.fields.ClosedReason,
}
if err := c.validate(); (err != nil) != tt.wantErr {
t.Errorf("ClosedWith.validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}