Skip to content

Commit

Permalink
Merge pull request crossplane-contrib#9 from humoflife/unit-tests
Browse files Browse the repository at this point in the history
updated unit tests, removed v1beta1, simplfied code, updated README
  • Loading branch information
humoflife authored Apr 22, 2024
2 parents 288a477 + a3be6f6 commit 8cd3370
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 154 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ is expected to follow the above pattern.
The `function-shell` accepts commands to run in a shell and it
returns the output to specified fields. It accepts the following parameters:

- `shellScriptsConfigMapsRef` - referencing at least one Kuberneres
- `shellScriptsConfigMapsRef` - referencing at least one Kubernetes
[`ConfigMap`](https://kubernetes.io/docs/concepts/configuration/configmap/)
with at least one shell script. This script can be written in an arbitrary
shell language, for example bash or python3.
- `shellEnvVarsSecretRef` - referencing environment variables in a
Kubernetes secret. `shellEnvVarsSecretRef` requires a `name`, a
Kubernetes secret. `shellEnvVarsSecretRef` requires a `name`, a
`namespace` and a `key` for the secret. Inside of it, the shell
expects a JSON structure with key value environment variables. Example:

Expand Down
28 changes: 1 addition & 27 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,32 +187,6 @@ func TestRunFunction(t *testing.T) {
},
},
},
"ResponseIsSecretError": {
reason: "The Function should return an error when secrets are not loadable",
args: args{
req: &fnv1beta1.RunFunctionRequest{
Meta: &fnv1beta1.RequestMeta{Tag: "hello"},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
"shellEnvVarsSecretRef": {"name": "test-secret", "namespace": "crossplane-system", "key": "credentials"},
"shellCommand": "echo testing",
"stdoutField": "spec.atFunction.shell.stdout"
}`),
},
},
want: want{
rsp: &fnv1beta1.RunFunctionResponse{
Meta: &fnv1beta1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Results: []*fnv1beta1.Result{
{
Severity: fnv1beta1.Severity_SEVERITY_FATAL,
Message: "cannot process contents of secret test-secret in namespace crossplane-system: Secret test-secret in namespace crossplane-system not found\n",
},
},
},
},
},
}

for name, tc := range cases {
Expand All @@ -229,4 +203,4 @@ func TestRunFunction(t *testing.T) {
}
})
}
}
}
52 changes: 0 additions & 52 deletions input/v1beta1/parameters.go

This file was deleted.

70 changes: 0 additions & 70 deletions input/v1beta1/zz_generated.deepcopy.go

This file was deleted.

4 changes: 1 addition & 3 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ func getScripts(clientset *kubernetes.Clientset, shellScriptsConfigMapRef v1alph
}

for _, scriptName := range scriptNames {
for _, scriptLine := range strings.Split(scriptConfigMap.Data[scriptName], "\n") {
scripts[scriptName] = append(scripts[scriptName], scriptLine)
}
scripts[scriptName] = append(scripts[scriptName], strings.Split(scriptConfigMap.Data[scriptName], "\n")...)
}

return scripts, nil
Expand Down

0 comments on commit 8cd3370

Please sign in to comment.