mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
Change check-lint to use golangci-lint (#3465)
golint is deprecated. The author of the code no longer supports the codebase. golangci-lint is faster than golint, and is in use by other opa repositories (e.g. Gatekeeper). This commit changes tools.go to reference golangci (so it ends up in vendor) and modifies check-lint to use golangci instead. Breaking API Changes: - plugins/rest/rest.go: Fix typo "AllowInsureTLS" -> "AllowInsecureTLS" - storage/errors.go: Removed unused IndexingNotSupportedErr Signed-off-by: Will Beason <willbeason@google.com>
This commit is contained in:
@@ -187,7 +187,7 @@ func (p *Plugin) Stop(ctx context.Context) {
|
||||
p.manager.UnregisterPluginStatusListener(Name)
|
||||
done := make(chan struct{})
|
||||
p.stop <- done
|
||||
_ = <-done
|
||||
<-done
|
||||
p.manager.UpdatePluginStatus(Name, &plugins.Status{State: plugins.StateNotReady})
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,10 @@ func TestPluginStart(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
fixture.plugin.Start(ctx)
|
||||
err := fixture.plugin.Start(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fixture.plugin.Stop(ctx)
|
||||
|
||||
// Start will trigger a status update when the plugin state switches
|
||||
@@ -61,10 +64,10 @@ func TestPluginStart(t *testing.T) {
|
||||
|
||||
status := testStatus()
|
||||
|
||||
fixture.plugin.UpdateBundleStatus(*status)
|
||||
fixture.plugin.BulkUpdateBundleStatus(map[string]*bundle.Status{"test": status})
|
||||
result = <-fixture.server.ch
|
||||
|
||||
exp.Bundle = status
|
||||
exp.Bundles = map[string]*bundle.Status{"test": status}
|
||||
|
||||
if !reflect.DeepEqual(result, exp) {
|
||||
t.Fatalf("Expected: %v but got: %v", exp, result)
|
||||
@@ -79,12 +82,15 @@ func TestPluginStartBulkUpdate(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
fixture.plugin.Start(ctx)
|
||||
err := fixture.plugin.Start(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fixture.plugin.Stop(ctx)
|
||||
|
||||
// Start will trigger a status update when the plugin state switches
|
||||
// from "not ready" to "ok".
|
||||
result := <-fixture.server.ch
|
||||
<-fixture.server.ch // Discard first request.
|
||||
|
||||
exp := UpdateRequestV1{
|
||||
Labels: map[string]string{
|
||||
@@ -100,7 +106,7 @@ func TestPluginStartBulkUpdate(t *testing.T) {
|
||||
status := testStatus()
|
||||
|
||||
fixture.plugin.BulkUpdateBundleStatus(map[string]*bundle.Status{status.Name: status})
|
||||
result = <-fixture.server.ch
|
||||
result := <-fixture.server.ch
|
||||
|
||||
exp.Bundles = map[string]*bundle.Status{status.Name: status}
|
||||
|
||||
@@ -117,15 +123,18 @@ func TestPluginStartBulkUpdateMultiple(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
fixture.plugin.Start(ctx)
|
||||
err := fixture.plugin.Start(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fixture.plugin.Stop(ctx)
|
||||
|
||||
// Ignore the plugin updating its status (tested elsewhere)
|
||||
<-fixture.server.ch
|
||||
|
||||
statuses := map[string]*bundle.Status{}
|
||||
tDownload, _ := time.Parse("2018-01-01T00:00:00.0000000Z", time.RFC3339Nano)
|
||||
tActivate, _ := time.Parse("2018-01-01T00:00:01.0000000Z", time.RFC3339Nano)
|
||||
tDownload, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:00.0000000Z")
|
||||
tActivate, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:01.0000000Z")
|
||||
for i := 0; i < 20; i++ {
|
||||
name := fmt.Sprintf("test-bundle-%d", i)
|
||||
statuses[name] = &bundle.Status{
|
||||
@@ -172,7 +181,10 @@ func TestPluginStartDiscovery(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
fixture.plugin.Start(ctx)
|
||||
err := fixture.plugin.Start(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fixture.plugin.Stop(ctx)
|
||||
|
||||
// Ignore the plugin updating its status (tested elsewhere)
|
||||
@@ -205,7 +217,7 @@ func TestPluginBadAuth(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fixture.server.expCode = 401
|
||||
defer fixture.server.stop()
|
||||
fixture.plugin.lastBundleStatus = &bundle.Status{}
|
||||
fixture.plugin.lastBundleStatuses = map[string]*bundle.Status{}
|
||||
err := fixture.plugin.oneShot(ctx)
|
||||
if err == nil {
|
||||
t.Fatal("Expected error")
|
||||
@@ -217,7 +229,7 @@ func TestPluginBadPath(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fixture.server.expCode = 404
|
||||
defer fixture.server.stop()
|
||||
fixture.plugin.lastBundleStatus = &bundle.Status{}
|
||||
fixture.plugin.lastBundleStatuses = map[string]*bundle.Status{}
|
||||
err := fixture.plugin.oneShot(ctx)
|
||||
if err == nil {
|
||||
t.Fatal("Expected error")
|
||||
@@ -229,7 +241,7 @@ func TestPluginBadStatus(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fixture.server.expCode = 500
|
||||
defer fixture.server.stop()
|
||||
fixture.plugin.lastBundleStatus = &bundle.Status{}
|
||||
fixture.plugin.lastBundleStatuses = map[string]*bundle.Status{}
|
||||
err := fixture.plugin.oneShot(ctx)
|
||||
if err == nil {
|
||||
t.Fatal("Expected error")
|
||||
@@ -245,10 +257,10 @@ func TestPluginReconfigure(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pluginConfig := []byte(fmt.Sprintf(`{
|
||||
pluginConfig := []byte(`{
|
||||
"service": "example",
|
||||
"partition_name": "test"
|
||||
}`))
|
||||
}`)
|
||||
|
||||
config, _ := ParseConfig(pluginConfig, fixture.manager.Services(), nil)
|
||||
|
||||
@@ -267,7 +279,10 @@ func TestMetrics(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
fixture.plugin.Start(ctx)
|
||||
err := fixture.plugin.Start(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fixture.plugin.Stop(ctx)
|
||||
|
||||
// Ignore the plugin updating its status (tested elsewhere)
|
||||
@@ -292,11 +307,11 @@ func TestParseConfigUseDefaultServiceNoConsole(t *testing.T) {
|
||||
"s3",
|
||||
}
|
||||
|
||||
loggerConfig := []byte(fmt.Sprintf(`{
|
||||
loggerConfig := []byte(`{
|
||||
"console": false
|
||||
}`))
|
||||
}`)
|
||||
|
||||
config, err := ParseConfig([]byte(loggerConfig), services, nil)
|
||||
config, err := ParseConfig(loggerConfig, services, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
@@ -314,11 +329,11 @@ func TestParseConfigDefaultServiceWithConsole(t *testing.T) {
|
||||
"s3",
|
||||
}
|
||||
|
||||
loggerConfig := []byte(fmt.Sprintf(`{
|
||||
loggerConfig := []byte(`{
|
||||
"console": true
|
||||
}`))
|
||||
}`)
|
||||
|
||||
config, err := ParseConfig([]byte(loggerConfig), services, nil)
|
||||
config, err := ParseConfig(loggerConfig, services, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
@@ -330,12 +345,12 @@ func TestParseConfigDefaultServiceWithConsole(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseConfigDefaultServiceWithNoServiceOrConsole(t *testing.T) {
|
||||
loggerConfig := []byte(fmt.Sprintf(`{}`))
|
||||
loggerConfig := []byte(`{}`)
|
||||
|
||||
_, err := ParseConfig([]byte(loggerConfig), []string{}, nil)
|
||||
_, err := ParseConfig(loggerConfig, []string{}, nil)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error but err==nil")
|
||||
t.Error("Expected an error but err==nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,9 +393,9 @@ func newTestFixture(t *testing.T, m metrics.Metrics, options ...testPluginCustom
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pluginConfig := []byte(fmt.Sprintf(`{
|
||||
pluginConfig := []byte(`{
|
||||
"service": "example",
|
||||
}`))
|
||||
}`)
|
||||
|
||||
config, _ := ParseConfig(pluginConfig, manager.Services(), nil)
|
||||
for _, option := range options {
|
||||
@@ -429,8 +444,8 @@ func (t *testServer) stop() {
|
||||
|
||||
func testStatus() *bundle.Status {
|
||||
|
||||
tDownload, _ := time.Parse("2018-01-01T00:00:00.0000000Z", time.RFC3339Nano)
|
||||
tActivate, _ := time.Parse("2018-01-01T00:00:01.0000000Z", time.RFC3339Nano)
|
||||
tDownload, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:00.0000000Z")
|
||||
tActivate, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:01.0000000Z")
|
||||
|
||||
status := bundle.Status{
|
||||
Name: "example/authz",
|
||||
@@ -474,8 +489,14 @@ func TestPluginCustomBackend(t *testing.T) {
|
||||
}
|
||||
|
||||
plugin := New(config, manager)
|
||||
plugin.oneShot(ctx)
|
||||
plugin.oneShot(ctx)
|
||||
err = plugin.oneShot(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = plugin.oneShot(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(backend.reqs) != 2 {
|
||||
t.Fatalf("Unexpected number of reqs: expected 2, got %d: %v", len(backend.reqs), backend.reqs)
|
||||
|
||||
Reference in New Issue
Block a user