gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/hexdump/hexdump_test.go (about)

     1  // Copyright 2017 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"testing"
    10  
    11  	"github.com/u-root/u-root/pkg/testutil"
    12  )
    13  
    14  var tests = []struct {
    15  	in  []byte
    16  	out []byte
    17  }{
    18  	{
    19  		in: []byte("abcdefghijklmnopqrstuvwxyz"),
    20  		out: []byte(
    21  			`00000000  61 62 63 64 65 66 67 68  69 6a 6b 6c 6d 6e 6f 70  |abcdefghijklmnop|
    22  00000010  71 72 73 74 75 76 77 78  79 7a                    |qrstuvwxyz|
    23  `),
    24  	},
    25  }
    26  
    27  func TestHexdump(t *testing.T) {
    28  	for _, tt := range tests {
    29  		cmd := testutil.Command(t)
    30  		cmd.Stdin = bytes.NewReader(tt.in)
    31  		out, err := cmd.CombinedOutput()
    32  		if err != nil {
    33  			t.Fatal(err)
    34  		}
    35  
    36  		if !bytes.Equal(out, tt.out) {
    37  			t.Errorf("want=%#v; got=%#v", tt.out, tt)
    38  		}
    39  	}
    40  }
    41  
    42  func TestMain(m *testing.M) {
    43  	testutil.Run(m, main)
    44  }