Skip to content

Commit

Permalink
feat: support for running a given test-sets (#956)
Browse files Browse the repository at this point in the history
* feat: support for running a given test-sets

Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Co-authored-by: Ritik Jain <60597329+re-Tick@users.noreply.github.com>
  • Loading branch information
AkashKumar7902 and re-Tick committed Oct 10, 2023
1 parent a58b369 commit 4ad57f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion cmd/test.go
Expand Up @@ -97,6 +97,12 @@ func (t *Test) GetCmd() *cobra.Command {
t.logger.Error("Failed to get the application's docker network name", zap.Error((err)))
}

testSets, err := cmd.Flags().GetStringSlice("testsets")

if err != nil {
t.logger.Error("Failed to get the testsets flag", zap.Error((err)))
}

delay, err := cmd.Flags().GetUint64("delay")
if err != nil {
t.logger.Error("Failed to get the delay flag", zap.Error((err)))
Expand Down Expand Up @@ -126,14 +132,17 @@ func (t *Test) GetCmd() *cobra.Command {

t.logger.Debug("the ports are", zap.Any("ports", ports))

t.tester.Test(path, testReportPath, appCmd, appContainer, networkName, delay, ports, apiTimeout)
t.tester.Test(path, testReportPath, appCmd, testSets, appContainer, networkName, delay, ports, apiTimeout)
return nil
},
}

testCmd.Flags().StringP("path", "p", "", "Path to local directory where generated testcases/mocks are stored")

testCmd.Flags().StringP("command", "c", "", "Command to start the user application")

testCmd.Flags().StringSliceP("testsets", "t", []string{}, "Testsets to run")

testCmd.Flags().String("containerName", "", "Name of the application's docker container")

testCmd.Flags().StringP("networkName", "n", "", "Name of the application's docker network")
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/test/service.go
Expand Up @@ -8,6 +8,6 @@ import (
)

type Tester interface {
Test(path, testReportPath string, appCmd, appContainer, networkName string, Delay uint64, passThorughPorts []uint, apiTimeout uint64) bool
Test(path, testReportPath string, appCmd string, testsets []string, appContainer, networkName string, Delay uint64, passThorughPorts []uint, apiTimeout uint64) bool
RunTestSet(testSet, path, testReportPath, appCmd, appContainer, appNetwork string, delay uint64, pid uint32, ys platform.TestCaseDB, loadedHook *hooks.Hook, testReportfs yaml.TestReportFS, testRunChan chan string, apiTimeout uint64) models.TestRunStatus
}
18 changes: 17 additions & 1 deletion pkg/service/test/test.go
Expand Up @@ -39,7 +39,7 @@ func NewTester(logger *zap.Logger) Tester {
}
}

func (t *tester) Test(path, testReportPath string, appCmd, appContainer, appNetwork string, Delay uint64, passThorughPorts []uint, apiTimeout uint64) bool {
func (t *tester) Test(path, testReportPath string, appCmd string, testsets []string, appContainer, appNetwork string, Delay uint64, passThorughPorts []uint, apiTimeout uint64) bool {

var ps *proxy.ProxySet

Expand Down Expand Up @@ -114,7 +114,23 @@ func (t *tester) Test(path, testReportPath string, appCmd, appContainer, appNetw

exitLoop := false

if len(testsets) == 0 {
// by default, run all the recorded test sets
testsets = sessions
}

sessionsMap := map[string]string{}

for _, sessionIndex := range sessions {
sessionsMap[sessionIndex] = sessionIndex
}

for _, sessionIndex := range testsets {
// checking whether the provided testset match with a recorded testset.
if _, ok := sessionsMap[sessionIndex]; !ok {
t.logger.Info("no testset found with: ", zap.Any("name", sessionIndex))
continue;
}
testRunStatus := t.RunTestSet(sessionIndex, path, testReportPath, appCmd, appContainer, appNetwork, Delay, 0, ys, loadedHooks, testReportFS, nil, apiTimeout)
switch testRunStatus {
case models.TestRunStatusAppHalted:
Expand Down

0 comments on commit 4ad57f6

Please sign in to comment.