Initial tests for platform.ID

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
Co-Authored-by: Lorenzo Fontana <lo@linux.com>
pull/10616/head
Leonardo Di Donato 2018-07-20 12:24:54 +02:00 committed by Leonardo Di Donato
parent d2a11aa77c
commit 5335c52c87
1 changed files with 47 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package platform
import (
"bytes"
"reflect"
"testing"
)
@ -36,3 +37,49 @@ func TestIDFromString(t *testing.T) {
})
}
}
func TestDecodeFromString(t *testing.T) {
var id1 ID
err := id1.DecodeFromString("020f755c3c082000")
if err != nil {
t.Errorf(err.Error())
}
want1 := []byte{48, 50, 48, 102, 55, 53, 53, 99, 51, 99, 48, 56, 50, 48, 48, 48}
byte1 := id1.Encode()
if !bytes.Equal(want1, byte1) {
t.Errorf("encoding error")
}
}
func TestDecodeFromShorterString(t *testing.T) {
var id1 ID
err := id1.DecodeFromString("020f75")
if err != nil {
t.Errorf(err.Error())
}
want1 := []byte{48, 50, 48, 102, 55, 53, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48}
byte1 := id1.Encode()
if !bytes.Equal(want1, byte1) {
t.Errorf("encoding error")
}
if id1.String() != "020f750000000000" {
t.Errorf("wrong id")
}
}
func TestDecodeFromLongerString(t *testing.T) {
var id1 ID
err := id1.DecodeFromString("020f755c3c082000aaa")
if err != nil {
t.Errorf(err.Error())
}
want1 := []byte{48, 50, 48, 102, 55, 53, 53, 99, 51, 99, 48, 56, 50, 48, 48, 48}
byte1 := id1.Encode()
if !bytes.Equal(want1, byte1) {
t.Errorf("encoding error")
}
}
// todo
// func TestDecodeFromEmptyString(t *testing.T) {}