github.com/kubeshop/testkube@v1.17.23/pkg/api/v1/client/interface.go (about)

     1  package client
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/kubeshop/testkube/pkg/api/v1/testkube"
     7  	"github.com/kubeshop/testkube/pkg/executor/output"
     8  	"github.com/kubeshop/testkube/pkg/logs/events"
     9  )
    10  
    11  // Client is the Testkube API client abstraction
    12  type Client interface {
    13  	TestAPI
    14  	ExecutionAPI
    15  	TestSuiteAPI
    16  	TestSuiteExecutionAPI
    17  	ExecutorAPI
    18  	WebhookAPI
    19  	ServiceAPI
    20  	ConfigAPI
    21  	TestSourceAPI
    22  	CopyFileAPI
    23  	TemplateAPI
    24  	TestWorkflowAPI
    25  	TestWorkflowExecutionAPI
    26  	TestWorkflowTemplateAPI
    27  }
    28  
    29  // TestAPI describes test api methods
    30  type TestAPI interface {
    31  	GetTest(id string) (test testkube.Test, err error)
    32  	GetTestWithExecution(id string) (test testkube.TestWithExecution, err error)
    33  	CreateTest(options UpsertTestOptions) (test testkube.Test, err error)
    34  	UpdateTest(options UpdateTestOptions) (test testkube.Test, err error)
    35  	DeleteTest(name string) error
    36  	DeleteTests(selector string) error
    37  	ListTests(selector string) (tests testkube.Tests, err error)
    38  	ListTestWithExecutionSummaries(selector string) (tests testkube.TestWithExecutionSummaries, err error)
    39  	ExecuteTest(id, executionName string, options ExecuteTestOptions) (executions testkube.Execution, err error)
    40  	ExecuteTests(selector string, concurrencyLevel int, options ExecuteTestOptions) (executions []testkube.Execution, err error)
    41  	Logs(id string) (logs chan output.Output, err error)
    42  	LogsV2(id string) (logs chan events.Log, err error)
    43  }
    44  
    45  // ExecutionAPI describes execution api methods
    46  type ExecutionAPI interface {
    47  	GetExecution(executionID string) (execution testkube.Execution, err error)
    48  	ListExecutions(id string, limit int, selector string) (executions testkube.ExecutionsResult, err error)
    49  	AbortExecution(test string, id string) error
    50  	AbortExecutions(test string) error
    51  	GetExecutionArtifacts(executionID string) (artifacts testkube.Artifacts, err error)
    52  	DownloadFile(executionID, fileName, destination string) (artifact string, err error)
    53  	DownloadArchive(executionID, destination string, masks []string) (archive string, err error)
    54  }
    55  
    56  // TestSuiteAPI describes test suite api methods
    57  type TestSuiteAPI interface {
    58  	CreateTestSuite(options UpsertTestSuiteOptions) (testSuite testkube.TestSuite, err error)
    59  	UpdateTestSuite(options UpdateTestSuiteOptions) (testSuite testkube.TestSuite, err error)
    60  	GetTestSuite(id string) (testSuite testkube.TestSuite, err error)
    61  	GetTestSuiteWithExecution(id string) (testSuite testkube.TestSuiteWithExecution, err error)
    62  	ListTestSuites(selector string) (testSuites testkube.TestSuites, err error)
    63  	ListTestSuiteWithExecutionSummaries(selector string) (testSuitesWithExecutionSummaries testkube.TestSuiteWithExecutionSummaries, err error)
    64  	DeleteTestSuite(name string) error
    65  	DeleteTestSuites(selector string) error
    66  	ExecuteTestSuite(id, executionName string, options ExecuteTestSuiteOptions) (executions testkube.TestSuiteExecution, err error)
    67  	ExecuteTestSuites(selector string, concurrencyLevel int, options ExecuteTestSuiteOptions) (executions []testkube.TestSuiteExecution, err error)
    68  }
    69  
    70  // TestSuiteExecutionAPI describes test suite execution api methods
    71  type TestSuiteExecutionAPI interface {
    72  	GetTestSuiteExecution(executionID string) (execution testkube.TestSuiteExecution, err error)
    73  	ListTestSuiteExecutions(testsuite string, limit int, selector string) (executions testkube.TestSuiteExecutionsResult, err error)
    74  	WatchTestSuiteExecution(executionID string) (resp chan testkube.WatchTestSuiteExecutionResponse)
    75  	AbortTestSuiteExecution(executionID string) error
    76  	AbortTestSuiteExecutions(testSuiteName string) error
    77  	GetTestSuiteExecutionArtifacts(executionID string) (artifacts testkube.Artifacts, err error)
    78  }
    79  
    80  // ExecutorAPI describes executor api methods
    81  type ExecutorAPI interface {
    82  	CreateExecutor(options UpsertExecutorOptions) (executor testkube.ExecutorDetails, err error)
    83  	UpdateExecutor(options UpdateExecutorOptions) (executor testkube.ExecutorDetails, err error)
    84  	GetExecutor(name string) (executor testkube.ExecutorDetails, err error)
    85  	ListExecutors(selector string) (executors testkube.ExecutorsDetails, err error)
    86  	DeleteExecutor(name string) (err error)
    87  	DeleteExecutors(selector string) (err error)
    88  }
    89  
    90  // WebhookAPI describes webhook api methods
    91  type WebhookAPI interface {
    92  	CreateWebhook(options CreateWebhookOptions) (webhook testkube.Webhook, err error)
    93  	UpdateWebhook(options UpdateWebhookOptions) (webhook testkube.Webhook, err error)
    94  	GetWebhook(name string) (webhook testkube.Webhook, err error)
    95  	ListWebhooks(selector string) (webhooks testkube.Webhooks, err error)
    96  	DeleteWebhook(name string) (err error)
    97  	DeleteWebhooks(selector string) (err error)
    98  }
    99  
   100  // TemplateAPI describes template api methods
   101  type TemplateAPI interface {
   102  	CreateTemplate(options CreateTemplateOptions) (template testkube.Template, err error)
   103  	UpdateTemplate(options UpdateTemplateOptions) (template testkube.Template, err error)
   104  	GetTemplate(name string) (template testkube.Template, err error)
   105  	ListTemplates(selector string) (templates testkube.Templates, err error)
   106  	DeleteTemplate(name string) (err error)
   107  	DeleteTemplates(selector string) (err error)
   108  }
   109  
   110  // ConfigAPI describes config api methods
   111  type ConfigAPI interface {
   112  	UpdateConfig(config testkube.Config) (outputConfig testkube.Config, err error)
   113  	GetConfig() (config testkube.Config, err error)
   114  }
   115  
   116  // ServiceAPI describes service api methods
   117  type ServiceAPI interface {
   118  	GetServerInfo() (info testkube.ServerInfo, err error)
   119  	GetDebugInfo() (info testkube.DebugInfo, err error)
   120  }
   121  
   122  // TestSourceAPI describes test source api methods
   123  type TestSourceAPI interface {
   124  	CreateTestSource(options UpsertTestSourceOptions) (testSource testkube.TestSource, err error)
   125  	UpdateTestSource(options UpdateTestSourceOptions) (testSource testkube.TestSource, err error)
   126  	GetTestSource(name string) (testSource testkube.TestSource, err error)
   127  	ListTestSources(selector string) (testSources testkube.TestSources, err error)
   128  	DeleteTestSource(name string) (err error)
   129  	DeleteTestSources(selector string) (err error)
   130  }
   131  
   132  // TestWorkflowAPI describes test workflow api methods
   133  type TestWorkflowAPI interface {
   134  	GetTestWorkflow(id string) (testkube.TestWorkflow, error)
   135  	GetTestWorkflowWithExecution(id string) (testkube.TestWorkflowWithExecution, error)
   136  	ListTestWorkflows(selector string) (testkube.TestWorkflows, error)
   137  	ListTestWorkflowWithExecutions(selector string) (testkube.TestWorkflowWithExecutions, error)
   138  	DeleteTestWorkflows(selector string) error
   139  	CreateTestWorkflow(workflow testkube.TestWorkflow) (testkube.TestWorkflow, error)
   140  	UpdateTestWorkflow(workflow testkube.TestWorkflow) (testkube.TestWorkflow, error)
   141  	DeleteTestWorkflow(name string) error
   142  	ExecuteTestWorkflow(name string, request testkube.TestWorkflowExecutionRequest) (testkube.TestWorkflowExecution, error)
   143  	GetTestWorkflowExecutionNotifications(id string) (chan testkube.TestWorkflowExecutionNotification, error)
   144  }
   145  
   146  // TestWorkflowExecutionAPI describes test workflow api methods
   147  type TestWorkflowExecutionAPI interface {
   148  	GetTestWorkflowExecution(executionID string) (execution testkube.TestWorkflowExecution, err error)
   149  	ListTestWorkflowExecutions(id string, limit int, selector string) (executions testkube.TestWorkflowExecutionsResult, err error)
   150  	AbortTestWorkflowExecution(workflow string, id string) error
   151  	AbortTestWorkflowExecutions(workflow string) error
   152  	GetTestWorkflowExecutionArtifacts(executionID string) (artifacts testkube.Artifacts, err error)
   153  	DownloadTestWorkflowArtifact(executionID, fileName, destination string) (artifact string, err error)
   154  	DownloadTestWorkflowArtifactArchive(executionID, destination string, masks []string) (archive string, err error)
   155  }
   156  
   157  // TestWorkflowTemplateAPI describes test workflow api methods
   158  type TestWorkflowTemplateAPI interface {
   159  	GetTestWorkflowTemplate(id string) (testkube.TestWorkflowTemplate, error)
   160  	ListTestWorkflowTemplates(selector string) (testkube.TestWorkflowTemplates, error)
   161  	DeleteTestWorkflowTemplates(selector string) error
   162  	CreateTestWorkflowTemplate(workflow testkube.TestWorkflowTemplate) (testkube.TestWorkflowTemplate, error)
   163  	UpdateTestWorkflowTemplate(workflow testkube.TestWorkflowTemplate) (testkube.TestWorkflowTemplate, error)
   164  	DeleteTestWorkflowTemplate(name string) error
   165  }
   166  
   167  // CopyFileAPI describes methods to handle files in the object storage
   168  type CopyFileAPI interface {
   169  	UploadFile(parentName string, parentType TestingType, filePath string, fileContent []byte, timeout time.Duration) error
   170  }
   171  
   172  // TODO consider replacing below types by testkube.*
   173  
   174  // UpsertTestSuiteOptions - mapping to OpenAPI schema for creating testsuite
   175  type UpsertTestSuiteOptions testkube.TestSuiteUpsertRequest
   176  
   177  // UpdateTestSuiteOptions - mapping to OpenAPI schema for changing testsuite
   178  type UpdateTestSuiteOptions testkube.TestSuiteUpdateRequest
   179  
   180  // UpsertTestOptions - is mapping for now to OpenAPI schema for creating test
   181  // if needed can be extended to custom struct
   182  type UpsertTestOptions testkube.TestUpsertRequest
   183  
   184  // UpdateTestOptions - is mapping for now to OpenAPI schema for changing test
   185  // if needed can be extended to custom struct
   186  type UpdateTestOptions testkube.TestUpdateRequest
   187  
   188  // UpsertExecutorOptions - is mapping for now to OpenAPI schema for creating executor request
   189  type UpsertExecutorOptions testkube.ExecutorUpsertRequest
   190  
   191  // UpdateExecutorOptions - is mapping for now to OpenAPI schema for changing executor request
   192  type UpdateExecutorOptions testkube.ExecutorUpdateRequest
   193  
   194  // CreateWebhookOptions - is mapping for now to OpenAPI schema for creating/changing webhook
   195  type CreateWebhookOptions testkube.WebhookCreateRequest
   196  
   197  // UpdateWebhookOptions - is mapping for now to OpenAPI schema for changing webhook request
   198  type UpdateWebhookOptions testkube.WebhookUpdateRequest
   199  
   200  // UpsertTestSourceOptions - is mapping for now to OpenAPI schema for creating test source
   201  // if needed can be extended to custom struct
   202  type UpsertTestSourceOptions testkube.TestSourceUpsertRequest
   203  
   204  // UpdateTestSourceOptions - is mapping for now to OpenAPI schema for changing test source
   205  // if needed can be extended to custom struct
   206  type UpdateTestSourceOptions testkube.TestSourceUpdateRequest
   207  
   208  // CreateTemplateOptions - is mapping for now to OpenAPI schema for creating/changing template
   209  type CreateTemplateOptions testkube.TemplateCreateRequest
   210  
   211  // UpdateTemplateOptions - is mapping for now to OpenAPI schema for changing template request
   212  type UpdateTemplateOptions testkube.TemplateUpdateRequest
   213  
   214  // TODO consider replacing it with testkube.ExecutionRequest - looks almost the samea and redundant
   215  // ExecuteTestOptions contains test run options
   216  type ExecuteTestOptions struct {
   217  	ExecutionVariables                 map[string]testkube.Variable
   218  	ExecutionVariablesFileContent      string
   219  	IsVariablesFileUploaded            bool
   220  	ExecutionLabels                    map[string]string
   221  	Command                            []string
   222  	Args                               []string
   223  	ArgsMode                           string
   224  	Envs                               map[string]string
   225  	SecretEnvs                         map[string]string
   226  	HTTPProxy                          string
   227  	HTTPSProxy                         string
   228  	Image                              string
   229  	Uploads                            []string
   230  	BucketName                         string
   231  	ArtifactRequest                    *testkube.ArtifactRequest
   232  	JobTemplate                        string
   233  	JobTemplateReference               string
   234  	ContentRequest                     *testkube.TestContentRequest
   235  	PreRunScriptContent                string
   236  	PostRunScriptContent               string
   237  	ExecutePostRunScriptBeforeScraping bool
   238  	SourceScripts                      bool
   239  	ScraperTemplate                    string
   240  	ScraperTemplateReference           string
   241  	PvcTemplate                        string
   242  	PvcTemplateReference               string
   243  	NegativeTest                       bool
   244  	IsNegativeTestChangedOnRun         bool
   245  	EnvConfigMaps                      []testkube.EnvReference
   246  	EnvSecrets                         []testkube.EnvReference
   247  	RunningContext                     *testkube.RunningContext
   248  	SlavePodRequest                    *testkube.PodRequest
   249  	ExecutionNamespace                 string
   250  }
   251  
   252  // ExecuteTestSuiteOptions contains test suite run options
   253  type ExecuteTestSuiteOptions struct {
   254  	ExecutionVariables       map[string]testkube.Variable
   255  	HTTPProxy                string
   256  	HTTPSProxy               string
   257  	ExecutionLabels          map[string]string
   258  	ContentRequest           *testkube.TestContentRequest
   259  	RunningContext           *testkube.RunningContext
   260  	ConcurrencyLevel         int32
   261  	JobTemplate              string
   262  	JobTemplateReference     string
   263  	ScraperTemplate          string
   264  	ScraperTemplateReference string
   265  	PvcTemplate              string
   266  	PvcTemplateReference     string
   267  }
   268  
   269  // Gettable is an interface of gettable objects
   270  type Gettable interface {
   271  	testkube.Test | testkube.TestSuite | testkube.ExecutorDetails |
   272  		testkube.Webhook | testkube.TestWithExecution | testkube.TestSuiteWithExecution | testkube.TestWithExecutionSummary |
   273  		testkube.TestSuiteWithExecutionSummary | testkube.Artifact | testkube.ServerInfo | testkube.Config | testkube.DebugInfo |
   274  		testkube.TestSource | testkube.Template |
   275  		testkube.TestWorkflow | testkube.TestWorkflowWithExecution | testkube.TestWorkflowTemplate | testkube.TestWorkflowExecution
   276  }
   277  
   278  // Executable is an interface of executable objects
   279  type Executable interface {
   280  	testkube.Execution | testkube.TestSuiteExecution | testkube.TestWorkflowExecution |
   281  		testkube.ExecutionsResult | testkube.TestSuiteExecutionsResult | testkube.TestWorkflowExecutionsResult
   282  }
   283  
   284  // All is an interface of all objects
   285  type All interface {
   286  	Gettable | Executable
   287  }
   288  
   289  // Transport provides methods to execute api calls
   290  type Transport[A All] interface {
   291  	Execute(method, uri string, body []byte, params map[string]string) (result A, err error)
   292  	ExecuteMultiple(method, uri string, body []byte, params map[string]string) (result []A, err error)
   293  	Delete(uri, selector string, isContentExpected bool) error
   294  	ExecuteMethod(method, uri, selector string, isContentExpected bool) error
   295  	GetURI(pathTemplate string, params ...interface{}) string
   296  	GetLogs(uri string, logs chan output.Output) error
   297  	GetLogsV2(uri string, logs chan events.Log) error
   298  	GetTestWorkflowExecutionNotifications(uri string, notifications chan testkube.TestWorkflowExecutionNotification) error
   299  	GetFile(uri, fileName, destination string, params map[string][]string) (name string, err error)
   300  }