From d47a37b197d37fda6ceb62f21194ff65e719cf66 Mon Sep 17 00:00:00 2001 From: garfthoffman <109185460+garfthoffman@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:12:11 +0000 Subject: [PATCH] add unit test, correct errors package Signed-off-by: garfthoffman <109185460+garfthoffman@users.noreply.github.com> --- go/vt/tableacl/tableacl.go | 2 +- go/vt/tableacl/tableacl_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go/vt/tableacl/tableacl.go b/go/vt/tableacl/tableacl.go index dd6638e9786..2bb48ca28f2 100644 --- a/go/vt/tableacl/tableacl.go +++ b/go/vt/tableacl/tableacl.go @@ -111,7 +111,7 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error { return err } if len(data) == 0 { - return error.New("tableACL config file is empty") + return errors.New("tableACL config file is empty") } config := &tableaclpb.Config{} diff --git a/go/vt/tableacl/tableacl_test.go b/go/vt/tableacl/tableacl_test.go index 388567b62e2..1f5e89a6a48 100644 --- a/go/vt/tableacl/tableacl_test.go +++ b/go/vt/tableacl/tableacl_test.go @@ -74,6 +74,21 @@ func TestInitWithValidConfig(t *testing.T) { } } +func TestInitWithEmptyConfig(t *testing.T) { + tacl := tableACL{factory: &simpleacl.Factory{}} + f, err := os.CreateTemp("", "tableacl") + if err != nil { + t.Fatal(err) + } + defer os.Remove(f.Name()) + if err := f.Close(); err != nil { + t.Fatal(err) + } + if err := tacl.init(f.Name(), func() {}); err == nil { + t.Fatal("tableACL config file is empty") + } +} + func TestInitFromProto(t *testing.T) { tacl := tableACL{factory: &simpleacl.Factory{}} readerACL := tacl.Authorized("my_test_table", READER)