mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-12 00:45:31 +00:00
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package helpers
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestStringToBytes(t *testing.T) {
|
|
type args struct {
|
|
s string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []byte
|
|
}{
|
|
{
|
|
name: "TestStringToBytes",
|
|
args: args{
|
|
s: "hello world",
|
|
},
|
|
want: []byte("hello world"),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := StringToBytes(tt.args.s); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("StringToBytes() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBytesToString(t *testing.T) {
|
|
type args struct {
|
|
b []byte
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
want string
|
|
args args
|
|
}{
|
|
{
|
|
name: "TestBytesToString",
|
|
args: args{
|
|
b: []byte("hello world"),
|
|
},
|
|
want: "hello world",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := BytesToString(tt.args.b); got != tt.want {
|
|
t.Errorf("BytesToString() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkStringToBytes(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
StringToBytes("hello world")
|
|
}
|
|
}
|
|
|
|
func BenchmarkBytesToString(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
BytesToString([]byte("hello world"))
|
|
}
|
|
}
|