Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:

env:
# Common versions
GO_VERSION: '1.25.6'
GOLANGCI_VERSION: 'v2.7'
GO_VERSION: '1.26'
GOLANGCI_VERSION: 'v2.12.2'
DOCKER_BUILDX_VERSION: 'v0.23.0'

# These environment variables are important to the Crossplane CLI install.sh
Expand Down
14 changes: 8 additions & 6 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/crossplane/function-sdk-go/resource"
)

const testPathSpecFoo = "spec.foo"

func TestFromValueRef(t *testing.T) {
type args struct {
req *fnv1.RunFunctionRequest
Expand Down Expand Up @@ -45,7 +47,7 @@ func TestFromValueRef(t *testing.T) {
},
},
},
path: "spec.foo",
path: testPathSpecFoo,
},
want: want{
result: "bar",
Expand Down Expand Up @@ -119,7 +121,7 @@ func TestFromFieldRef(t *testing.T) {
},
},
fieldRef: v1alpha1.FieldRef{
Path: "spec.foo",
Path: testPathSpecFoo,
},
},
want: want{
Expand All @@ -144,7 +146,7 @@ func TestFromFieldRef(t *testing.T) {
},
},
fieldRef: v1alpha1.FieldRef{
Path: "spec.foo",
Path: testPathSpecFoo,
Policy: v1alpha1.FieldRefPolicyRequired,
},
},
Expand All @@ -170,7 +172,7 @@ func TestFromFieldRef(t *testing.T) {
},
},
fieldRef: v1alpha1.FieldRef{
Path: "spec.foo",
Path: testPathSpecFoo,
},
},
want: want{
Expand All @@ -196,7 +198,7 @@ func TestFromFieldRef(t *testing.T) {
},
fieldRef: v1alpha1.FieldRef{
DefaultValue: "default",
Path: "spec.foo",
Path: testPathSpecFoo,
Policy: v1alpha1.FieldRefPolicyOptional,
},
},
Expand All @@ -222,7 +224,7 @@ func TestFromFieldRef(t *testing.T) {
},
},
fieldRef: v1alpha1.FieldRef{
Path: "spec.foo",
Path: testPathSpecFoo,
Policy: v1alpha1.FieldRefPolicyOptional,
},
},
Expand Down
54 changes: 28 additions & 26 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/crossplane/function-sdk-go/response"
)

const testTagHello = "hello"

func TestRunFunction(t *testing.T) {
type args struct {
ctx context.Context
Expand All @@ -37,7 +39,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should return a fatal result if no input was specified",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters"
Expand All @@ -46,7 +48,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Results: []*fnv1.Result{
{
Severity: fnv1.Severity_SEVERITY_FATAL,
Expand All @@ -61,7 +63,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should return a response when after a script is run",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -71,7 +73,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Results: []*fnv1.Result{
{
Severity: fnv1.Severity_SEVERITY_FATAL,
Expand All @@ -86,7 +88,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should write stdout to the specified field",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -97,7 +99,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -127,7 +129,7 @@ func TestRunFunction(t *testing.T) {
reason: "The function should write to the specified stderr when the shell command is invalid",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -140,7 +142,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -171,7 +173,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should write to the specified stderr field when the shellCommand is not found",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -184,7 +186,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -215,7 +217,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should capture both stdout and stderr when a command fails but produces output",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -227,7 +229,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -258,7 +260,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should accept and use environment variables",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -270,7 +272,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -300,7 +302,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should accept and use environment variables from a fieldPath",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -323,7 +325,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -353,7 +355,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should accept and use environment variables from a default FieldRef ",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -365,7 +367,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -395,7 +397,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should return an error when a bad shellEnVars type is provided",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -407,7 +409,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Results: []*fnv1.Result{
{
Severity: fnv1.Severity_SEVERITY_FATAL,
Expand All @@ -422,7 +424,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should return an error when a shellEnvVars fieldRef.path is empty",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -434,7 +436,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Results: []*fnv1.Result{
{
Severity: fnv1.Severity_SEVERITY_FATAL,
Expand All @@ -449,7 +451,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should set custom TTL when cacheTTL is specified",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -461,7 +463,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(5 * time.Minute)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(5 * time.Minute)},
Desired: &fnv1.State{
Composite: &fnv1.Resource{
Resource: resource.MustStructJSON(`{
Expand Down Expand Up @@ -491,7 +493,7 @@ func TestRunFunction(t *testing.T) {
reason: "The Function should return a fatal error when cacheTTL has invalid format",
args: args{
req: &fnv1.RunFunctionRequest{
Meta: &fnv1.RequestMeta{Tag: "hello"},
Meta: &fnv1.RequestMeta{Tag: testTagHello},
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
Expand All @@ -503,7 +505,7 @@ func TestRunFunction(t *testing.T) {
},
want: want{
rsp: &fnv1.RunFunctionResponse{
Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
Meta: &fnv1.ResponseMeta{Tag: testTagHello, Ttl: durationpb.New(response.DefaultTTL)},
Results: []*fnv1.Result{
{
Severity: fnv1.Severity_SEVERITY_FATAL,
Expand Down
Loading
Loading