From 245a41f1fa992fefb396fc4591a2bbdd6858e525 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 4 Aug 2017 23:41:08 +0200 Subject: Split names --- names_test.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 names_test.go (limited to 'names_test.go') diff --git a/names_test.go b/names_test.go new file mode 100644 index 0000000..3fee0d0 --- /dev/null +++ b/names_test.go @@ -0,0 +1,65 @@ +package main + +import "testing" + +func TestCheckNames(t *testing.T) { + testCases := []struct { + pub, sec string + err error + }{ + {"key.pub", "key.sec", nil}, + {"testdata/key.pub", "key.sec", nil}, + {"key.pub", "testdata/key.sec", nil}, + {"foo.pub", "bar.sec", ErrNames}, + {"key.foo", "key.bar", ErrNames}, + } + for _, tc := range testCases { + t.Run(tc.pub+"+"+tc.sec, func(t *testing.T) { + err := ValidateNames(tc.pub, tc.sec) + if err != tc.err { + t.Errorf("got %v, want %v", err, tc.err) + } + }) + } +} + +func TestVerify(t *testing.T) { + testCases := []struct { + comment string + file string + }{ + {"verify with key.pub", "key.pub"}, + {"verify with s p a c e s.pub", "s p a c e s.pub"}, + {"verify with key.sec", ""}, + {"whatever", ""}, + } + for _, tc := range testCases { + t.Run(tc.comment, func(t *testing.T) { + file := CommentPubFile(tc.comment) + if file != tc.file { + t.Errorf("got %v, want %v", file, tc.file) + } + }) + } +} + +func TestSplit(t *testing.T) { + testCases := []struct { + fname, name, ext string + }{ + {"testkey.pub", "testkey", ".pub"}, + {"testkey", "testkey", ""}, + {".pub", "", ".pub"}, + {".testkey.pub", ".testkey", ".pub"}, + {"", "", ""}, + {"path/key.pub", "key", ".pub"}, + } + for _, tc := range testCases { + t.Run(tc.fname, func(t *testing.T) { + name, ext := splitNameExt(tc.fname) + if name != tc.name || ext != tc.ext { + t.Errorf("got %q %q, want %q %q", name, tc.name, ext, tc.ext) + } + }) + } +} -- cgit v1.2.3