* chore: code cleanup
This commit is contained in:
Shwetha Radhakrishna 2021-05-20 09:44:46 -07:00 коммит произвёл GitHub
Родитель 0304c4cf21
Коммит 1a513a8b07
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 48 добавлений и 52 удалений

4
.github/workflows/golangci-lint.yml поставляемый
Просмотреть файл

@ -10,8 +10,6 @@ jobs:
with:
fetch-depth: 0
- name: golangci-lint
uses: golangci/golangci-lint-action@v2.5.2
uses: golangci/golangci-lint-action@v2
with:
version: latest
github-token: ${{ secrets.github_token }}
only-new-issues: true

1
go.mod
Просмотреть файл

@ -3,6 +3,7 @@ module github.com/twilio/terraform-provider-twilio
go 1.16
require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.4
github.com/joho/godotenv v1.3.0
github.com/stretchr/testify v1.7.0

4
go.sum
Просмотреть файл

@ -591,10 +591,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1
github.com/tomarrell/wrapcheck v1.0.0/go.mod h1:Bd3i1FaEKe3XmcPoHhNQ+HM0S8P6eIXoQIoGj/ndJkU=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
github.com/tommy-muehle/go-mnd/v2 v2.3.1/go.mod h1:WsUAkMJMYww6l/ufffCD3m+P7LEvr8TnZn9lwVDlgzw=
github.com/twilio/twilio-go v0.7.1-0.20210511195028-5b98eca17aee h1:nJD1jUU6nPlmLpUOgH7hb6uEz1nRMIjpDoXa5BqZuaQ=
github.com/twilio/twilio-go v0.7.1-0.20210511195028-5b98eca17aee/go.mod h1:7KyNHcmMcBifTtf1YPaVBnXP7aE6I2RE45Alo0gjWBs=
github.com/twilio/twilio-go v0.7.1-0.20210517164903-3f2595863a35 h1:BYmz+fQqmLg2JvyIa8jIpleFbSiFOQT+ROkWi8Zjkto=
github.com/twilio/twilio-go v0.7.1-0.20210517164903-3f2595863a35/go.mod h1:7KyNHcmMcBifTtf1YPaVBnXP7aE6I2RE45Alo0gjWBs=
github.com/twilio/twilio-go v0.8.0 h1:XnPJ87qUSbUIhm3BMjqGgh5aiNgobXK2CrqGcNm/omw=
github.com/twilio/twilio-go v0.8.0/go.mod h1:7KyNHcmMcBifTtf1YPaVBnXP7aE6I2RE45Alo0gjWBs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=

Просмотреть файл

@ -86,7 +86,7 @@ func processParamValue(paramType string, form *url.Values, field reflect.StructF
func FormEncoder(src interface{}) (url.Values, error) {
if src == nil {
return nil, CreateErrorGeneric(fmt.Sprintf("Nil form provided"))
return nil, CreateErrorGeneric("Nil form provided")
}
srcType := reflect.TypeOf(src)

Просмотреть файл

@ -316,8 +316,7 @@ func marshallNode(setter func(string, interface{}) error, fieldName string, fiel
return setter(fieldName, value)
} else {
// TF expects typed nil!
var value *interface{}
value = nil
var value *interface{} = nil
return setter(fieldName, value)
}
}
@ -368,7 +367,7 @@ func marshallNode(setter func(string, interface{}) error, fieldName string, fiel
if fieldValue.IsNil() {
return setter(fieldName, nil)
}
sliceTarget := make([]interface{}, fieldValue.Len(), fieldValue.Len())
sliceTarget := make([]interface{}, fieldValue.Len(), fieldValue.Len()) //nolint
sliceSetter := func(name string, value interface{}) error {
index, err := strconv.ParseInt(name[strings.LastIndex(name, ".")+1:], 10, 32)
if err != nil {

Просмотреть файл

@ -611,7 +611,7 @@ func TestComplexMarshal(t *testing.T) {
testString := "t0"
testSid := AccountSid{}
testSid.Set("AC00112233445566778899aabbccddeeff")
_ = testSid.Set("AC00112233445566778899aabbccddeeff")
testString2 := "2010-04-01"
testInt := 1

Просмотреть файл

@ -8,7 +8,7 @@ import (
func QueryEncoder(src interface{}) (string, error) {
if src == nil {
return "", CreateErrorGeneric(fmt.Sprintf("Nil query provided"))
return "", CreateErrorGeneric("Nil query provided")
}
srcType := reflect.TypeOf(src)

Просмотреть файл

@ -3,6 +3,8 @@ package common
import (
"fmt"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
@ -105,11 +107,11 @@ func AsSid(sid SidInterface, conf *options) *schema.Schema {
Type: schema.TypeString,
}
if !conf.Computed {
ret.ValidateFunc = func(val interface{}, key string) (warns []string, errs []error) {
ret.ValidateDiagFunc = func(val interface{}, path cty.Path) diag.Diagnostics {
if err := sid.Set(val); err != nil {
return []string{}, []error{err}
return diag.FromErr(err)
}
return []string{}, []error{}
return nil
}
}
return addSchemaOptions(ret, conf)

Просмотреть файл

@ -8,65 +8,65 @@ import (
)
func TestRequiredSchema(t *testing.T) {
schema := AsInt(SchemaRequired)
assert.Equal(t, false, schema.Optional, "Invalid options")
assert.Equal(t, true, schema.Required, "Invalid options")
assert.Equal(t, false, schema.Computed, "Invalid options")
assert.Equal(t, false, schema.ForceNew, "Invalid options")
testSchema := AsInt(SchemaRequired)
assert.Equal(t, false, testSchema.Optional, "Invalid options")
assert.Equal(t, true, testSchema.Required, "Invalid options")
assert.Equal(t, false, testSchema.Computed, "Invalid options")
assert.Equal(t, false, testSchema.ForceNew, "Invalid options")
}
func TestOptionalSchema(t *testing.T) {
schema := AsInt(SchemaOptional)
assert.Equal(t, true, schema.Optional, "Invalid options")
assert.Equal(t, false, schema.Required, "Invalid options")
assert.Equal(t, false, schema.Computed, "Invalid options")
assert.Equal(t, false, schema.ForceNew, "Invalid options")
testSchema := AsInt(SchemaOptional)
assert.Equal(t, true, testSchema.Optional, "Invalid options")
assert.Equal(t, false, testSchema.Required, "Invalid options")
assert.Equal(t, false, testSchema.Computed, "Invalid options")
assert.Equal(t, false, testSchema.ForceNew, "Invalid options")
}
func TestComputedSchema(t *testing.T) {
schema := AsInt(SchemaComputed)
assert.Equal(t, false, schema.Optional, "Invalid options")
assert.Equal(t, false, schema.Required, "Invalid options")
assert.Equal(t, true, schema.Computed, "Invalid options")
assert.Equal(t, false, schema.ForceNew, "Invalid options")
testSchema := AsInt(SchemaComputed)
assert.Equal(t, false, testSchema.Optional, "Invalid options")
assert.Equal(t, false, testSchema.Required, "Invalid options")
assert.Equal(t, true, testSchema.Computed, "Invalid options")
assert.Equal(t, false, testSchema.ForceNew, "Invalid options")
}
func TestForceNewRequiredSchemaSchema(t *testing.T) {
schema := AsInt(SchemaForceNewRequired)
assert.Equal(t, false, schema.Optional, "Invalid options")
assert.Equal(t, true, schema.Required, "Invalid options")
assert.Equal(t, false, schema.Computed, "Invalid options")
assert.Equal(t, true, schema.ForceNew, "Invalid options")
testSchema := AsInt(SchemaForceNewRequired)
assert.Equal(t, false, testSchema.Optional, "Invalid options")
assert.Equal(t, true, testSchema.Required, "Invalid options")
assert.Equal(t, false, testSchema.Computed, "Invalid options")
assert.Equal(t, true, testSchema.ForceNew, "Invalid options")
}
func TestForceNewRequiredOptionalSchema(t *testing.T) {
schema := AsInt(SchemaForceNewOptional)
assert.Equal(t, true, schema.Optional, "Invalid options")
assert.Equal(t, false, schema.Required, "Invalid options")
assert.Equal(t, false, schema.Computed, "Invalid options")
assert.Equal(t, true, schema.ForceNew, "Invalid options")
testSchema := AsInt(SchemaForceNewOptional)
assert.Equal(t, true, testSchema.Optional, "Invalid options")
assert.Equal(t, false, testSchema.Required, "Invalid options")
assert.Equal(t, false, testSchema.Computed, "Invalid options")
assert.Equal(t, true, testSchema.ForceNew, "Invalid options")
}
func TestInvalidEmptySchema(t *testing.T) {
defer func() { recover() }()
defer func() { _ = recover() }()
AsInt(&options{})
t.Errorf("Invalid schema allowed")
}
func TestInvalidComputedRequiredSchema(t *testing.T) {
defer func() { recover() }()
defer func() { _ = recover() }()
AsInt(&options{Required: true, Computed: true})
t.Errorf("Invalid schema allowed")
}
func TestInvalidComputedOptionalSchema(t *testing.T) {
defer func() { recover() }()
defer func() { _ = recover() }()
AsInt(&options{Optional: true, Computed: true})
t.Errorf("Invalid schema allowed")
}
func TestInvalidComputedForcenewSchema(t *testing.T) {
defer func() { recover() }()
defer func() { _ = recover() }()
AsInt(&options{ForceNew: true, Computed: true})
t.Errorf("Invalid schema allowed")
}
@ -95,11 +95,11 @@ func TestSidSchema(t *testing.T) {
s := AsSid(&Sid{}, SchemaRequired)
assert.Equal(t, schema.TypeString, s.Type, "Invalid type")
_, errs := s.ValidateFunc("XX00112233445566778899aabbccddeeff", "test")
assert.Empty(t, errs, "Sid validate errored")
err := s.ValidateDiagFunc("XX00112233445566778899aabbccddeeff", nil)
assert.Empty(t, err, "Sid errored")
_, errs = s.ValidateFunc("abc", "test")
assert.NotEmpty(t, errs, "Sid validate did not error")
err = s.ValidateDiagFunc("abc", nil)
assert.NotEmpty(t, err, "Sid validate did not error")
}
func TestListSchemaScalar(t *testing.T) {

Просмотреть файл

@ -176,7 +176,7 @@ func TestGenericJsonMarshal(t *testing.T) {
}
m := MarshalTest{}
m.Sid.Set("XY00112233445566778899aabbccddeeff")
_ = m.Sid.Set("XY00112233445566778899aabbccddeeff")
resp, err := json.Marshal(m)
if err != nil {
t.Errorf("Marshal failed '%v'", err)
@ -835,7 +835,7 @@ func TestWorkflowSidJsonUnmarshal(t *testing.T) {
func TestCanCreateRandomSid(t *testing.T) {
rq := RequestSid{}
assert.False(t, rq.Valid, "It's just a reference")
rq.Randomize(&rq)
_ = rq.Randomize(&rq)
assert.True(t, rq.Valid, "It's just a reference")
}
@ -845,6 +845,6 @@ func TestCanNotCreateRandomSidOnValue(t *testing.T) {
// This panics because it expects pointer rq.Randomize(&rq);
// and Randomize method cannot declare Randomize(t *interface{})
// because Cannot use 'rq' (type RequestSid) as type *interface{}
rq.Randomize(rq)
_ = rq.Randomize(rq)
})
}