(t *testing.T)
| 38 | } |
| 39 | |
| 40 | func TestNamespacesCreate(t *testing.T) { |
| 41 | tests := []struct { |
| 42 | name string |
| 43 | doctlFlags map[string]any |
| 44 | expectedOutput string |
| 45 | expectedError error |
| 46 | expectList bool |
| 47 | willConnect bool |
| 48 | }{ |
| 49 | { |
| 50 | name: "no flags", |
| 51 | expectedError: errors.New("the '--label' and '--region' flags are both required"), |
| 52 | }, |
| 53 | { |
| 54 | name: "invalid region", |
| 55 | doctlFlags: map[string]any{ |
| 56 | "label": "my_dog", |
| 57 | "region": "dog", |
| 58 | }, |
| 59 | expectedError: errors.New("'dog' is not a valid region value"), |
| 60 | }, |
| 61 | { |
| 62 | name: "legal flags, with no-connect", |
| 63 | doctlFlags: map[string]any{ |
| 64 | "label": "something", |
| 65 | "region": "lon", |
| 66 | "no-connect": true, |
| 67 | }, |
| 68 | expectedOutput: "New namespace hello created, but not connected.\n", |
| 69 | expectList: true, |
| 70 | }, |
| 71 | { |
| 72 | name: "legal flags, with label conflict", |
| 73 | doctlFlags: map[string]any{ |
| 74 | "label": "my_dog", |
| 75 | "region": "lon", |
| 76 | }, |
| 77 | expectList: true, |
| 78 | expectedError: errors.New("you are using label 'my_dog' for another namespace; labels should be unique"), |
| 79 | }, |
| 80 | { |
| 81 | name: "legal flags, should connect", |
| 82 | doctlFlags: map[string]any{ |
| 83 | "label": "something", |
| 84 | "region": "lon", |
| 85 | }, |
| 86 | expectList: true, |
| 87 | willConnect: true, |
| 88 | expectedOutput: "Connected to functions namespace 'hello' on API host 'https://api.example.com'\n", |
| 89 | }, |
| 90 | } |
| 91 | for _, tt := range tests { |
| 92 | t.Run(tt.name, func(t *testing.T) { |
| 93 | withTestClient(t, func(config *CmdConfig, tm *tcMocks) { |
| 94 | buf := &bytes.Buffer{} |
| 95 | config.Out = buf |
| 96 | if tt.doctlFlags != nil { |
| 97 | for k, v := range tt.doctlFlags { |
nothing calls this directly
no test coverage detected