Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit 07a31b4

Browse files
committed
pkg/analysis/importalias: add tests
1 parent 00ba86c commit 07a31b4

File tree

7 files changed

+2021
-0
lines changed

7 files changed

+2021
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright Project Contour Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package importalias
15+
16+
import (
17+
"os"
18+
"os/exec"
19+
"path/filepath"
20+
"testing"
21+
22+
"golang.org/x/tools/go/analysis/analysistest"
23+
)
24+
25+
func TestAnalyzer(t *testing.T) {
26+
t.Parallel()
27+
28+
testdata := analysistest.TestData()
29+
30+
testCases := []struct {
31+
desc string
32+
pkg string
33+
}{
34+
{
35+
desc: "Valid imports",
36+
pkg: "a",
37+
},
38+
{
39+
desc: "Invalid imports",
40+
pkg: "b",
41+
},
42+
}
43+
44+
for _, test := range testCases {
45+
test := test
46+
t.Run(test.desc, func(t *testing.T) {
47+
t.Parallel()
48+
49+
cmd := exec.Command("go", "mod", "vendor")
50+
cmd.Dir = filepath.Join(testdata, "src", test.pkg)
51+
52+
t.Cleanup(func() {
53+
_ = os.RemoveAll(filepath.Join(testdata, "src", test.pkg, "vendor"))
54+
})
55+
56+
if err := cmd.Run(); err != nil {
57+
t.Fatal(err)
58+
}
59+
60+
analysistest.Run(t, testdata, Analyzer, test.pkg)
61+
})
62+
}
63+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright Project Contour Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package a
15+
16+
import (
17+
// envoy_api_v2_auth "github.com/envoyproxy/go-control-plane/envoy/api/v2/auth"
18+
envoy_config_filter_http_ext_authz_v2 "github.com/envoyproxy/go-control-plane/envoy/config/filter/http/ext_authz/v2"
19+
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
20+
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
21+
kingpin_v2 "gopkg.in/alecthomas/kingpin.v2"
22+
api_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
api_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
gateway_v1alpha1 "sigs.k8s.io/gateway-api/apis/v1alpha1"
26+
gatewayapi_v1alpha1 "sigs.k8s.io/gateway-api/apis/v1alpha1"
27+
)
28+
29+
func foo() {
30+
meta_v1.Now()
31+
api_meta_v1.Now()
32+
api_v1.Now()
33+
// _ = envoy_api_v2_auth.CertificateValidationContext_ACCEPT_UNTRUSTED
34+
_ = envoy_config_filter_http_ext_authz_v2.AuthorizationRequest{}
35+
contour_api_v1.AddKnownTypes(nil)
36+
_ = contour_api_v1alpha1.GroupVersion
37+
kingpin_v2.Parse()
38+
_ = gatewayapi_v1alpha1.GroupVersion
39+
_ = gateway_v1alpha1.GroupVersion
40+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/projectcontour/lint/pkg/analysis/importalias/testdata/src/src/a
2+
3+
go 1.16
4+
5+
require (
6+
github.com/envoyproxy/go-control-plane v0.9.8
7+
github.com/projectcontour/contour v1.13.0
8+
gopkg.in/alecthomas/kingpin.v2 v2.2.6
9+
k8s.io/apimachinery v0.20.4
10+
sigs.k8s.io/gateway-api v0.2.0
11+
)

0 commit comments

Comments
 (0)