github.com/hugelgupf/u-root@v0.0.0-20191023214958-4807c632154c/cmds/core/shasum/shasum_test.go (about)

     1  // Copyright 2018 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  	"testing"
     9  
    10  	"github.com/u-root/u-root/pkg/testutil"
    11  )
    12  
    13  func TestCksum(t *testing.T) {
    14  	var testMatrix = []struct {
    15  		data      []byte
    16  		cksum     string
    17  		algorithm int
    18  	}{
    19  		{[]byte("abcdef\n"), "bdc37c074ec4ee6050d68bc133c6b912f36474df", 1},
    20  		{[]byte("pqra\n"), "e8ed2d487f1dc32152c8590f39c20b7703f9e159", 1},
    21  		{[]byte("abcdef\n"), "ae0666f161fed1a5dde998bbd0e140550d2da0db27db1d0e31e370f2bd366a57", 256},
    22  		{[]byte("pqra\n"), "db296dd0bcb796df9b327f44104029da142c8fff313a25bd1ac7c3b7562caea9", 256},
    23  	}
    24  
    25  	for _, testData := range testMatrix {
    26  		if testData.cksum != shaPrinter(testData.algorithm, testData.data) {
    27  			t.Errorf("shasum verification failed.(Expected:%s, Received:%s)", testData.cksum, shaPrinter(testData.algorithm, testData.data))
    28  		}
    29  	}
    30  
    31  }
    32  
    33  func TestMain(m *testing.M) {
    34  	testutil.Run(m, main)
    35  }