summaryrefslogtreecommitdiffstats
path: root/modules/util/pack_test.go
blob: 42ada89b81f43f455f7ad6fa513a339f5af2033b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package util

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestPackAndUnpackData(t *testing.T) {
	s := "string"
	i := int64(4)
	f := float32(4.1)

	var s2 string
	var i2 int64
	var f2 float32

	data, err := PackData(s, i, f)
	require.NoError(t, err)

	require.NoError(t, UnpackData(data, &s2, &i2, &f2))
	require.NoError(t, UnpackData(data, &s2))
	require.Error(t, UnpackData(data, &i2))
	require.Error(t, UnpackData(data, &s2, &f2))
}