Skip to content

Commit

Permalink
FAAS-288: Fixed unit-tests for FaaS
Browse files Browse the repository at this point in the history
  • Loading branch information
shelomentsevd committed Oct 19, 2023
1 parent 5c71fe1 commit 0592e52
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package cmd

import (
"fmt"
"github.com/G-Core/gcorelabscloud-go/client/faas/v1/functions"
"os"
"path/filepath"

"github.com/G-Core/gcorelabscloud-go/client/ais/v1/ais"
"github.com/G-Core/gcorelabscloud-go/client/apitokens/v1/apitokens"
"github.com/G-Core/gcorelabscloud-go/client/apptemplates/v1/apptemplates"
"github.com/G-Core/gcorelabscloud-go/client/faas/v1/functions"
"github.com/G-Core/gcorelabscloud-go/client/file_shares/v1/file_shares"
"github.com/G-Core/gcorelabscloud-go/client/flags"
"github.com/G-Core/gcorelabscloud-go/client/flavors/v1/flavors"
Expand Down
2 changes: 1 addition & 1 deletion gcore/faas/v1/faas/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ type CreateFunctionOpts struct {
Keys []string `json:"keys,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
MainMethod string `json:"main_method"`
Dependencies string `json:"dependencies"`
Dependencies string `json:"dependencies,omitempty"`
}

// ToFunctionCreateMap builds a request body from CreateFunctionOpts.
Expand Down
19 changes: 4 additions & 15 deletions gcore/faas/v1/faas/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ const getKeyResponse = `
"description": "description",
"name": "test-key",
"status": "active",
"created_at": "2023-08-22T11:21:00Z",
"expire": "2023-08-22T11:21:00Z",
"functions": [
{
"name": "function",
Expand All @@ -161,8 +159,7 @@ const createKeyRequest = `
"name": "function",
"namespace": "namespace"
}
],
"expire": "2023-08-22T11:21:00Z"
]
}
`

Expand All @@ -171,14 +168,12 @@ const createKeyResponse = `
"description": "description",
"name": "test-key",
"status": "active",
"created_at": "2023-08-22T11:21:00Z",
"functions": [
{
"name": "function",
"namespace": "namespace"
}
],
"expire": "2023-08-22T11:21:00Z"
]
}
`

Expand All @@ -190,8 +185,6 @@ const listKeysResponse = `
"description": "description",
"name": "test-key",
"status": "active",
"created_at": "2023-08-22T11:21:00Z",
"expire": "2023-08-22T11:21:00Z",
"functions": [
{
"name": "function",
Expand Down Expand Up @@ -224,7 +217,6 @@ const updateKeyResponse = `
"description": "long string",
"name": "test-key",
"status": "active",
"created_at": "2023-08-22T11:21:00Z",
"functions": [
{
"name": "function1",
Expand Down Expand Up @@ -295,9 +287,7 @@ var (
Namespace: "namespace",
},
},
CreatedAt: "2023-08-22T11:21:00Z",
Expire: "2023-08-22T11:21:00Z",
Status: "active",
Status: "active",
}
expectedKeysSlice = []faas.Key{expectedKey}
expectedUpdatedKey = faas.Key{
Expand All @@ -313,7 +303,6 @@ var (
Namespace: "namespace1",
},
},
CreatedAt: "2023-08-22T11:21:00Z",
Status: "active",
Status: "active",
}
)
17 changes: 9 additions & 8 deletions gcore/faas/v1/faas/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"testing"

"github.com/AlekSi/pointer"
"github.com/G-Core/gcorelabscloud-go/gcore/faas/v1/faas"
"github.com/G-Core/gcorelabscloud-go/pagination"
fake "github.com/G-Core/gcorelabscloud-go/testhelper/client"
Expand Down Expand Up @@ -347,11 +348,13 @@ func TestCreateFunction(t *testing.T) {
Timeout: 5,
Flavor: "64mCPU-64MB",
Autoscaling: faas.FunctionAutoscaling{
MinInstances: 1,
MaxInstances: 2,
MinInstances: pointer.To(1),
MaxInstances: pointer.To(2),
},
CodeText: "def main(): print('It works!')",
MainMethod: "main",
EnableApiKey: pointer.To(true),
Keys: []string{"key-one"},
CodeText: "def main(): print('It works!')",
MainMethod: "main",
}
task, err := faas.CreateFunction(client, nsName, opts).Extract()
require.NoError(t, err)
Expand Down Expand Up @@ -408,8 +411,8 @@ func TestUpdateFunction(t *testing.T) {
Timeout: 180,
Flavor: "string",
Autoscaling: &faas.FunctionAutoscaling{
MinInstances: 1,
MaxInstances: 2,
MinInstances: pointer.To(1),
MaxInstances: pointer.To(2),
},
CodeText: "string",
MainMethod: "string",
Expand Down Expand Up @@ -521,11 +524,9 @@ func TestCreateKeys(t *testing.T) {
})

client := fake.ServiceTokenClient("faas/keys", "v1")
expire := "2023-08-22T11:21:00Z"
opts := faas.CreateKeyOpts{
Name: "test-key",
Description: "description",
Expire: &expire,
Functions: []faas.KeysFunction{
{
Name: "function",
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ require (
k8s.io/client-go v0.18.2
)

require github.com/AlekSi/pointer v1.2.0

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w=
github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0=
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
Expand Down

0 comments on commit 0592e52

Please sign in to comment.