mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-18 14:56:17 -05:00
chore: Upgrade golangci-lint to next major version (#686)
* chore: Upgrade golangci-lint to next major version * chore: Add //nolint to new tests --------- Co-authored-by: Martin Wentzel <junker@monoceres.uberspace.de>
This commit is contained in:
parent
64b95701e3
commit
dacb5dfe73
17 changed files with 54 additions and 39 deletions
4
.github/workflows/golangci-lint.yaml
vendored
4
.github/workflows/golangci-lint.yaml
vendored
|
|
@ -19,6 +19,6 @@ jobs:
|
|||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
uses: golangci/golangci-lint-action@v7
|
||||
with:
|
||||
version: v1.57
|
||||
version: v2.1.1
|
||||
|
|
|
|||
|
|
@ -1,7 +1,14 @@
|
|||
linters-settings:
|
||||
errcheck:
|
||||
# https://github.com/hashicorp/terraform-provider-aws/blob/9c9a116a857fb838a0e7d1cfbf420c2524f0abe1/.golangci.yml#L37-L39
|
||||
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close
|
||||
version: "2"
|
||||
|
||||
linters:
|
||||
settings:
|
||||
errcheck:
|
||||
# https://github.com/hashicorp/terraform-provider-aws/blob/9c9a116a857fb838a0e7d1cfbf420c2524f0abe1/.golangci.yml#L37-L39
|
||||
exclude-functions:
|
||||
- github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close
|
||||
- (*github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.ResourceData).Set
|
||||
- io.Close
|
||||
|
||||
|
||||
|
||||
run:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ TEST?=$$(go list ./... |grep -v 'vendor')
|
|||
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
|
||||
PKG_NAME=internal/provider
|
||||
|
||||
GOLANGCI_VERSION = 1.49.0
|
||||
GOLANGCI_VERSION = 2.1.1
|
||||
|
||||
# Values to install the provider locally for testing purposes
|
||||
HOSTNAME=registry.terraform.io
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func buildHTTPClientFromBytes(caPEMCert, certPEMBlock, keyPEMBlock []byte) (*htt
|
|||
} else {
|
||||
caPool := x509.NewCertPool()
|
||||
if !caPool.AppendCertsFromPEM(caPEMCert) {
|
||||
return nil, errors.New("Could not add RootCA pem")
|
||||
return nil, errors.New("could not add RootCA pem")
|
||||
}
|
||||
tlsConfig.RootCAs = caPool
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ func dataSourceDockerLogsRead(ctx context.Context, d *schema.ResourceData, meta
|
|||
if err != nil {
|
||||
return diag.Errorf("dataSourceDockerLogsRead: error while asking for logs %s", err)
|
||||
}
|
||||
defer readCloser.Close()
|
||||
defer readCloser.Close() //nolint:errcheck
|
||||
|
||||
// see https://github.com/moby/moby/issues/7375#issuecomment-51462963
|
||||
discard := d.Get("discard_headers").(bool)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
}
|
||||
|
||||
func TestProvider_impl(t *testing.T) {
|
||||
var _ *schema.Provider = New("dev")()
|
||||
var _ = New("dev")()
|
||||
}
|
||||
|
||||
func TestProvider(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ func resourceDockerConfigRead(ctx context.Context, d *schema.ResourceData, meta
|
|||
log.Printf("[DEBUG] Docker config inspect from readFunc: %s", jsonObj)
|
||||
|
||||
d.SetId(config.ID)
|
||||
d.Set("name", config.Spec.Name)
|
||||
d.Set("data", base64.StdEncoding.EncodeToString(config.Spec.Data))
|
||||
d.Set("name", config.Spec.Name) //nolint:errcheck
|
||||
d.Set("data", base64.StdEncoding.EncodeToString(config.Spec.Data)) //nolint:errcheck
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -86,6 +86,6 @@ func resourceDockerConfigDelete(ctx context.Context, d *schema.ResourceData, met
|
|||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
d.SetId("") //nolint:errcheck
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,8 @@ func resourceDockerContainerCreate(ctx context.Context, d *schema.ResourceData,
|
|||
mountInstance.ReadOnly = value.(bool)
|
||||
}
|
||||
|
||||
if mountType == mount.TypeBind {
|
||||
// QF1003: could use tagged switch on mountType
|
||||
if mountType == mount.TypeBind { //nolint:staticcheck
|
||||
if value, ok := rawMount["bind_options"]; ok {
|
||||
if len(value.([]interface{})) > 0 {
|
||||
mountInstance.BindOptions = &mount.BindOptions{}
|
||||
|
|
@ -521,8 +522,8 @@ func resourceDockerContainerCreate(ctx context.Context, d *schema.ResourceData,
|
|||
if err != nil {
|
||||
result <- fmt.Errorf("error inspecting container state: %s", err)
|
||||
}
|
||||
//infos.ContainerJSONBase.State.Health is only set when there is a healthcheck defined on the container resource
|
||||
if infos.ContainerJSONBase.State.Health.Status == types.Healthy {
|
||||
// QF1008: could remove embedded field "ContainerJSONBase" from selector
|
||||
if infos.ContainerJSONBase.State.Health.Status == types.Healthy { //nolint:staticcheck
|
||||
log.Printf("[DEBUG] container state is healthy")
|
||||
break
|
||||
}
|
||||
|
|
@ -564,7 +565,7 @@ func resourceDockerContainerCreate(ctx context.Context, d *schema.ResourceData,
|
|||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer reader.Close()
|
||||
defer reader.Close() //nolint:errcheck
|
||||
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
|
|
@ -870,7 +871,8 @@ func resourceDockerContainerUpdate(ctx context.Context, d *schema.ResourceData,
|
|||
if a > 0 {
|
||||
a = a * 1024 * 1024
|
||||
}
|
||||
updateConfig.Resources.MemorySwap = a
|
||||
// QF1008: could remove embedded field "Resources" from selector
|
||||
updateConfig.Resources.MemorySwap = a //nolint:staticcheck
|
||||
}
|
||||
client := meta.(*ProviderConfig).DockerClient
|
||||
_, err := client.ContainerUpdate(ctx, d.Id(), updateConfig)
|
||||
|
|
@ -936,7 +938,8 @@ func resourceDockerContainerDelete(ctx context.Context, d *schema.ResourceData,
|
|||
func fetchDockerContainer(ctx context.Context, ID string, client *client.Client) (*types.Container, error) {
|
||||
apiContainers, err := client.ContainerList(ctx, types.ContainerListOptions{All: true})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error fetching container information from Docker: %s\n", err)
|
||||
// ST1005: error strings should not end with punctuation or newlines
|
||||
return nil, fmt.Errorf("error fetching container information from Docker: %s\n", err) //nolint:staticcheck
|
||||
}
|
||||
|
||||
for _, apiContainer := range apiContainers {
|
||||
|
|
|
|||
|
|
@ -1069,7 +1069,8 @@ func TestAccDockerContainer_port_internal(t *testing.T) {
|
|||
var c types.ContainerJSON
|
||||
|
||||
testCheck := func(*terraform.State) error {
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports
|
||||
// QF1008: could remove embedded field "NetworkSettingsBase" from selector
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports //nolint:staticcheck
|
||||
portBindings, ok := portMap["80/tcp"]
|
||||
if !ok || len(portMap["80/tcp"]) == 0 {
|
||||
return fmt.Errorf("Port 80 on tcp is not set")
|
||||
|
|
@ -1116,7 +1117,8 @@ func TestAccDockerContainer_port_multiple_internal(t *testing.T) {
|
|||
var c types.ContainerJSON
|
||||
|
||||
testCheck := func(*terraform.State) error {
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports
|
||||
// QF1008: could remove embedded field "NetworkSettingsBase" from selector
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports //nolint:staticcheck
|
||||
portBindings, ok := portMap["80/tcp"]
|
||||
if !ok || len(portMap["80/tcp"]) == 0 {
|
||||
return fmt.Errorf("Port 80 on tcp is not set")
|
||||
|
|
@ -1185,7 +1187,8 @@ func TestAccDockerContainer_port(t *testing.T) {
|
|||
var c types.ContainerJSON
|
||||
|
||||
testCheck := func(*terraform.State) error {
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports
|
||||
// QF1008: could remove embedded field "NetworkSettingsBase" from selector
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports //nolint:staticcheck
|
||||
portBindings, ok := portMap["80/tcp"]
|
||||
if !ok || len(portMap["80/tcp"]) == 0 {
|
||||
return fmt.Errorf("Port 80 on tcp is not set")
|
||||
|
|
@ -1240,7 +1243,8 @@ func TestAccDockerContainer_multiple_ports(t *testing.T) {
|
|||
var c types.ContainerJSON
|
||||
|
||||
testCheck := func(*terraform.State) error {
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports
|
||||
// QF1008: could remove embedded field "NetworkSettingsBase" from selector
|
||||
portMap := c.NetworkSettings.NetworkSettingsBase.Ports //nolint:staticcheck
|
||||
portBindings, ok := portMap["80/tcp"]
|
||||
if !ok || len(portMap["80/tcp"]) == 0 {
|
||||
return fmt.Errorf("Port 80 on tcp is not set")
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ func pullImage(ctx context.Context, data *Data, client *client.Client, authConfi
|
|||
if err != nil {
|
||||
return fmt.Errorf("error pulling image %s: %w", image, err)
|
||||
}
|
||||
defer out.Close()
|
||||
defer out.Close() //nolint:errcheck
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
if _, err := buf.ReadFrom(out); err != nil {
|
||||
|
|
@ -362,7 +362,7 @@ func buildDockerImage(ctx context.Context, rawBuild map[string]interface{}, imag
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
defer response.Body.Close() //nolint:errcheck
|
||||
|
||||
buildResult, err := decodeBuildMessages(response)
|
||||
if err != nil {
|
||||
|
|
@ -386,7 +386,7 @@ func enableBuildKitIfSupported(
|
|||
}
|
||||
//nolint
|
||||
go s.Run(ctx, dialSession)
|
||||
defer s.Close()
|
||||
defer s.Close() //nolint:errcheck
|
||||
buildOptions.SessionID = s.ID()
|
||||
buildOptions.Version = types.BuilderBuildKit
|
||||
return s
|
||||
|
|
@ -413,7 +413,7 @@ func prepareBuildContext(specifiedContext string, specifiedDockerfile string) (i
|
|||
if err != nil {
|
||||
return nil, "", errors.Errorf("unable to open Dockerfile: %v", err)
|
||||
}
|
||||
defer dockerfileCtx.Close()
|
||||
defer dockerfileCtx.Close() //nolint:errcheck
|
||||
}
|
||||
excludes, err := build.ReadDockerignore(contextDir)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ func TestAccDockerImage_build(t *testing.T) {
|
|||
if err := os.WriteFile(dfPath, []byte(testDockerFileExample), 0o644); err != nil {
|
||||
t.Fatalf("failed to create a Dockerfile %s for test: %+v", dfPath, err)
|
||||
}
|
||||
defer os.Remove(dfPath)
|
||||
defer os.Remove(dfPath) //nolint:errcheck
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
ProviderFactories: providerFactories,
|
||||
|
|
@ -469,7 +469,7 @@ func TestAccDockerImageSecrets_build(t *testing.T) {
|
|||
if err := os.WriteFile(dfPath, []byte(testDockerFileWithSecret), 0o644); err != nil {
|
||||
t.Fatalf("failed to create a Dockerfile %s for test: %+v", dfPath, err)
|
||||
}
|
||||
defer os.Remove(dfPath)
|
||||
defer os.Remove(dfPath) //nolint:errcheck
|
||||
|
||||
const secretContent = "THIS IS A SECRET"
|
||||
sPath := filepath.Join(wd, "secret")
|
||||
|
|
@ -477,7 +477,7 @@ func TestAccDockerImageSecrets_build(t *testing.T) {
|
|||
t.Fatalf("failed to create a secret file %s for test: %+v", sPath, err)
|
||||
}
|
||||
|
||||
defer os.Remove(sPath)
|
||||
defer os.Remove(sPath) //nolint:errcheck
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
|
@ -516,7 +516,7 @@ func TestAccDockerImage_buildOutsideContext(t *testing.T) {
|
|||
if err := os.WriteFile(dfPath, []byte(testDockerFileExample), 0o644); err != nil {
|
||||
t.Fatalf("failed to create a Dockerfile %s for test: %+v", dfPath, err)
|
||||
}
|
||||
defer os.Remove(dfPath)
|
||||
defer os.Remove(dfPath) //nolint:errcheck
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
ProviderFactories: providerFactories,
|
||||
|
|
@ -622,7 +622,7 @@ func TestAccDockerImageResource_buildWithDockerignore(t *testing.T) {
|
|||
if err != nil {
|
||||
panic("failed to create test file")
|
||||
}
|
||||
f.Close()
|
||||
f.Close() //nolint:errcheck
|
||||
},
|
||||
Config: fmt.Sprintf(loadTestConfiguration(t, RESOURCE, "docker_image", "testBuildDockerImageNoKeepJustCache"), "two", name, context),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
|
|
@ -657,7 +657,7 @@ func testAccImageCreated(resourceName string, image *types.ImageInspect) resourc
|
|||
// TODO mavogel: it's because we set the ID in the format:
|
||||
// d.SetId(foundImage.ID + d.Get("name").(string))
|
||||
// so we need to strip away the name
|
||||
strippedID := strings.Replace(rs.Primary.ID, name, "", -1)
|
||||
strippedID := strings.ReplaceAll(rs.Primary.ID, name, "")
|
||||
|
||||
client := testAccProvider.Meta().(*ProviderConfig).DockerClient
|
||||
inspectedImage, _, err := client.ImageInspectWithRaw(ctx, strippedID)
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ func resourceDockerNetworkReadRefreshFunc(ctx context.Context,
|
|||
d.Set("ipam_options", retNetwork.IPAM.Options)
|
||||
d.Set("scope", retNetwork.Scope)
|
||||
if retNetwork.Scope == "overlay" {
|
||||
if retNetwork.Options != nil && len(retNetwork.Options) != 0 {
|
||||
if len(retNetwork.Options) != 0 {
|
||||
d.Set("options", retNetwork.Options)
|
||||
} else {
|
||||
log.Printf("[DEBUG] options: %v not exposed", retNetwork.Options)
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ func pushDockerRegistryImage(ctx context.Context, client *client.Client, pushOpt
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
defer out.Close() //nolint:errcheck
|
||||
|
||||
type ErrorMessage struct {
|
||||
Error string
|
||||
|
|
|
|||
|
|
@ -100,7 +100,8 @@ func resourceDockerSecretCreate(ctx context.Context, d *schema.ResourceData, met
|
|||
}
|
||||
|
||||
if v, ok := d.GetOk("labels"); ok {
|
||||
secretSpec.Annotations.Labels = labelSetToMap(v.(*schema.Set))
|
||||
// QF1008: could remove embedded field "Annotations" from selector
|
||||
secretSpec.Annotations.Labels = labelSetToMap(v.(*schema.Set)) //nolint:staticcheck
|
||||
}
|
||||
|
||||
secret, err := client.SecretCreate(ctx, secretSpec)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func main() {
|
|||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write([]byte(fmt.Sprintf("%s - Hello World!", configs.Prefix)))
|
||||
_, err = w.Write([]byte(fmt.Sprintf("%s - Hello World!", configs.Prefix))) //nolint:staticcheck
|
||||
if err != nil {
|
||||
log.Fatalln("failed to write for path '/'")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func main() {
|
|||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write([]byte(fmt.Sprintf("%s - Hello World!", configs.Prefix)))
|
||||
_, err = w.Write([]byte(fmt.Sprintf("%s - Hello World!", configs.Prefix))) //nolint:staticcheck
|
||||
if err != nil {
|
||||
log.Fatalln("failed to write for path '/'")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func main() {
|
|||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write([]byte(fmt.Sprintf("%s - Hello World!", configs.Prefix)))
|
||||
_, err = w.Write([]byte(fmt.Sprintf("%s - Hello World!", configs.Prefix))) //nolint:staticcheck
|
||||
if err != nil {
|
||||
log.Fatalln("failed to write for path '/'")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue