Skip to content

Commit

Permalink
Merge pull request #28 from CrowdStrike/chore/drop_version
Browse files Browse the repository at this point in the history
fix: drop Fn Version from Fn output
  • Loading branch information
jsteenb2 committed Jul 11, 2024
2 parents 5dbe9cb + 111ecda commit 3c1f5a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
11 changes: 3 additions & 8 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ import (
"net/url"
"os"
"runtime/debug"
"strconv"
)

// Fn returns the active function id and version.
func Fn() struct {
ID string
Version int
ID string
} {
v, _ := strconv.Atoi(os.Getenv("CS_FN_VERSION"))
return struct {
ID string
Version int
ID string
}{
ID: os.Getenv("CS_FN_ID"),
Version: v,
ID: os.Getenv("CS_FN_ID"),
}
}

Expand Down
20 changes: 7 additions & 13 deletions sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
func TestFn(t *testing.T) {
type (
inputs struct {
fnID string
fnVersion string
fnID string
}

wantFn func(t *testing.T, gotFnID string, gotVersion int)
wantFn func(t *testing.T, gotFnID string)
)

tests := []struct {
Expand All @@ -26,34 +25,29 @@ func TestFn(t *testing.T) {
{
name: "fn-id set with version 1",
inputs: inputs{
fnID: "fn-id",
fnVersion: "1",
fnID: "fn-id",
},
wants: func(t *testing.T, gotFnID string, gotVersion int) {
wants: func(t *testing.T, gotFnID string) {
fdk.EqualVals(t, "fn-id", gotFnID)
fdk.EqualVals(t, 1, gotVersion)
},
},
{
name: "fn-id set without version",
inputs: inputs{
fnID: "fn-id",
fnVersion: "",
fnID: "fn-id",
},
wants: func(t *testing.T, gotFnID string, gotVersion int) {
wants: func(t *testing.T, gotFnID string) {
fdk.EqualVals(t, "fn-id", gotFnID)
fdk.EqualVals(t, 0, gotVersion)
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Setenv("CS_FN_ID", tt.inputs.fnID)
t.Setenv("CS_FN_VERSION", tt.inputs.fnVersion)

fn := fdk.Fn()
tt.wants(t, fn.ID, fn.Version)
tt.wants(t, fn.ID)
})
}

Expand Down

0 comments on commit 3c1f5a4

Please sign in to comment.