Repository: knative-sandbox/kn-plugin-func
Pull request #666 (2021-11-17 14:05:12)

[main] Format Go code
Cron -knative-prow-robot

/cc knative-sandbox/kn-plugin-func-approvers
/assign knative-sandbox/kn-plugin-func-approvers

Produced by: knative-sandbox/knobots/actions/update-gofmt

Details:
```
 
```

knative-prow-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative-sandbox/kn-plugin-func/pull/666#" title="Author self-approved">knative-automation</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **matejvasek** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @matejvasek` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative-sandbox%2Fkn-plugin-func).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/knative-sandbox/kn-plugin-func/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["matejvasek"]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/666?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox) Report
> Merging [#666](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/666?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox) (d6d279a) into [main](https://codecov.io/gh/knative-sandbox/kn-plugin-func/commit/3935747b91e31804070f0939f346e87f635fe09d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox) (3935747) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/666/graphs/tree.svg?width=650&height=150&src=pr&token=da1B9bMsQ9&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox)](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/666?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox)

```diff
@@           Coverage Diff           @@
##             main     #666   +/-   ##
=======================================
  Coverage   37.52%   37.52%           
=======================================
  Files          38       38           
  Lines        3891     3891           
=======================================
  Hits         1460     1460           
  Misses       2238     2238           
  Partials      193      193           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/666?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/666?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox). Last update [3935747...d6d279a](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/666?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox).


Patch:
diff --git a/.github/workflows/knative-boilerplate.yaml b/.github/workflows/knative-boilerplate.yaml
index 9d4093ea..2a0b01ba 100644
--- a/.github/workflows/knative-boilerplate.yaml
+++ b/.github/workflows/knative-boilerplate.yaml
@@ -42,10 +42,10 @@ jobs:
 
     steps:
 
-      - name: Set up Go 1.16.x
+      - name: Set up Go 1.17.x
         uses: actions/setup-go@v2
         with:
-          go-version: 1.16.x
+          go-version: 1.17.x
         id: go
 
       - name: Check out code
@@ -61,7 +61,7 @@ jobs:
           echo '::endgroup::'
 
           echo '::group:: Installing boilerplate-check ... https://github.com/mattmoor/boilerplate-check'
-          go get github.com/mattmoor/boilerplate-check/cmd/boilerplate-check
+          go install github.com/mattmoor/boilerplate-check/cmd/boilerplate-check@latest
           echo '::endgroup::'
 
           echo "${TEMP_PATH}" >> $GITHUB_PATH
diff --git a/.github/workflows/knative-go-build.yaml b/.github/workflows/knative-go-build.yaml
index da2ffd01..b377c975 100644
--- a/.github/workflows/knative-go-build.yaml
+++ b/.github/workflows/knative-go-build.yaml
@@ -27,7 +27,7 @@ jobs:
     name: Build
     strategy:
       matrix:
-        go-version: [1.16.x]
+        go-version: [1.17.x]
         platform: [ubuntu-latest]
 
     runs-on: ${{ matrix.platform }}
@@ -56,6 +56,7 @@ jobs:
                 grep -v '^./hack/' | \
                 grep -v '^./third_party' | \
                 cut -f3 -d' ' | \
+                tr ',' '\n' | \
                 sort | uniq | \
                 grep -v '^!' | \
                 tr '\n' ' ')"
diff --git a/.github/workflows/knative-releasability.yaml b/.github/workflows/knative-releasability.yaml
index c77fd982..1d911195 100644
--- a/.github/workflows/knative-releasability.yaml
+++ b/.github/workflows/knative-releasability.yaml
@@ -25,6 +25,8 @@ on:
     inputs:
       releaseFamily:
         description: 'Release? (vX.Y)'
+      moduleReleaseFamily:
+        description: 'Module Release? (vX.Y)'
       slackChannel:
         description: 'Slack Channel? (release-#)'
 
@@ -36,17 +38,21 @@ jobs:
     env:
       #########################################
       #   Update this section each release.   #
-      RELEASE: 'v0.26'
-      SLACK_CHANNEL: 'release-26'
+      RELEASE: 'v1.0'
+      MODULE_RELEASE: 'v0.27'
+      SLACK_CHANNEL: 'release-1dot0'
       #########################################
 
     steps:
       - name: Defaults
         run: |
-          # If manual trigger sent releaseFamily and slackChannel, then override them
+          # If manual trigger sent releaseFamily, moduleReleaseFamily and slackChannel, then override them
           if [[ "${{ github.event.inputs.releaseFamily }}" != "" ]]; then
             echo "RELEASE=${{ github.event.inputs.releaseFamily }}" >> $GITHUB_ENV
           fi
+          if [[ "${{ github.event.inputs.moduleReleaseFamily }}" != "" ]]; then
+            echo "MODULE_RELEASE=${{ github.event.inputs.moduleReleaseFamily }}" >> $GITHUB_ENV
+          fi
           if [[ "${{ github.event.inputs.slackChannel }}" != "" ]]; then
             echo "SLACK_CHANNEL=${{ github.event.inputs.slackChannel }}" >> $GITHUB_ENV
           fi
@@ -54,13 +60,13 @@ jobs:
             echo "SLACK_WEBHOOK=exists" >> $GITHUB_ENV
           fi
 
-      - name: Set up Go 1.16.x
+      - name: Set up Go
         uses: actions/setup-go@v2
         with:
-          go-version: 1.16.x
+          go-version: 1.17.x
 
       - name: Install Dependencies
-        run: GO111MODULE=on go get knative.dev/test-infra/buoy@main
+        run: go install knative.dev/test-infra/buoy@main
 
       - name: Check out code
         uses: actions/checkout@v2
@@ -69,7 +75,7 @@ jobs:
         id: exists
         run: |
           EXISTS=0
-          buoy exists go.mod --release ${RELEASE} --verbose || EXISTS=$?
+          buoy exists go.mod --release ${RELEASE} --module-release ${MODULE_RELEASE} --verbose || EXISTS=$?
           if [[ "$EXISTS" -eq "0" ]]; then
             EXISTS=true
           else
@@ -83,7 +89,7 @@ jobs:
           # The following pushes the stdout of buoy into $CHECK_MESSAGE
           CHECK=0
           echo 'CHECK_MESSAGE<<EOF' >> $GITHUB_ENV
-          buoy check go.mod --release ${RELEASE} --domain knative.dev --verbose >> $GITHUB_ENV 2>&1 || CHECK=$?
+          buoy check go.mod --release ${RELEASE} --module-release ${MODULE_RELEASE} --domain knative.dev --verbose >> $GITHUB_ENV 2>&1 || CHECK=$?
           echo 'EOF' >> $GITHUB_ENV
 
           # We just captured the return code of the buoy call, test it to see
@@ -99,7 +105,7 @@ jobs:
         if: steps.exists.outputs.release-branch == 'false' && env.current == 'true'
         run: |
           # if update deps returns un-successful, then mark current to false.
-          if ! ./hack/update-deps.sh --release ${RELEASE} --upgrade; then
+          if ! ./hack/update-deps.sh --release ${RELEASE} --module-release ${MODULE_RELEASE} --upgrade; then
             echo "VERIFY_MESSAGE=Unable to update deps for ${{ github.repository }}." >> $GITHUB_ENV
             echo 'current=false' >> $GITHUB_ENV
           fi
diff --git a/.github/workflows/knative-release-notes.yaml b/.github/workflows/knative-release-notes.yaml
index 172eb390..999231ca 100644
--- a/.github/workflows/knative-release-notes.yaml
+++ b/.github/workflows/knative-release-notes.yaml
@@ -41,10 +41,10 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v2
         with:
-          go-version: 1.16.x
+          go-version: 1.17.x
 
       - name: Install Dependencies
-        run: GO111MODULE=on go get k8s.io/release/cmd/release-notes
+        run: go install k8s.io/release/cmd/release-notes@latest
 
       - name: Check out code
         uses: actions/checkout@v2
diff --git a/.github/workflows/knative-style.yaml b/.github/workflows/knative-style.yaml
index ac9ecb85..bbd30678 100644
--- a/.github/workflows/knative-style.yaml
+++ b/.github/workflows/knative-style.yaml
@@ -37,23 +37,23 @@ jobs:
         - tool: gofmt
           options: -s
         - tool: goimports
-          importpath: golang.org/x/tools/cmd/goimports
+          package: golang.org/x/tools/cmd/goimports@latest
 
     steps:
-      - name: Set up Go 1.16.x
+      - name: Set up Go
         uses: actions/setup-go@v2
         with:
-          go-version: 1.16.x
+          go-version: 1.17.x
         id: go
 
       - name: Check out code
         uses: actions/checkout@v2
 
       - name: Install Dependencies
-        if: ${{ matrix.importpath != '' }}
+        if: ${{ matrix.package != '' }}
         run: |
           cd $(mktemp -d)
-          GO111MODULE=on go get ${{ matrix.importpath }}
+          go install ${{ matrix.package }}
 
       - name: ${{ matrix.tool }} ${{ matrix.options }}
         shell: bash
@@ -89,10 +89,10 @@ jobs:
     runs-on: ubuntu-latest
 
     steps:
-      - name: Set up Go 1.16.x
+      - name: Set up Go
         uses: actions/setup-go@v2
         with:
-          go-version: 1.16.x
+          go-version: 1.17.x
         id: go
 
       - name: Check out code
@@ -106,7 +106,7 @@ jobs:
         if: steps.golangci_configuration.outputs.files_exists == 'true'
         uses: golangci/golangci-lint-action@v2
         with:
-          version: v1.42
+          version: v1.43
 
       - name: Install Tools
         env:
diff --git a/.github/workflows/knative-verify.yaml b/.github/workflows/knative-verify.yaml
index e18937e1..8106b267 100644
--- a/.github/workflows/knative-verify.yaml
+++ b/.github/workflows/knative-verify.yaml
@@ -27,16 +27,12 @@ jobs:
     name: Verify Deps and Codegen
     strategy:
       matrix:
-        go-version: [1.16.x]
+        go-version: [1.17.x]
         platform: [ubuntu-latest]
 
     runs-on: ${{ matrix.platform }}
 
-    env:
-      GOPATH: ${{ github.workspace }}
-
     steps:
-
     - name: Set up Go ${{ matrix.go-version }}
       uses: actions/setup-go@v2
       with:
@@ -45,22 +41,16 @@ jobs:
 
     - name: Install Dependencies
       run: |
-        curl -L https://github.com/google/ko/releases/download/v0.6.0/ko_0.6.0_Linux_x86_64.tar.gz | tar xzf - ko
-        chmod +x ./ko
-        sudo mv ko /usr/local/bin
-        go get github.com/google/go-licenses
+        go install github.com/google/ko@latest
+        go install github.com/google/go-licenses@latest
 
-    - name: Check out code onto GOPATH
+    - name: Check out code
       uses: actions/checkout@v2
-      with:
-        path: ./src/knative.dev/${{ github.event.repository.name }}
 
     - name: Update Codegen
       shell: bash
       run: |
-        pushd ./src/knative.dev/${{ github.event.repository.name }}
         [[ ! -f hack/update-codegen.sh ]] || ./hack/update-codegen.sh
-        popd
 
     - name: Verify
       shell: bash
@@ -72,7 +62,6 @@ jobs:
           sed ':begin;$!N;s/\n/%0A/;tbegin'
         }
 
-        pushd ./src/knative.dev/${{ github.event.repository.name }}
         if [[ -z "$(git status --porcelain)" ]]; then
             echo "${{ github.repository }} up to date."
         else
@@ -85,4 +74,3 @@ jobs:
             echo "${{ github.repository }} is out of date. Please run hack/update-codegen.sh"
             exit 1
         fi
-        popd
diff --git a/cmd/create.go b/cmd/create.go
index 9e6ea70b..a667e334 100644
--- a/cmd/create.go
+++ b/cmd/create.go
@@ -16,6 +16,15 @@ import (
 	"knative.dev/kn-plugin-func/utils"
 )
 
+// ErrNoRuntime indicates that the language runtime flag was not passed.
+type ErrNoRuntime error
+
+// ErrInvalidRuntime indicates that the passed language runtime was invalid.
+type ErrInvalidRuntime error
+
+// ErrInvalidTemplate indicates that the passed template was invalid.
+type ErrInvalidTemplate error
+
 func init() {
 	// Add to the root a new "Create" command which obtains an appropriate
 	// instance of fn.Client from the given client creator function.
@@ -86,7 +95,7 @@ EXAMPLES
 	}
 
 	// Flags
-	cmd.Flags().StringP("language", "l", fn.DefaultRuntime, "Language Runtime (see help text for list) (Env: $FUNC_LANGUAGE)")
+	cmd.Flags().StringP("language", "l", "", "Language Runtime (see help text for list) (Env: $FUNC_LANGUAGE)")
 	cmd.Flags().StringP("template", "t", fn.DefaultTemplate, "Function template. (see help text for list) (Env: $FUNC_TEMPLATE)")
 	cmd.Flags().StringP("repository", "r", "", "URI to a Git repository containing the specified template (Env: $FUNC_REPOSITORY)")
 	cmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all options interactively (Env: $FUNC_CONFIRM)")
@@ -315,6 +324,22 @@ func isValidTemplate(client *fn.Client, runtime, template string) bool {
 	return false
 }
 
+// noRuntimeError creates an error stating that the language flag
+// is required, and a verbose list of valid options.
+func noRuntimeError(client *fn.Client) error {
+	b := strings.Builder{}
+	fmt.Fprintf(&b, "Required flag \"language\" not set.\n")
+	fmt.Fprintln(&b, "Available language runtimes are:")
+	runtimes, err := client.Runtimes()
+	if err != nil {
+		return err
+	}
+	for _, v := range runtimes {
+		fmt.Fprintf(&b, "  %v\n", v)
+	}
+	return ErrNoRuntime(errors.New(b.String()))
+}
+
 // newInvalidRuntimeError creates an error stating that the given language
 // is not valid, and a verbose list of valid options.
 func newInvalidRuntimeError(client *fn.Client, runtime string) error {
@@ -328,7 +353,7 @@ func newInvalidRuntimeError(client *fn.Client, runtime string) error {
 	for _, v := range runtimes {
 		fmt.Fprintf(&b, "  %v\n", v)
 	}
-	return errors.New(b.String())
+	return ErrInvalidRuntime(errors.New(b.String()))
 }
 
 // newInvalidTemplateError creates an error stating that the given template
@@ -345,7 +370,7 @@ func newInvalidTemplateError(client *fn.Client, runtime, template string) error
 	for _, v := range templates {
 		fmt.Fprintf(&b, "  %v\n", v)
 	}
-	return errors.New(b.String())
+	return ErrInvalidTemplate(errors.New(b.String()))
 }
 
 // Validate the current state of the config, returning any errors.
@@ -355,6 +380,7 @@ func newInvalidTemplateError(client *fn.Client, runtime, template string) error
 // pre-client validation should not be required, as the Client does its own
 // validation.
 func (c createConfig) Validate(client *fn.Client) (err error) {
+
 	// Confirm Name is valid
 	// Note that this is highly constricted, as it must currently adhere to the
 	// naming of a Knative Service, which itself is constrained to a Kubernetes
@@ -371,13 +397,16 @@ func (c createConfig) Validate(client *fn.Client) (err error) {
 	// Perhaps additional validation would be of use here in the CLI, but
 	// the client libray itself is ultimately responsible for validating all input
 	// prior to exeuting any requests.
-	// Client validates both language runtime and template exist, defaulting
-	// them if not (to 'node' and 'http', respectively).  However, if either of
-	// them are invalid, or the chosen combination does not exist, the error
-	// message is a rather terse one-liner.  This is suitable for libraries, but
+	// Client validates both language runtime and template exist, with language runtime
+	// being a mandatory flag while defaulting template if not present to 'http'.
+	// However, if either of them are invalid, or the chosen combination does not exist,
+	// the error message is a rather terse one-liner. This is suitable for libraries, but
 	// for a CLI it behooves us to be more verbose, including valid options for
 	// each.  So here, we check that the values entered (if any) are both valid
 	// and valid together.
+	if c.Runtime == "" {
+		return noRuntimeError(client)
+	}
 	if c.Runtime != "" && c.Repository == "" &&
 		!isValidRuntime(client, c.Runtime) {
 		return newInvalidRuntimeError(client, c.Runtime)
diff --git a/pkged.go b/pkged.go
index 80cbc429..3c41c665 100644
--- a/pkged.go
+++ b/pkged.go
@@ -1,5 +1,6 @@
 // Code generated by pkger; DO NOT EDIT.
 
+//go:build !skippkger
 // +build !skippkger
 
 package function


Test patch:
diff --git a/.github/workflows/knative-go-test.yaml b/.github/workflows/knative-go-test.yaml
index 14f2941d..8c531a63 100644
--- a/.github/workflows/knative-go-test.yaml
+++ b/.github/workflows/knative-go-test.yaml
@@ -31,7 +31,7 @@ jobs:
     name: Unit Tests
     strategy:
       matrix:
-        go-version: [1.16.x]
+        go-version: [1.17.x]
         platform: [ubuntu-latest]
 
     runs-on: ${{ matrix.platform }}
diff --git a/cmd/create_test.go b/cmd/create_test.go
index feb96a08..1a7b25f6 100644
--- a/cmd/create_test.go
+++ b/cmd/create_test.go
@@ -2,6 +2,7 @@ package cmd
 
 import (
 	"errors"
+	"fmt"
 	"io/ioutil"
 	"os"
 	"path/filepath"
@@ -18,13 +19,68 @@ func TestCreate(t *testing.T) {
 
 	// command with a client factory which yields a fully default client.
 	cmd := NewCreateCmd(func(createConfig) *fn.Client { return fn.New() })
-	cmd.SetArgs([]string{})
+	cmd.SetArgs([]string{
+		fmt.Sprintf("--language=%s", "go"),
+	})
 
 	if err := cmd.Execute(); err != nil {
 		t.Fatal(err)
 	}
 }
 
+// TestCreateWithNoRuntime ensures that an invocation of create must be
+// done with a runtime.
+func TestCreateWithNoRuntime(t *testing.T) {
+	defer fromTempDir(t)()
+
+	// command with a client factory which yields a fully default client.
+	cmd := NewCreateCmd(func(createConfig) *fn.Client { return fn.New() })
+	cmd.SetArgs([]string{})
+
+	err := cmd.Execute()
+	var e ErrNoRuntime
+	if !errors.As(err, &e) {
+		t.Fatalf("Did not receive ErrNoRuntime. Got %v", err)
+	}
+}
+
+// TestCreateWithNoRuntime ensures that an invocation of create must be
+// done with one of the valid runtimes only.
+func TestCreateWithInvalidRuntime(t *testing.T) {
+	defer fromTempDir(t)()
+
+	// command with a client factory which yields a fully default client.
+	cmd := NewCreateCmd(func(createConfig) *fn.Client { return fn.New() })
+	cmd.SetArgs([]string{
+		fmt.Sprintf("--language=%s", "test"),
+	})
+
+	err := cmd.Execute()
+	var e ErrInvalidRuntime
+	if !errors.As(err, &e) {
+		t.Fatalf("Did not receive ErrInvalidRuntime. Got %v", err)
+	}
+}
+
+// TestCreateWithInvalidTemplate ensures that an invocation of create must be
+// done with one of the valid templates only.
+func TestCreateWithInvalidTemplate(t *testing.T) {
+	defer fromTempDir(t)()
+
+	// command with a client factory which yields a fully default client.
+	cmd := NewCreateCmd(func(createConfig) *fn.Client { return fn.New() })
+	cmd.SetArgs([]string{
+		fmt.Sprintf("--language=%s", "go"),
+		fmt.Sprintf("--template=%s", "events"),
+	})
+
+	err := cmd.Execute()
+	var e ErrInvalidTemplate
+	if !errors.As(err, &e) {
+		t.Fatalf("Did not receive ErrInvalidTemplate. Got %v", err)
+	}
+}
+
 // TestCreateValidatesName ensures that the create command only accepts
 // DNS-1123 labels for Function name.
 func TestCreateValidatesName(t *testing.T) {
@@ -71,7 +127,9 @@ func TestCreateRepositoriesPath(t *testing.T) {
 		}
 		return fn.New()
 	})
-
+	cmd.SetArgs([]string{
+		fmt.Sprintf("--language=%s", "go"),
+	})
 	// Invoke the command, which is an airball, but does invoke the client
 	// constructor, which which evaluates the aceptance condition of ensuring the
 	// default repositories path was updated based on XDG_CONFIG_HOME.
diff --git a/function_test.go b/function_test.go
index dc7bfa03..391889cd 100644
--- a/function_test.go
+++ b/function_test.go
@@ -9,7 +9,7 @@ import (
 	fn "knative.dev/kn-plugin-func"
 	. "knative.dev/kn-plugin-func/testing"
 )
-
+    
 // TestFunctionNameDefault ensures that a Function's name is defaulted to that
 // which can be derived from the last part of its path.
 func TestFunctionNameDefault(t *testing.T) {
@@ -21,4 +21,4 @@ func TestFunctionNameDefault(t *testing.T) {
 	}
 	// TODO
 	// Test that the name was defaulted
-}
+}
\ No newline at end of file