github.com/pion/dtls/v2@v2.2.12/pkg/protocol/change_cipher_spec_test.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package protocol
     5  
     6  import (
     7  	"errors"
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestChangeCipherSpecRoundTrip(t *testing.T) {
    13  	c := ChangeCipherSpec{}
    14  	raw, err := c.Marshal()
    15  	if err != nil {
    16  		t.Error(err)
    17  	}
    18  
    19  	var cNew ChangeCipherSpec
    20  	if err := cNew.Unmarshal(raw); err != nil {
    21  		t.Error(err)
    22  	}
    23  
    24  	if !reflect.DeepEqual(c, cNew) {
    25  		t.Errorf("ChangeCipherSpec round trip: got %#v, want %#v", cNew, c)
    26  	}
    27  }
    28  
    29  func TestChangeCipherSpecInvalid(t *testing.T) {
    30  	c := ChangeCipherSpec{}
    31  	if err := c.Unmarshal([]byte{0x00}); !errors.Is(err, errInvalidCipherSpec) {
    32  		t.Errorf("ChangeCipherSpec invalid assert: got %#v, want %#v", err, errInvalidCipherSpec)
    33  	}
    34  }