File: random_test.go

package info (click to toggle)
golang-github-u-root-uio 0.0~git20240224.d2acac8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 276 kB
  • sloc: sh: 25; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 743 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
35
36
// Copyright 2019 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package rand

import (
	"context"
	"testing"
	"time"
)

func TestRandomRead(t *testing.T) {
	b := make([]byte, 5)
	n, err := Read(b)
	if err != nil {
		t.Fatalf("got %v, expected nil err", err)
	}
	if n != 5 {
		t.Fatalf("got %d bytes, expected 5 bytes", n)
	}
}

func TestRandomReadContext(t *testing.T) {
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	b := make([]byte, 5)
	n, err := ReadContext(ctx, b)
	if err != nil {
		t.Fatalf("got %v, expected nil err", err)
	}
	if n != 5 {
		t.Fatalf("got %d bytes, expected 5 bytes", n)
	}
}