From b39a0f422d66a09ddfdad0a223e10e72c4f5b485 Mon Sep 17 00:00:00 2001 From: Wade Simmons Date: Wed, 11 Dec 2019 10:13:19 -0500 Subject: [PATCH] Fix nebula-cert tests on darwin and windows This fixes a couple issues: - NoSuchFileError not defined for darwin. - ca_test and sign_test do a bunch of filesystem specific tests that error differently on Windows. Just disable these tests on Windows for now. - Make the signcert test more deterministic by only testing one existing file at a time. --- cmd/nebula-cert/ca_test.go | 2 ++ cmd/nebula-cert/sign_test.go | 9 +++++++++ cmd/nebula-cert/test_darwin.go | 4 ++++ 3 files changed, 15 insertions(+) create mode 100644 cmd/nebula-cert/test_darwin.go diff --git a/cmd/nebula-cert/ca_test.go b/cmd/nebula-cert/ca_test.go index 4abd394..e8e20ae 100644 --- a/cmd/nebula-cert/ca_test.go +++ b/cmd/nebula-cert/ca_test.go @@ -1,3 +1,5 @@ +// +build !windows + package main import ( diff --git a/cmd/nebula-cert/sign_test.go b/cmd/nebula-cert/sign_test.go index a278545..da49294 100644 --- a/cmd/nebula-cert/sign_test.go +++ b/cmd/nebula-cert/sign_test.go @@ -1,3 +1,5 @@ +// +build !windows + package main import ( @@ -262,6 +264,7 @@ func Test_signCert(t *testing.T) { assert.Nil(t, signCert(args, ob, eb)) // test that we won't overwrite existing key file + os.Remove(crtF.Name()) ob.Reset() eb.Reset() args = []string{"-ca-crt", caCrtF.Name(), "-ca-key", caKeyF.Name(), "-name", "test", "-ip", "1.1.1.1/24", "-out-crt", crtF.Name(), "-out-key", keyF.Name(), "-duration", "100m", "-subnets", "10.1.1.1/32, , 10.2.2.2/32 , , ,, 10.5.5.5/32", "-groups", "1,, 2 , ,,,3,4,5"} @@ -269,6 +272,12 @@ func Test_signCert(t *testing.T) { assert.Empty(t, ob.String()) assert.Empty(t, eb.String()) + // create valid cert/key for overwrite tests + os.Remove(keyF.Name()) + os.Remove(crtF.Name()) + args = []string{"-ca-crt", caCrtF.Name(), "-ca-key", caKeyF.Name(), "-name", "test", "-ip", "1.1.1.1/24", "-out-crt", crtF.Name(), "-out-key", keyF.Name(), "-duration", "100m", "-subnets", "10.1.1.1/32, , 10.2.2.2/32 , , ,, 10.5.5.5/32", "-groups", "1,, 2 , ,,,3,4,5"} + assert.Nil(t, signCert(args, ob, eb)) + // test that we won't overwrite existing certificate file os.Remove(keyF.Name()) ob.Reset() diff --git a/cmd/nebula-cert/test_darwin.go b/cmd/nebula-cert/test_darwin.go new file mode 100644 index 0000000..7276dfa --- /dev/null +++ b/cmd/nebula-cert/test_darwin.go @@ -0,0 +1,4 @@ +package main + +const NoSuchFileError = "no such file or directory" +const NoSuchDirError = "no such file or directory"