github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/mount/mtd/chips_test.go (about)

     1  // Copyright 2019 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 mtd
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  func TestFindVendor(t *testing.T) {
    13  	var tests = []struct {
    14  		id VendorID
    15  		v  VendorName
    16  		e  error
    17  	}{
    18  		{0xba, "ZETTADEVICE", nil},
    19  		{0x123451234, "", fmt.Errorf("%v: not a known vendor", 0x123451234)},
    20  	}
    21  
    22  	for _, tt := range tests {
    23  		v, err := VendorFromID(tt.id)
    24  		if fmt.Sprintf("%v", err) != fmt.Sprintf("%v", tt.e) {
    25  			t.Errorf("%v: got %v want %v", tt.id, err, tt.e)
    26  		}
    27  		if tt.e != nil {
    28  			continue
    29  		}
    30  		if v.Name() != tt.v {
    31  			t.Errorf("%v: got (%q) want (%q)", tt.id, v.Name(), tt.v)
    32  		}
    33  
    34  	}
    35  }
    36  
    37  func TestFindDevice(t *testing.T) {
    38  	var tests = []struct {
    39  		v  VendorName
    40  		id ChipID
    41  		d  ChipName
    42  		e  error
    43  	}{
    44  		{"WINBOND", 0x32, "W49V002FA", nil},
    45  		// Test a synonym
    46  		{"AMD", 0x0212, "S25FL004A", nil},
    47  		{"ZETTADEVICE", 0xaa66aa44, "", fmt.Errorf("no chip with id 0xaa66aa44 for vendor [\"Zetta\"]")},
    48  	}
    49  
    50  	for _, tt := range tests {
    51  		v, err := VendorFromName(tt.v)
    52  		t.Logf("vformname %v", v)
    53  		if err != nil {
    54  			t.Errorf("VendorFromName(%v): got %v, want nil", tt.v, err)
    55  		}
    56  		d, err := v.Chip(tt.id)
    57  		if fmt.Sprintf("%v", err) != fmt.Sprintf("%v", tt.e) {
    58  			t.Errorf("(%q,%v): got %v want %v", tt.v, tt.id, err, tt.e)
    59  		}
    60  		if tt.e != nil {
    61  			continue
    62  		}
    63  		t.Logf("%s", d.Name())
    64  		if d.Name() != tt.d {
    65  			t.Errorf("(%q, %#x): got (%q) want (%q)", tt.v, tt.id, d, tt.d)
    66  		}
    67  
    68  	}
    69  }