Add function test CLI tests (#2871)

* Add function test CLI tests
* Add few more services to tests

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2023-11-13 14:34:56 +05:30
committed by GitHub
parent 3fabf64b3c
commit 2e4825def0
8 changed files with 60 additions and 39 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ func (opts *LogSubCommand) do(input cli.Input) error {
// request the controller to establish a proxy server to the database.
logDB, err := logdb.GetLogDB(dbType, input.Context(), logDBOptions)
if err != nil {
return errors.Wrapf(err, "failed to get log database")
return errors.Wrapf(err, "failed to get log from %s", dbType)
}
requestChan := make(chan struct{})
+4 -14
View File
@@ -164,13 +164,13 @@ func (opts *TestSubCommand) do(input cli.Input) error {
return nil
}
console.Errorf("Error calling function %s: %d; Please try again or fix the error: %s\n", m.Name, resp.StatusCode, string(body))
err = printPodLogs(input.Context(), opts.Client(), m)
console.Errorf("calling function %s: %d; Please try again or fix the error: %s\n", m.Name, resp.StatusCode, string(body))
err = util.FunctionPodLogs(input.Context(), m.Name, m.Namespace, opts.Client())
if err != nil {
console.Errorf("Error getting function logs from controller: %v. Try to get logs from log database.", err)
console.Errorf("getting function logs: %v. Try to get logs from log database.", err)
err = Log(input)
if err != nil {
return errors.Wrapf(err, "error retrieving function log from log database")
console.Errorf("getting function logs from log database: %v", err)
}
}
return errors.New("error getting function response")
@@ -236,13 +236,3 @@ func doHTTPRequest(ctx context.Context, url string, headers []string, method, bo
return resp, nil
}
func printPodLogs(ctx context.Context, client cmd.Client, fnMeta *metav1.ObjectMeta) error {
err := util.FunctionPodLogs(ctx, fnMeta.Name, fnMeta.Namespace, client)
if err != nil {
return errors.Wrap(err, "error executing get logs request")
}
return nil
}
+3 -6
View File
@@ -32,7 +32,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/core/v1"
"github.com/fission/fission/pkg/fission-cli/cmd"
"github.com/fission/fission/pkg/fission-cli/console"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -70,7 +69,8 @@ func GetFunctionPodLogs(ctx context.Context, client cmd.Client, logFilter LogFil
fv1.ENVIRONMENT_NAMESPACE: f.Spec.Environment.Namespace,
}
podList, err := client.KubernetesClient.CoreV1().Pods(util.ResolveFunctionNS(podNs)).List(ctx, metav1.ListOptions{
podNs = util.ResolveFunctionNS(podNs)
podList, err := client.KubernetesClient.CoreV1().Pods(podNs).List(ctx, metav1.ListOptions{
LabelSelector: labels.Set(selector).AsSelector().String(),
})
if err != nil {
@@ -78,10 +78,7 @@ func GetFunctionPodLogs(ctx context.Context, client cmd.Client, logFilter LogFil
}
if len(podList.Items) <= 0 {
if logFilter.WarnUser {
console.Warn("version<1.18 used fission-function as pod's default namespace. Specify appropriate namespace with --pod-namespace tag or export an environment variable for function-namespace FUNCTION_NAMESPACE")
}
return errors.New("no active pods found")
return errors.Errorf("no active pods found for function in namespace %s", podNs)
}
pods := podList.Items
+1 -2
View File
@@ -582,8 +582,7 @@ func FunctionPodLogs(ctx context.Context, fnName, ns string, client cmd.Client)
})
if len(pods) <= 0 {
return errors.New("no active pods found")
return errors.New("no active pods found for function in namespace " + podNs)
}
// get the pod with highest resource version