summaryrefslogtreecommitdiff
path: root/util/pinmap/pm/reader_test.go
blob: ca004eab6a514b3024955fb4cbcf5cc3d564eeff (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package pm_test

import (
	"testing"

	"reflect"

	"pinmap/pm"
)

type testReader struct {
	name string
	key  string
	arg  string
	pins pm.Pins
}

func (r *testReader) Name() string {
	return r.name
}

func (r *testReader) Read(key, arg string) (*pm.Pins, error) {
	r.key = key
	r.arg = arg
	return &r.pins, nil
}

func TestReader(t *testing.T) {
	n := "Test1"
	tr1 := &testReader{name: n}
	pm.RegisterReader(tr1)
	p, err := pm.ReadPins(n, "key", "arg1")
	if err != nil {
		t.Errorf("Error %v on reading pins", err)
	}
	if p != &tr1.pins {
		t.Errorf("Did not match Pins")
	}
	p, err = pm.ReadPins("notMine", "key", "arg1")
	if err == nil {
		t.Errorf("Should heve returned error")
	}
	readers := pm.Readers()
	exp := []string{n}
	if !reflect.DeepEqual(exp, readers) {
		t.Errorf("Expected %v, got %v", exp, readers)
	}
}