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

     1  package tests
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/taubyte/tau-cli/constants"
     8  	applicationPrompts "github.com/taubyte/tau-cli/prompts/application"
     9  )
    10  
    11  func TestApplicationAll(t *testing.T) {
    12  	runTests(t, createApplicationMonkey(), true)
    13  }
    14  
    15  func createApplicationMonkey() *testSpider {
    16  
    17  	// Define shared variables
    18  	command := "application"
    19  	profileName := "test"
    20  	projectName := "test_project"
    21  	testApplicationName := "someApp"
    22  
    23  	// Define method for simple resource creation of name
    24  	basicNew := func(name string) []string {
    25  		return []string{
    26  			"new", "-y", command,
    27  			"--name", name,
    28  			"--description", "some app desc",
    29  			"--tags", "some, other, tags",
    30  
    31  			"--color", "never",
    32  		}
    33  	}
    34  
    35  	// The config that will be written
    36  	getConfigString := basicGetConfigString(profileName, projectName)
    37  
    38  	// Run before each test
    39  	beforeEach := func(tt testMonkey) [][]string {
    40  		tt.env[constants.CurrentProjectEnvVarName] = projectName
    41  		return nil
    42  	}
    43  
    44  	// Define tests
    45  	tests := []testMonkey{
    46  		{
    47  			name:    "New Basic",
    48  			args:    []string{"query", command, "--name", testApplicationName},
    49  			wantOut: []string{testApplicationName, "some app desc", "some", "other", "tags"},
    50  			preRun:  [][]string{},
    51  			children: []testMonkey{{
    52  				name:    "new",
    53  				args:    basicNew(testApplicationName),
    54  				wantOut: []string{"Created application:", testApplicationName},
    55  			}},
    56  		},
    57  		{
    58  			name:     "New Basic no -y",
    59  			args:     []string{"new", command, "--name", testApplicationName, "--description", "some app desc", "--tags", "some, other, tags"},
    60  			exitCode: 1,
    61  			errOut:   []string{"EOF"},
    62  		},
    63  		{
    64  			name:    "Edit Basic",
    65  			args:    []string{"query", command, "--name", testApplicationName},
    66  			wantOut: []string{testApplicationName, "some nedwdadda", "some", "wack", "tags"},
    67  			preRun: [][]string{
    68  				basicNew(testApplicationName),
    69  			},
    70  			children: []testMonkey{{
    71  				args: []string{
    72  					"edit", "-y", command,
    73  					"--name", testApplicationName,
    74  					"--description", "some nedwdadda",
    75  					"--tags", "some, wack, tags",
    76  					"--color", "never",
    77  				},
    78  				wantOut: []string{"Edited application: " + testApplicationName},
    79  			}},
    80  		},
    81  		{
    82  			name:     "Edit Basic no -y",
    83  			args:     []string{"edit", command, "--name", testApplicationName, "--description", "some nedwdadda", "--tags", "some, dsadsad, tags"},
    84  			exitCode: 1,
    85  			errOut:   []string{"EOF"},
    86  			preRun: [][]string{
    87  				basicNew(testApplicationName),
    88  			},
    89  		},
    90  		{
    91  			name:     "Delete Basic",
    92  			args:     []string{"query", command, "--name", testApplicationName},
    93  			exitCode: 1,
    94  			errOut:   []string{fmt.Sprintf(applicationPrompts.NotFound, testApplicationName)},
    95  			preRun: [][]string{
    96  				basicNew(testApplicationName),
    97  			},
    98  			children: []testMonkey{{
    99  				args: []string{
   100  					"delete", "-y", command,
   101  					"--name", testApplicationName,
   102  					"--color", "never",
   103  				},
   104  				wantOut: []string{"Deleted application: " + testApplicationName},
   105  			}},
   106  		},
   107  		{
   108  			name:    "Delete Basic no -y",
   109  			args:    []string{"query", command, "--name", testApplicationName},
   110  			wantOut: []string{testApplicationName, "some app desc", "some", "other", "tags"},
   111  			preRun: [][]string{
   112  				basicNew(testApplicationName),
   113  			},
   114  			children: []testMonkey{
   115  				{
   116  					args:     []string{"delete", command, "--name", testApplicationName},
   117  					exitCode: 1,
   118  					errOut:   []string{"EOF"},
   119  				},
   120  			},
   121  		},
   122  		{
   123  			name:        "Query",
   124  			args:        []string{"query", command, "--list"},
   125  			wantOut:     []string{"someapp1", "someapp2", "someapp3", "someapp4", "someapp5"},
   126  			dontWantOut: []string{"someapp13"},
   127  			preRun: [][]string{
   128  				basicNew("someapp1"),
   129  				basicNew("someapp2"),
   130  				basicNew("someapp3"),
   131  				basicNew("someapp13"),
   132  				{"delete", "-y", command, "--name", "someapp13"},
   133  				basicNew("someapp4"),
   134  				basicNew("someapp5"),
   135  			},
   136  			env: map[string]string{
   137  				constants.CurrentApplicationEnvVarName: "",
   138  			},
   139  		},
   140  		{
   141  			name:    "Select from new",
   142  			args:    basicNew(testApplicationName),
   143  			wantOut: []string{"Selected application:", testApplicationName},
   144  		},
   145  		{
   146  			name:    "Select from created",
   147  			args:    []string{"select", command, "--name", "someapp1", "--color", "never"},
   148  			wantOut: []string{"Selected application: someapp1"},
   149  			preRun: [][]string{
   150  				basicNew("someapp1"),
   151  				basicNew("someapp2"),
   152  			},
   153  		},
   154  		{
   155  			name:     "Select non exsistant",
   156  			args:     []string{"select", command, "--name", "somenoneapp1"},
   157  			exitCode: 1,
   158  			errOut:   []string{"application `somenoneapp1` not found"},
   159  			preRun: [][]string{
   160  				basicNew("someapp1"),
   161  				basicNew("someapp2"),
   162  			},
   163  		},
   164  	}
   165  	return &testSpider{projectName, tests, beforeEach, getConfigString, "application"}
   166  }