diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..b4af68e --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,66 @@ +name: Build +on: + push: + branches: + - main + pull_request: +env: + go_version: 1.21.6 +jobs: + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Pin Golang version for linting + uses: actions/setup-go@v5 + with: + go-version: ${{ env.go_version }} + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55.2 + test: + name: go test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.go_version }} + - name: Set up gotestfmt + uses: GoTestTools/gotestfmt-action@v2 + - uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: go-test-${{ hashFiles('**/go.sum') }} + restore-keys: go-test- + - name: Run go test + run: | + set -euo pipefail + go generate + go test -coverprofile /tmp/coverage.out -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt + echo "# Code coverage summary" > /tmp/coverage.md + echo "|File|Type|Coverage|" >> /tmp/coverage.md + echo "|----|----|--------|" >> /tmp/coverage.md + go tool cover -func /tmp/coverage.out | sed -e 's/\s\s*/|/g' -e 's/^/|/g' -e 's/$/|/g' >> /tmp/coverage.md + + cat /tmp/coverage.md >> $GITHUB_STEP_SUMMARY + echo "::group::Code coverage summary" + go tool cover -func /tmp/coverage.out + echo "::endgroup::" + - name: Upload test log + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results + path: | + /tmp/gotest.log + /tmp/coverage.out + /tmp/coverage.md + if-no-files-found: error diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..996864c --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,96 @@ +run: + timeout: 5m +linters: + enable: + # region General + + # Add depguard to prevent adding additional dependencies. This is a client library, we really don't want + # additional dependencies. + - depguard + # Prevent improper directives in go.mod. + - gomoddirectives + # Prevent improper nolint directives. + - nolintlint + + # endregion + + + # region Code Quality and Comments + + # Inspect source code for potential security problems. This check has a fairly high false positive rate, + # comment with // nolint:gosec where not relevant. + - gosec + # Complain about deeply nested if cases. + - nestif + # Prevent naked returns in long functions. + - nakedret + # Make Go code more readable. + - gocritic + # Check if comments end in a period. This helps prevent incomplete comment lines, such as half-written sentences. + - godot + # Complain about comments as these indicate incomplete code. + - godox + # Keep the cyclomatic complexity of functions to a reasonable level. + - gocyclo + # Find repeated strings that could be converted into constants. + - goconst + # Complain about unnecessary type conversions. + - unconvert + # Complain about unused parameters. These should be replaced with underscores. + - unparam + # Check for non-ASCII identifiers. + - asciicheck + # Check for HTTP response body being closed. Sometimes, you may need to disable this using // nolint:bodyclose. + - bodyclose + # Check for duplicate code. You may want to disable this with // nolint:dupl if the source code is the same, but + # legitimately exists for different reasons. + - dupl + # Check for pointers in loops. This is a typical bug source. + - exportloopref + # Prevent dogsledding (mass-ignoring return values). This typically indicates missing error handling. + - dogsled + # Enforce consistent import aliases across all files. + - importas + # Make code properly formatted. + - gofmt + # Prevent faulty error checks. + - nilerr + # Prevent direct error checks that won't work with wrapped errors. + - errorlint + # Find slice usage that could potentially be preallocated. + - prealloc + # Check for improper duration handling. + - durationcheck + + # endregion +linters-settings: + depguard: + rules: + main: + list-mode: strict + files: + - "**/internal/*.go" + allow: + - $gostd + - go.flow.arcalot.io/ + - go.arcalot.io/ + - github.com/docker/ + - github.com/opencontainers/ + - gopkg.in/yaml.v3 + - github.com/fxamacker/cbor + - k8s.io/ + - sigs.k8s.io/ + - golang.org/ + - github.com/stretchr/testify + govet: + enable-all: true + check-shadowing: false + disable: + # We don't care about variable shadowing. + - shadow + - fieldalignment + stylecheck: + checks: + - all +issues: + exclude-use-default: false diff --git a/go.mod b/go.mod index 8fb6d4a..cbeb2a5 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module arcaflow-lib-kubernetes -go 1.19 +go 1.21 require ( github.com/stretchr/testify v1.8.4 - go.arcalot.io/lang v1.0.0 - go.flow.arcalot.io/pluginsdk v0.5.1 + go.arcalot.io/lang v1.1.0 + go.flow.arcalot.io/pluginsdk v0.8.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.28.4 k8s.io/client-go v0.28.4 diff --git a/go.sum b/go.sum index 2034220..6f6533b 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,7 @@ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+ github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -31,6 +32,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -41,6 +43,7 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -55,11 +58,15 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/onsi/ginkgo/v2 v2.9.4 h1:xR7vG4IXt5RWx6FfIjyAtsoMAtnc3C/rFXBBd2AjZwE= +github.com/onsi/ginkgo/v2 v2.9.4/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM= github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= +github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -71,13 +78,12 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.arcalot.io/assert v1.4.0 h1:X7ptZSl4WrB+jUn53Kzvp3aPWCSsCgUp4iW2wdLEOv4= -go.arcalot.io/lang v1.0.0 h1:mgDaieT4wWdZTnR4V7+/pgYRmzfU7VZZgIzHccuxAbY= -go.arcalot.io/lang v1.0.0/go.mod h1:ALqfYEhAzC2WoGLaycmJoNJd5NmkR7V1PSKp/c5D278= -go.flow.arcalot.io/pluginsdk v0.4.1 h1:sooyHRNCH/EIQJe+842qZJAgXHuffclFbc3hPMgbhCc= -go.flow.arcalot.io/pluginsdk v0.4.1/go.mod h1:8Gp8Q0Eo0s+2I4nNl3uQ95jPi2zFKEX7JqyjhmK7BiI= -go.flow.arcalot.io/pluginsdk v0.5.1 h1:ebb2ThAqmjmwGpDyKpd1wEDUisPqPabgARjFohy47Io= -go.flow.arcalot.io/pluginsdk v0.5.1/go.mod h1:2s2f//7uOkBjr1QaiWJD/bqDIeLlINJtD1BhiY4aGPM= +go.arcalot.io/assert v1.7.0 h1:PTLyeisNMUKpM9wXRDxResanBhuGOYO1xFK3v5b3FSw= +go.arcalot.io/assert v1.7.0/go.mod h1:nNmWPoNUHFyrPkNrD2aASm5yPuAfiWdB/4X7Lw3ykHk= +go.arcalot.io/lang v1.1.0 h1:ugglRKpd3qIMkdghAjKJxsziIgHm8QpxrzZPSXoa08I= +go.arcalot.io/lang v1.1.0/go.mod h1:2BZJO4csY7NnN/Nf1+eTdIQH4A2vxtOMneaO+PJl+Co= +go.flow.arcalot.io/pluginsdk v0.8.0 h1:cShsshrR17ZFLcbgi3aZvqexLttcp3JISFNqPUPuDvA= +go.flow.arcalot.io/pluginsdk v0.8.0/go.mod h1:sk7ssInR/T+Gy+RSRr+QhKqZcECFFxMyn1hPQCTZSyU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -114,6 +120,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y= +golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -135,16 +142,10 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.28.2 h1:9mpl5mOb6vXZvqbQmankOfPIGiudghwCoLl1EYfUZbw= -k8s.io/api v0.28.2/go.mod h1:RVnJBsjU8tcMq7C3iaRSGMeaKt2TWEUXcpIt/90fjEg= k8s.io/api v0.28.4 h1:8ZBrLjwosLl/NYgv1P7EQLqoO8MGQApnbgH8tu3BMzY= k8s.io/api v0.28.4/go.mod h1:axWTGrY88s/5YE+JSt4uUi6NMM+gur1en2REMR7IRj0= -k8s.io/apimachinery v0.28.2 h1:KCOJLrc6gu+wV1BYgwik4AF4vXOlVJPdiqn0yAWWwXQ= -k8s.io/apimachinery v0.28.2/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU= k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8= k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg= -k8s.io/client-go v0.28.2 h1:DNoYI1vGq0slMBN/SWKMZMw0Rq+0EQW6/AK4v9+3VeY= -k8s.io/client-go v0.28.2/go.mod h1:sMkApowspLuc7omj1FOSUxSoqjr+d5Q0Yc0LOFnYFJY= k8s.io/client-go v0.28.4 h1:Np5ocjlZcTrkyRJ3+T3PkXDpe4UpatQxj85+xjaD2wY= k8s.io/client-go v0.28.4/go.mod h1:0VDZFpgoZfelyP5Wqu0/r/TRYcLYuJ2U1KEeoaPa1N4= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= diff --git a/internal/util/base64.go b/internal/util/base64.go index 36d247d..fd0b2eb 100644 --- a/internal/util/base64.go +++ b/internal/util/base64.go @@ -1,3 +1,5 @@ +// Package util provides utility functions common to the +// rest of this deployer package. package util import ( diff --git a/model_connection.go b/model_connection.go index e9eebfd..3da5713 100644 --- a/model_connection.go +++ b/model_connection.go @@ -60,11 +60,14 @@ func (c *ConnectionParameters) UnmarshalYAML(unmarshaller func(interface{}) erro if err := unmarshaller(&temp); err != nil { return fmt.Errorf("failed to JSON unmarshal data (%w)", err) } - unserializedData, err := connectionParametersSchema.UnserializeType(temp) + unserializedData, err := connectionParametersSchema.UnserializeType(temp) //nolint:all if err != nil { return fmt.Errorf("failed to unserialize data (%w)", err) } - c = &unserializedData + // This assignment has no effect! We disable the linter's objection to it + // pending investigation. + // see https://github.com/arcalot/arcaflow-lib-kubernetes-go/issues/18 + c = &unserializedData //nolint:all return nil } diff --git a/model_connection_test.go b/model_connection_test.go index a9d05d1..b5a15dc 100644 --- a/model_connection_test.go +++ b/model_connection_test.go @@ -1 +1 @@ -package arcaflow_lib_kubernetes +package arcaflow_lib_kubernetes_test diff --git a/parse_kubeconfig.go b/parse_kubeconfig.go index a0747d2..0e03478 100644 --- a/parse_kubeconfig.go +++ b/parse_kubeconfig.go @@ -16,7 +16,7 @@ import ( ) func ParseKubeConfig(data string) (KubeConfig, error) { - var kubeconfig KubeConfig = KubeConfig{} + var kubeconfig = KubeConfig{} if err := yaml.Unmarshal([]byte(data), &kubeconfig); err != nil { return kubeconfig, err } @@ -30,7 +30,8 @@ func KubeConfigToConnection(kubeconfig KubeConfig, inlineFiles bool) (Connection var context *KubeConfigContext for _, ctx := range kubeconfig.Contexts { if ctx.Name == *kubeconfig.CurrentContext { - context = &ctx + ctxLocal := ctx + context = &ctxLocal } } if context == nil { @@ -43,7 +44,8 @@ func KubeConfigToConnection(kubeconfig KubeConfig, inlineFiles bool) (Connection for _, clstr := range kubeconfig.Clusters { if clstr.Name == currentCluster { - cluster = &clstr + clstrLocal := clstr + cluster = &clstrLocal } } if cluster == nil { @@ -53,7 +55,8 @@ func KubeConfigToConnection(kubeconfig KubeConfig, inlineFiles bool) (Connection var user *KubeConfigUser for _, usr := range kubeconfig.Users { if usr.Name == currentUser { - user = &usr + usrLocal := usr + user = &usrLocal } } @@ -207,7 +210,7 @@ func ConnectionToKubeConfig(connection ConnectionParameters) (KubeConfig, error) Contexts: []KubeConfigContext{context}, Users: []KubeConfigUser{user}, CurrentContext: &defaultStr, - Preferences: map[interface{}]interface{}{}, //default type in sdk parser, used to compare the struct in unit tests + Preferences: map[interface{}]interface{}{}, // default type in sdk parser, used to compare the struct in unit tests } return kubeconfig, nil diff --git a/parse_kubeconfig_test.go b/parse_kubeconfig_test.go index e158c47..391e8ed 100644 --- a/parse_kubeconfig_test.go +++ b/parse_kubeconfig_test.go @@ -20,7 +20,7 @@ type testFixtures struct { kubeconfigNoData string kubeconfigNoHost string kubeconfigNoContext string - kubeconfigSkipTls string + kubeconfigSkipTLS string tokenFile string kubeconfigExtensions string } @@ -41,7 +41,7 @@ func NewFixtures(t *testing.T) testFixtures { assert.Nil(t, err) kubeNoCtx, err := os.ReadFile("testdata/kubeconfig-nocontext.yaml") assert.Nil(t, err) - kubeTlsSkip, err := os.ReadFile("testdata/kubeconfig-tlsskip.yaml") + kubeTLSSkip, err := os.ReadFile("testdata/kubeconfig-tlsskip.yaml") assert.Nil(t, err) tokenFile, err := os.ReadFile("testdata/tokenfile") assert.Nil(t, err) @@ -56,7 +56,7 @@ func NewFixtures(t *testing.T) testFixtures { kubeconfigNoData: string(kubeNodata), kubeconfigNoHost: string(kubeNoHost), kubeconfigNoContext: string(kubeNoCtx), - kubeconfigSkipTls: string(kubeTlsSkip), + kubeconfigSkipTLS: string(kubeTLSSkip), tokenFile: string(tokenFile), kubeconfigExtensions: string(kubeExtensions), } @@ -74,7 +74,7 @@ func TestParseKubeConfig(t *testing.T) { } func TestKubeConfigToConnection(t *testing.T) { - //test with cert inlining + // test with cert inlining fixtures := NewFixtures(t) kubeconf, err := ParseKubeConfig(fixtures.kubeconfigNoData) assert.Nil(t, err) @@ -87,7 +87,7 @@ func TestKubeConfigToConnection(t *testing.T) { // test that by default insecure-skip-tls-verify is false assert.False(t, connection.Insecure) - //test without inlining + // test without inlining kubeconf, err = ParseKubeConfig(fixtures.kubeconfigNoData) assert.Nil(t, err) connection, err = KubeConfigToConnection(kubeconf, false) @@ -96,19 +96,24 @@ func TestKubeConfigToConnection(t *testing.T) { assert.Equal(t, connection.CertFile, CERTPATH) assert.Equal(t, connection.CAFile, CACERTPATH) - //test failure on empty host + // test failure on empty host kubeconf, err = ParseKubeConfig(fixtures.kubeconfigNoHost) + assert.NoError(t, err) + assert.NotNil(t, kubeconf) connection, err = KubeConfigToConnection(kubeconf, true) assert.NotNil(t, err) - err = nil - //test failure on empty default context + + // test failure on empty default context kubeconf, err = ParseKubeConfig(fixtures.kubeconfigNoContext) + assert.NoError(t, err) + assert.NotNil(t, kubeconf) connection, err = KubeConfigToConnection(kubeconf, true) assert.NotNil(t, err) - err = nil - //test success on insecure-skip-tls-verify: true - kubeconf, err = ParseKubeConfig(fixtures.kubeconfigSkipTls) + // test success on insecure-skip-tls-verify: true + kubeconf, err = ParseKubeConfig(fixtures.kubeconfigSkipTLS) + assert.NoError(t, err) + assert.NotNil(t, kubeconf) connection, err = KubeConfigToConnection(kubeconf, true) assert.True(t, connection.Insecure) assert.Nil(t, err) @@ -120,6 +125,7 @@ func TestConnectionToKubeConfig(t *testing.T) { kubeconf, err := ParseKubeConfig(fixtures.kubeconfigNoData) assert.Nil(t, err) connection, err := KubeConfigToConnection(kubeconf, false) + assert.NoError(t, err) kubeconfBack, err := ConnectionToKubeConfig(connection) assert.Nil(t, err) assert.Equal(t, kubeconf, kubeconfBack) @@ -127,6 +133,7 @@ func TestConnectionToKubeConfig(t *testing.T) { kubeconf, err = ParseKubeConfig(fixtures.kubeconfig) assert.Nil(t, err) connection, err = KubeConfigToConnection(kubeconf, false) + assert.NoError(t, err) kubeconfBack, err = ConnectionToKubeConfig(connection) assert.Nil(t, err) assert.Equal(t, kubeconf, kubeconfBack) @@ -135,6 +142,7 @@ func TestConnectionToKubeConfig(t *testing.T) { kubeconf, err = ParseKubeConfig(fixtures.kubeconfigNoData) assert.Nil(t, err) connection, err = KubeConfigToConnection(kubeconf, false) + assert.NoError(t, err) connection.BearerToken = "" connection.BearerTokenFile = "testdata/tokenfile" kubeconfBack, err = ConnectionToKubeConfig(connection)