From 2cdc3defb7394e62b1d205c075e0d6e9919c90df Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Fri, 11 Sep 2020 18:15:24 -0700 Subject: [PATCH] Use here.Doc() in a few more places that were begging for it --- .../controller/issuerconfig/publisher_test.go | 19 +++++---- internal/server/server.go | 10 +++-- test/integration/client_test.go | 42 ++++++++++--------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/internal/controller/issuerconfig/publisher_test.go b/internal/controller/issuerconfig/publisher_test.go index f45d8390..2e7b6987 100644 --- a/internal/controller/issuerconfig/publisher_test.go +++ b/internal/controller/issuerconfig/publisher_test.go @@ -8,7 +8,6 @@ package issuerconfig import ( "context" "errors" - "strings" "testing" "time" @@ -27,6 +26,7 @@ import ( pinnipedfake "github.com/suzerain-io/pinniped/generated/1.19/client/clientset/versioned/fake" pinnipedinformers "github.com/suzerain-io/pinniped/generated/1.19/client/informers/externalversions" "github.com/suzerain-io/pinniped/internal/controllerlib" + "github.com/suzerain-io/pinniped/internal/here" "github.com/suzerain-io/pinniped/internal/testutil" ) @@ -256,14 +256,15 @@ func TestSync(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "cluster-info", Namespace: "kube-public"}, // Note that go fmt puts tabs in our file, which we must remove from our configmap yaml below. Data: map[string]string{ - "kubeconfig": strings.ReplaceAll(` - kind: Config - apiVersion: v1 - clusters: - - name: "" - cluster: - certificate-authority-data: "`+caData+`" - server: "`+kubeServerURL+`"`, "\t", " "), + "kubeconfig": here.Docf(` + kind: Config + apiVersion: v1 + clusters: + - name: "" + cluster: + certificate-authority-data: "%s" + server: "%s"`, + caData, kubeServerURL), "uninteresting-key": "uninteresting-value", }, } diff --git a/internal/server/server.go b/internal/server/server.go index 1dcdb808..4c146ca8 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -29,6 +29,7 @@ import ( "github.com/suzerain-io/pinniped/internal/controller/issuerconfig" "github.com/suzerain-io/pinniped/internal/controllermanager" "github.com/suzerain-io/pinniped/internal/downward" + "github.com/suzerain-io/pinniped/internal/here" "github.com/suzerain-io/pinniped/internal/provider" "github.com/suzerain-io/pinniped/internal/registry/credentialrequest" "github.com/suzerain-io/pinniped/pkg/config" @@ -62,10 +63,11 @@ func (a *App) Run() error { // Create the server command and save it into the App. func (a *App) addServerCommand(ctx context.Context, args []string, stdout, stderr io.Writer) { cmd := &cobra.Command{ - Use: `pinniped-server`, - Long: "pinniped-server provides a generic API for mapping an external\n" + - "credential from somewhere to an internal credential to be used for\n" + - "authenticating to the Kubernetes API.", + Use: "pinniped-server", + Long: here.Doc(` + pinniped-server provides a generic API for mapping an external + credential from somewhere to an internal credential to be used for + authenticating to the Kubernetes API.`), RunE: func(cmd *cobra.Command, args []string) error { return a.runServer(ctx) }, Args: cobra.NoArgs, } diff --git a/test/integration/client_test.go b/test/integration/client_test.go index ad480d1a..138db6d7 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/require" "github.com/suzerain-io/pinniped/internal/client" + "github.com/suzerain-io/pinniped/internal/here" "github.com/suzerain-io/pinniped/test/library" ) @@ -28,27 +29,28 @@ Test certificate and private key that should get an authentication error. Genera [1]: https://github.com/cloudflare/cfssl */ var ( - testCert = strings.TrimSpace(` ------BEGIN CERTIFICATE----- -MIICBDCCAaugAwIBAgIUeidKWlZQuoKfBGydObI1hMwzt9cwCgYIKoZIzj0EAwIw -SDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1TYW4gRnJhbmNp -c2NvMRQwEgYDVQQDEwtleGFtcGxlLm5ldDAeFw0yMDA3MjgxOTI3MDBaFw0yMTA3 -MjgxOTI3MDBaMEgxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMN -U2FuIEZyYW5jaXNjbzEUMBIGA1UEAxMLZXhhbXBsZS5uZXQwWTATBgcqhkjOPQIB -BggqhkjOPQMBBwNCAARk7XBC+OjYmrXOhm7RaJ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yq/fPAiBNCJw1MCLT8LjNlyUZCfwI2zuI3e0w6vuau89oj2zvVA== + -----END CERTIFICATE----- `) - testKey = maskKey(strings.TrimSpace(` ------BEGIN EC TESTING KEY----- -MHcCAQEEIAqkBGGKTH5GzLx8XZLAHEFW2E8jT+jpy0p6w6MMR7DkoAoGCCqGSM49 -AwEHoUQDQgAEZO1wQvjo2Jq1zoZu0WiYh1uEOVbBPojFfdAc6u2p7KgIW9OESOt2 -O2D8LtWhMbrYy755Fgq4H9s3vCgfvHY1AQ== ------END EC TESTING KEY----- + + testKey = maskKey(here.Doc(` + -----BEGIN EC TESTING KEY----- + MHcCAQEEIAqkBGGKTH5GzLx8XZLAHEFW2E8jT+jpy0p6w6MMR7DkoAoGCCqGSM49 + AwEHoUQDQgAEZO1wQvjo2Jq1zoZu0WiYh1uEOVbBPojFfdAc6u2p7KgIW9OESOt2 + O2D8LtWhMbrYy755Fgq4H9s3vCgfvHY1AQ== + -----END EC TESTING KEY----- `)) )