-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal/tls test #485
internal/tls test #485
Changes from all commits
a314cd3
fb22b4f
4e9a292
8d2d9e5
2d5326e
d874042
f98d5b0
2cf693e
206faab
fb00e58
93bb0db
f7f8d87
06cb7db
4ce264a
6981070
e814f21
e94a488
d8debd5
dbd4a3f
a3c5d28
eac37ae
91f32fc
f3ca8e7
c3437c6
da77a2d
9bebdd8
53733fd
f52b03c
0e59520
c618c63
585dfd2
ea04cde
72e687b
5e2c0c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDoTCCAomgAwIBAgILBAAAAAABD4WqLUgwDQYJKoZIhvcNAQEFBQAwOzEYMBYG | ||
A1UEChMPQ3liZXJ0cnVzdCwgSW5jMR8wHQYDVQQDExZDeWJlcnRydXN0IEdsb2Jh | ||
bCBSb290MB4XDTA2MTIxNTA4MDAwMFoXDTIxMTIxNTA4MDAwMFowOzEYMBYGA1UE | ||
ChMPQ3liZXJ0cnVzdCwgSW5jMR8wHQYDVQQDExZDeWJlcnRydXN0IEdsb2JhbCBS | ||
b290MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA+Mi8vRRQZhP/8NN5 | ||
7CPytxrHjoXxEnOmGaoQ25yiZXRadz5RfVb23CO21O1fWLE3TdVJDm71aofW0ozS | ||
J8bi/zafmGWgE07GKmSb1ZASzxQG9Dvj1Ci+6A74q05IlG2OlTEQXO2iLb3VOm2y | ||
HLtgwEZLAfVJrn5GitB0jaEMAs7u/OePuGtm839EAL9mJRQr3RAwHQeWP032a7iP | ||
t3sMpTjr3kfb1V05/Iin89cqdPHoWqI7n1C6poxFNcJQZZXcY4Lv3b93TZxiyWNz | ||
FtApD0mpSPCzqrdsxacwOUBdrsTiXSZT8M4cIwhhqJQZugRiQOwfOHB3EgZxpzAY | ||
XSUnpQIDAQABo4GlMIGiMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/ | ||
MB0GA1UdDgQWBBS2CHsNesysIEyGVjJez6tuhS1wVzA/BgNVHR8EODA2MDSgMqAw | ||
hi5odHRwOi8vd3d3Mi5wdWJsaWMtdHJ1c3QuY29tL2NybC9jdC9jdHJvb3QuY3Js | ||
MB8GA1UdIwQYMBaAFLYIew16zKwgTIZWMl7Pq26FLXBXMA0GCSqGSIb3DQEBBQUA | ||
A4IBAQBW7wojoFROlZfJ+InaRcHUowAl9B8Tq7ejhVhpwjCt2BWKLePJzYFa+HMj | ||
Wqd8BfP9IjsO0QbE2zZMcwSO5bAi5MXzLqXZI+O4Tkogp24CJJ8iYGd7ix1yCcUx | ||
XOl5n4BHPa2hCwcUPUf/A2kaDAtE52Mlp3+yybh2hO0j9n0Hq0V+09+zv+mKts2o | ||
omcrUtW3ZfA5TGOgkXmTUg9U3YO7n9GPp1Nzw8v/MOx8BLjYRB+TX3EJIrduPuoc | ||
A06dGiBh+4E37F78CkWr1+cXVdCg6mCbpvbjjFspwgZgFJ0tl0ypkxWdYcQBX0jW | ||
WL1WMRJOEcgh4LMRkWXbtKaIOM5V | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIC/jCCAeYCCQCb1aA3TeyoljANBgkqhkiG9w0BAQUFADBBMQswCQYDVQQGEwJK | ||
UDEOMAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCWNoaXlvZGFrdTEOMAwGA1UECgwF | ||
eWFob28wHhcNMTgwOTE4MDMxMjQyWhcNMjgwOTE1MDMxMjQyWjBBMQswCQYDVQQG | ||
EwJKUDEOMAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCWNoaXlvZGFrdTEOMAwGA1UE | ||
CgwFeWFob28wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDUBKwhDHGl | ||
yj5GFOhDlyH67BsW9l/A2rna21WVnq69ANN9WmaiFp32C+2BrqF8DYwtPyoaTgXd | ||
+WQ8wmtjlYwp378P743vBgf6tazZYKbCa7PZsNMLCdI0KurXf6iwOkCY7zQQcOji | ||
STUVtfr009LFgc8KBduxBiyEe1tXoN1qrjUZgty/05EtW09QFE2XqVFQS4jN6CC4 | ||
whmN3J7yWHyZv3K1lO0aeC31kIOqw0/DxD/Dj/RMJBpz0q3jeYJwvM3rE4DNajTW | ||
6BLiPWVkLW4H3paRE6jYfyCRazE8tLLWHzGGqPWUElV2rKWzdV6OnyWLFxWC2RK/ | ||
71IuZS1UDqmHAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBAFaGiKYXqlKhqHDND/RJ | ||
oJnZfgEYca6urTKHgmYYu3SJRe6Gf3j/1NZZJ9EKr9vGIiFhpKOHcdnBkeXEweWK | ||
7+8yyCxG7Uw3Ixw7jQPQ/bAzb7CJ8Q2Ogsj1EqSHbPoOyu2a0fYCu3rLomDVNdbn | ||
9BX2ywyiUonV36H773DrAbe0a/+LhThW9SftUyeyK+0RIU4PML0C5rQWUxNsz6yR | ||
OIkfFdRA10nOqIfV2jVHbNT7bnMI9HLBpltbfoY7SBEFncRdEbkGvemjUIB7YAe4 | ||
sjosi65MZ/BcCUcC0s8tczl1/e/UjoJ/uC91APKFSmKu2RltBNVTLxSpAxZv+2bV | ||
SGI= | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpQIBAAKCAQEA1ASsIQxxpco+RhToQ5ch+uwbFvZfwNq52ttVlZ6uvQDTfVpm | ||
ohad9gvtga6hfA2MLT8qGk4F3flkPMJrY5WMKd+/D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6n5pIkarZHu5AcswH9nXRfbxfZZ8pT35ThKU9i7pQEDnul | ||
llKWByYhDt2ddY1ViQBolJ8hF61UaQ+J+ExyAhH41Kh+qvSgQ42acExfrsP0rSuo | ||
kwImBP7e6vl83qQaqNz5b7ECgYEAlgVUjKz2fCM5o/cveZXgR2nGDuDPuvMc3PJN | ||
NzVblx/LRJvdfqU/BNtq4WncMEVtFE2aIg3VjTLbjwJEnCFIovRT14LZ/9GKeRFK | ||
SwqK8c/tdrOVxN09hp40eAWERZoxDOTVPuaWUnHwRtS+AtGBwRhx9SbiVLx9Fgmm | ||
OGjGBY0CgYEAr2Go4s2QBQXpvJPdYSUGi/osF1jfntIL0JydqBOy9xx9R6d/CvWX | ||
8ekhlYdXLZPmgUoZ8EIBlULRs+8XJRn1zXGBUu1hEdU8rO7WdkHV6tJBIw6mSppV | ||
btGQ8m0qKBLMJco77ZZCjp5lsG/Af308ojuK/DJcomH1slxyTkSYEjg= | ||
-----END RSA PRIVATE KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invalid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invalid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
kevindiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Package test provides functions for general testing use | ||
package test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kevindiu please submit package description There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote it on |
||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// GetTestdataPath returns the test data file path under `internal/test/data` | ||
func GetTestdataPath(filename string) string { | ||
fp, _ := filepath.Abs(baseDir() + "/internal/test/data/" + filename) | ||
return fp | ||
} | ||
|
||
func baseDir() string { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
for cur := filepath.Dir(wd); cur != "/"; cur = filepath.Dir(cur) { | ||
if strings.HasSuffix(cur, "vald") { | ||
return cur | ||
} | ||
} | ||
return "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// | ||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package test | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"go.uber.org/goleak" | ||
) | ||
|
||
func TestGetTestdataPath(t *testing.T) { | ||
type args struct { | ||
filename string | ||
} | ||
type want struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
want string | ||
} | ||
type test struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
name string | ||
args args | ||
want want | ||
checkFunc func(want, string) error | ||
beforeFunc func(args) | ||
afterFunc func(args) | ||
} | ||
defaultCheckFunc := func(w want, got string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
if !reflect.DeepEqual(got, w.want) { | ||
return errors.Errorf("got = %v, want %v", got, w.want) | ||
} | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
} | ||
tests := []test{ | ||
{ | ||
name: "returns the result of combining the given path and test directory", | ||
args: args{ | ||
filename: "tls/dummyCa.pem", | ||
}, | ||
want: want{ | ||
want: func() string { | ||
return baseDir() + "/internal/test/data/tls/dummyCa.pem" | ||
}(), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
defer goleak.VerifyNone(tt) | ||
if test.beforeFunc != nil { | ||
test.beforeFunc(test.args) | ||
} | ||
if test.afterFunc != nil { | ||
defer test.afterFunc(test.args) | ||
} | ||
if test.checkFunc == nil { | ||
test.checkFunc = defaultCheckFunc | ||
} | ||
|
||
got := GetTestdataPath(test.args.filename) | ||
if err := test.checkFunc(test.want, got); err != nil { | ||
tt.Errorf("error = %v", err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_baseDir(t *testing.T) { | ||
type want struct { | ||
want string | ||
} | ||
type test struct { | ||
name string | ||
want want | ||
checkFunc func(want, string) error | ||
beforeFunc func() | ||
afterFunc func() | ||
} | ||
defaultCheckFunc := func(w want, got string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
if !reflect.DeepEqual(got, w.want) { | ||
return errors.Errorf("got = %v, want %v", got, w.want) | ||
} | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
} | ||
tests := []test{ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add an abnormal test ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you for your comment. Since it only return the file path, I couldn't think any abnormal test.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kevindiu please add error pattern test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanna to add it but I couldn't think of any error pattern for testing (as it called |
||
name: "check testdata.go exists", | ||
checkFunc: func(w want, got string) error { | ||
_, err := os.Stat(got + "/internal/test/testdata.go") | ||
return err | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
defer goleak.VerifyNone(tt) | ||
if test.beforeFunc != nil { | ||
test.beforeFunc() | ||
} | ||
if test.afterFunc != nil { | ||
defer test.afterFunc() | ||
} | ||
if test.checkFunc == nil { | ||
test.checkFunc = defaultCheckFunc | ||
} | ||
|
||
got := baseDir() | ||
if err := test.checkFunc(test.want, got); err != nil { | ||
tt.Errorf("error = %v", err) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golangci] reported by reviewdog 🐶
package comment should be of the form "Package test ..." (golint)