github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/tests/messaging_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/taubyte/tau-cli/constants"
     8  	messagingPrompts "github.com/taubyte/tau-cli/prompts/messaging"
     9  )
    10  
    11  func TestMessagingAll(t *testing.T) {
    12  	runTests(t, createMessagingMonkey(), true)
    13  }
    14  
    15  func createMessagingMonkey() *testSpider {
    16  	// Define shared variables
    17  	command := "messaging"
    18  	profileName := "test"
    19  	projectName := "test_project"
    20  	testName := "someMessaging"
    21  
    22  	// Create a basic resource of name
    23  	basicNew := func(name string) []string {
    24  		return []string{
    25  			"new", "-y", command,
    26  			"--name", name,
    27  			"--description", "some messaging description",
    28  			"--tags", "tag1, tag2,   tag3",
    29  			"--match", "xpath",
    30  			"--no-local",
    31  			"--no-mqtt",
    32  			"--no-ws",
    33  			"--no-regex",
    34  		}
    35  	}
    36  
    37  	// The config that will be written
    38  	getConfigString := basicGetConfigString(profileName, projectName)
    39  
    40  	// Run before each test
    41  	beforeEach := func(tt testMonkey) [][]string {
    42  		tt.env[constants.CurrentProjectEnvVarName] = projectName
    43  		return nil
    44  	}
    45  
    46  	// Define test monkeys that will run in parallel
    47  	tests := []testMonkey{
    48  		{
    49  			name: "Query new",
    50  			args: []string{"query", command, testName},
    51  			wantOut: []string{
    52  				testName,
    53  				"some messaging description",
    54  				"tag1", "tag2", "tag3",
    55  				"false", "xpath",
    56  			},
    57  			dontWantOut: []string{"true"},
    58  			children: []testMonkey{
    59  				{
    60  					name:    "New basic",
    61  					args:    basicNew(testName),
    62  					wantOut: []string{command, testName, "Created"},
    63  				},
    64  			},
    65  		},
    66  		{
    67  			name: "Query edit",
    68  			args: []string{"query", command, testName},
    69  			wantOut: []string{
    70  				testName,
    71  				"some new messaging description",
    72  				"tag1", "tag2", "tag341",
    73  				"true", "xpdsaath",
    74  			},
    75  			preRun: [][]string{
    76  				basicNew(testName),
    77  			},
    78  			children: []testMonkey{
    79  				{
    80  					name: "Edit basic",
    81  					args: []string{"edit", "-y", command, "--name", testName,
    82  						"--description", "some new messaging description",
    83  						"--tags", "tag1, tag2,   tag341",
    84  						"--local",
    85  						"--regex",
    86  						"--match", "xpdsaath",
    87  						"--mqtt",
    88  						"--web-socket",
    89  					},
    90  					wantOut: []string{command, testName, "Edited"},
    91  				},
    92  			},
    93  		},
    94  		{
    95  			name:     "Query delete",
    96  			args:     []string{"query", command, testName},
    97  			exitCode: 1,
    98  			errOut:   []string{fmt.Sprintf(messagingPrompts.NotFound, testName)},
    99  			preRun: [][]string{
   100  				basicNew(testName),
   101  				{"delete", "-y", command, "--name", testName},
   102  			},
   103  		},
   104  		{
   105  			name: "Query list",
   106  			args: []string{"query", command, "--list"},
   107  			wantOut: []string{
   108  				"someMsging1",
   109  				"someMsging2",
   110  				// "someMsging3", deleted
   111  				"someMsging4",
   112  				"someMsging5",
   113  			},
   114  			dontWantOut: []string{
   115  				"someMsging3",
   116  			},
   117  			preRun: [][]string{
   118  				basicNew("someMsging1"),
   119  				basicNew("someMsging2"),
   120  				basicNew("someMsging3"),
   121  				{"delete", "-y", command, "--name", "someMsging3"},
   122  				basicNew("someMsging4"),
   123  				basicNew("someMsging5"),
   124  			},
   125  		},
   126  		{
   127  			name:     "Query New no -y",
   128  			args:     []string{"query", command, testName},
   129  			exitCode: 1,
   130  			errOut:   []string{fmt.Sprintf(messagingPrompts.NotFound, testName)},
   131  			children: []testMonkey{
   132  				{
   133  					name: "new no -y",
   134  					args: []string{
   135  						"new", command, "--name", testName,
   136  						"--description", "some messaging description",
   137  						"--tags", "tag1, tag2,   tag3",
   138  						"--match", "xpath",
   139  						"--no-local",
   140  						"--no-mqtt",
   141  						"--no-web-socket",
   142  						"--no-regex",
   143  					},
   144  					exitCode: 1,
   145  					errOut:   []string{"EOF"},
   146  				},
   147  			},
   148  		},
   149  		{
   150  			name: "Query Edit no -y",
   151  			args: []string{"query", command, testName},
   152  			dontWantOut: []string{
   153  				"some new messaging description",
   154  				"tag341",
   155  				"true", "xpdsaath",
   156  			},
   157  			preRun: [][]string{
   158  				basicNew(testName),
   159  			},
   160  			children: []testMonkey{
   161  				{
   162  					name: "Edit no -y",
   163  					args: []string{"edit", command, "--name", testName,
   164  						"--description", "some new messaging description",
   165  						"--tags", "tag1, tag2,   tag341",
   166  						"--local",
   167  						"--regex",
   168  						"--match", "xpdsaath",
   169  						"--mqtt",
   170  						"--web-socket",
   171  					},
   172  					exitCode: 1,
   173  					errOut:   []string{"EOF"},
   174  				},
   175  			},
   176  		},
   177  		{
   178  			name: "New with selected application",
   179  			args: []string{"query", command, testName},
   180  			wantOut: []string{
   181  				testName,
   182  				"some messaging description",
   183  				"tag1", "tag2", "tag3",
   184  				"false", "xpath",
   185  			},
   186  			dontWantOut: []string{"true"},
   187  			preRun: [][]string{
   188  				basicNew(testName),
   189  			},
   190  			env: map[string]string{
   191  				constants.CurrentApplicationEnvVarName: "someasdasdapp",
   192  			},
   193  		},
   194  		{
   195  			name: "Edit with selected application",
   196  			args: []string{"query", command, testName},
   197  			wantOut: []string{
   198  				testName,
   199  				"some new messaging description",
   200  				"tag1", "tag2", "tag341",
   201  				"true", "xpdsaath",
   202  			},
   203  			preRun: [][]string{
   204  				basicNew(testName),
   205  			},
   206  			env: map[string]string{
   207  				constants.CurrentApplicationEnvVarName: "someasdasdapp",
   208  			},
   209  			children: []testMonkey{
   210  				{
   211  					name: "Edit with selected application",
   212  					args: []string{"edit", "-y", command, "--name", testName,
   213  						"--description", "some new messaging description",
   214  						"--tags", "tag1, tag2,   tag341",
   215  						"--local",
   216  						"--regex",
   217  						"--match", "xpdsaath",
   218  						"--mqtt",
   219  						"--web-socket",
   220  					},
   221  				},
   222  			},
   223  		},
   224  		{
   225  			name:     "Delete with selected application",
   226  			args:     []string{"query", command, testName},
   227  			exitCode: 1,
   228  			errOut:   []string{fmt.Sprintf(messagingPrompts.NotFound, testName)},
   229  			preRun: [][]string{
   230  				basicNew(testName),
   231  			},
   232  			env: map[string]string{
   233  				constants.CurrentApplicationEnvVarName: "someasdasdapp",
   234  			},
   235  			children: []testMonkey{
   236  				{
   237  					name: "Delete with selected application",
   238  					args: []string{"delete", "-y", command, "--name", testName},
   239  				},
   240  			},
   241  		},
   242  	}
   243  	return &testSpider{projectName, tests, beforeEach, getConfigString, "messaging"}
   244  }