This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fernandez Ludovic <[email protected]>
- Loading branch information
Showing
7 changed files
with
2,023 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright Project Contour Authors | ||
// 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 | ||
// | ||
// http://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 importalias | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis/analysistest" | ||
) | ||
|
||
func TestAnalyzer(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
|
||
testCases := []struct { | ||
desc string | ||
pkg string | ||
}{ | ||
{ | ||
desc: "Valid imports", | ||
pkg: "a", | ||
}, | ||
{ | ||
desc: "Invalid imports", | ||
pkg: "b", | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
test := test | ||
t.Run(test.desc, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
dir := filepath.Join(testdata, "src", test.pkg) | ||
|
||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { | ||
cmd := exec.Command("go", "mod", "vendor") | ||
cmd.Dir = dir | ||
|
||
t.Cleanup(func() { | ||
_ = os.RemoveAll(filepath.Join(testdata, "src", test.pkg, "vendor")) | ||
}) | ||
|
||
if output, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(err, string(output)) | ||
} | ||
} | ||
|
||
analysistest.Run(t, testdata, Analyzer, test.pkg) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright Project Contour Authors | ||
// 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 | ||
// | ||
// http://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 a | ||
|
||
import ( | ||
// envoy_api_v2_auth "github.com/envoyproxy/go-control-plane/envoy/api/v2/auth" | ||
envoy_config_filter_http_ext_authz_v2 "github.com/envoyproxy/go-control-plane/envoy/config/filter/http/ext_authz/v2" | ||
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1" | ||
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1" | ||
kingpin_v2 "gopkg.in/alecthomas/kingpin.v2" | ||
api_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
api_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
gateway_v1alpha1 "sigs.k8s.io/gateway-api/apis/v1alpha1" | ||
gatewayapi_v1alpha1 "sigs.k8s.io/gateway-api/apis/v1alpha1" | ||
) | ||
|
||
func foo() { | ||
meta_v1.Now() | ||
api_meta_v1.Now() | ||
api_v1.Now() | ||
// _ = envoy_api_v2_auth.CertificateValidationContext_ACCEPT_UNTRUSTED | ||
_ = envoy_config_filter_http_ext_authz_v2.AuthorizationRequest{} | ||
contour_api_v1.AddKnownTypes(nil) | ||
_ = contour_api_v1alpha1.GroupVersion | ||
kingpin_v2.Parse() | ||
_ = gatewayapi_v1alpha1.GroupVersion | ||
_ = gateway_v1alpha1.GroupVersion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module github.com/projectcontour/lint/pkg/analysis/importalias/testdata/src/src/a | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/envoyproxy/go-control-plane v0.9.8 | ||
github.com/projectcontour/contour v1.13.0 | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | ||
k8s.io/apimachinery v0.20.4 | ||
sigs.k8s.io/gateway-api v0.2.0 | ||
) |
Oops, something went wrong.