| 149 | } |
| 150 | |
| 151 | func TestSubmitFilesAndDir(t *testing.T) { |
| 152 | tmpDir, err := os.MkdirTemp("", "submit-no-such-file") |
| 153 | defer os.RemoveAll(tmpDir) |
| 154 | assert.NoError(t, err) |
| 155 | |
| 156 | v := viper.New() |
| 157 | v.Set("token", "abc123") |
| 158 | v.Set("workspace", tmpDir) |
| 159 | v.Set("apibaseurl", "http://api.example.com") |
| 160 | |
| 161 | cfg := config.Config{ |
| 162 | Persister: config.InMemoryPersister{}, |
| 163 | UserViperConfig: v, |
| 164 | DefaultBaseURL: "http://example.com", |
| 165 | } |
| 166 | |
| 167 | err = os.WriteFile(filepath.Join(tmpDir, "file-1.txt"), []byte("This is file 1"), os.FileMode(0755)) |
| 168 | assert.NoError(t, err) |
| 169 | |
| 170 | err = os.WriteFile(filepath.Join(tmpDir, "file-2.txt"), []byte("This is file 2"), os.FileMode(0755)) |
| 171 | assert.NoError(t, err) |
| 172 | files := []string{ |
| 173 | filepath.Join(tmpDir, "file-1.txt"), |
| 174 | tmpDir, |
| 175 | filepath.Join(tmpDir, "file-2.txt"), |
| 176 | } |
| 177 | |
| 178 | err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), files) |
| 179 | if assert.Error(t, err) { |
| 180 | assert.Regexp(t, "submitting a directory", err.Error()) |
| 181 | assert.Regexp(t, "Please change into the directory and provide the path to the file\\(s\\) you wish to submit", err.Error()) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | func TestDuplicateFiles(t *testing.T) { |
| 186 | co := newCapturedOutput() |