44package commands_test
55
66import (
7+ "os"
8+ "path/filepath"
79 "testing"
8- )
910
10- var (
11- // packFilePath1 = filepath.Join(testingDir, "TheVendor.PublicLocalPack.pack")
12- // fileWithPacksListed1 = "file_with_listed_packs.txt"
13- // fileWithNoPacksListed1 = "file_with_no_listed_packs.txt"
11+ errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
1412)
1513
1614var updateCmdTests = []TestCase {
@@ -19,85 +17,70 @@ var updateCmdTests = []TestCase{
1917 args : []string {"help" , "update" },
2018 expectedErr : nil ,
2119 },
22- /* {
20+ {
2321 name : "test updating pack file no args" ,
2422 args : []string {"update" },
2523 createPackRoot : true ,
26- expectedStdout: []string{"Missing a pack-path or list with pack urls specified via -f/--packs-list-filename"},
27- expectedErr: errs.ErrIncorrectCmdArgs,
28- },*/
29- /*{
30- name: "test updating pack file default mode",
31- args: []string{"update", packFilePath1},
32- createPackRoot: true,
33- defaultMode: true,
34- expectedStdout: []string{"updating pack", filepath.Base(packFilePath1)},
35- },*/
36- /*{
37- name: "test updating pack file default mode no preexisting index",
38- args: []string{"update", packFilePath1},
39- createPackRoot: false,
40- defaultMode: true,
41- expectedStdout: []string{"updating pack", filepath.Base(packFilePath1)},
42- },*/
24+ expectedErr : nil ,
25+ },
4326 {
4427 name : "test updating pack missing file" ,
4528 args : []string {"update" , "DoesNotExist.Pack" },
4629 createPackRoot : true ,
47- // expectedStdout: []string{"cannot be determined"},
48- // expectedErr: errs.ErrPackURLCannotBeFound,
30+ expectedStdout : []string {"is not installed" },
4931 },
50- /* {
51- name: "test updating pack file",
52- args: []string{"update", packFilePath},
53- createPackRoot: true,
54- expectedStdout: []string{"updating pack", filepath.Base(packFilePath)},
32+ {
33+ name : "test updating packs listed in file" ,
34+ args : []string {"update" , "-f" , fileWithPacksListed },
35+ createPackRoot : true ,
36+ expectedStdout : []string {"Parsing packs urls via file " + fileWithPacksListed ,
37+ "is not installed" , filepath .Base ("DoesNotExist.Pack" )},
38+ setUpFunc : func (t * TestCase ) {
39+ f , _ := os .Create (fileWithPacksListed )
40+ _ , _ = f .WriteString ("DoesNotExist.Pack" )
41+ f .Close ()
42+ },
43+ tearDownFunc : func () {
44+ os .Remove (fileWithPacksListed )
5545 },
56- {
57- name: "test updating packs listed in file",
58- args: []string{"update", "-f", fileWithPacksListed},
59- createPackRoot: true,
60- expectedStdout: []string{"Parsing packs urls via file " + fileWithPacksListed,
61- "Updating pack", filepath.Base(packFilePath)},
62- setUpFunc: func(t *TestCase) {
63- f, _ := os.Create(fileWithPacksListed)
64- _, _ = f.WriteString(packFilePath)
65- f.Close()
66- },
67- tearDownFunc: func() {
68- os.Remove(fileWithPacksListed)
69- },
46+ },
47+ {
48+ name : "test updating empty packs list file" ,
49+ args : []string {"update" , "-f" , fileWithNoPacksListed },
50+ createPackRoot : true ,
51+ expectedStdout : []string {"Parsing packs urls via file " + fileWithNoPacksListed },
52+ expectedErr : nil ,
53+ setUpFunc : func (t * TestCase ) {
54+ f , _ := os .Create (fileWithNoPacksListed )
55+ _ , _ = f .WriteString ("" )
56+ f .Close ()
7057 },
71- {
72- name: "test updating empty packs list file",
73- args: []string{"update", "-f", fileWithNoPacksListed},
74- createPackRoot: true,
75- expectedStdout: []string{"Parsing packs urls via file " + fileWithNoPacksListed},
76- expectedErr: nil,
77- setUpFunc: func(t *TestCase) {
78- f, _ := os.Create(fileWithNoPacksListed)
79- _, _ = f.WriteString("")
80- f.Close()
81- },
82- tearDownFunc: func() {
83- os.Remove(fileWithNoPacksListed)
84- },
58+ tearDownFunc : func () {
59+ os .Remove (fileWithNoPacksListed )
8560 },
86- {
87- name: "test updating empty packs list file (but whitespace characters)",
88- args: []string{"update", "-f", fileWithNoPacksListed},
89- createPackRoot: true,
90- expectedStdout: []string{"Parsing packs urls via file " + fileWithNoPacksListed},
91- expectedErr: nil,
92- setUpFunc: func(t *TestCase) {
93- f, _ := os.Create(fileWithNoPacksListed)
94- _, _ = f.WriteString(" \n \t \n")
95- f.Close()
96- },
97- tearDownFunc: func() {
98- os.Remove(fileWithNoPacksListed)
99- },
100- },*/
61+ },
62+ {
63+ name : "test updating empty packs list file (but whitespace characters)" ,
64+ args : []string {"update" , "-f" , fileWithNoPacksListed },
65+ createPackRoot : true ,
66+ expectedStdout : []string {"Parsing packs urls via file " + fileWithNoPacksListed },
67+ expectedErr : nil ,
68+ setUpFunc : func (t * TestCase ) {
69+ f , _ := os .Create (fileWithNoPacksListed )
70+ _ , _ = f .WriteString (" \n \t \n " )
71+ f .Close ()
72+ },
73+ tearDownFunc : func () {
74+ os .Remove (fileWithNoPacksListed )
75+ },
76+ },
77+ {
78+ name : "test updating packs listed in missing file" ,
79+ args : []string {"update" , "-f" , fileWithPacksListed },
80+ createPackRoot : true ,
81+ expectedErr : errs .ErrFileNotFound ,
82+ expectedStdout : []string {"Parsing packs urls via file " + fileWithPacksListed },
83+ },
10184}
10285
10386func TestUpdateCmd (t * testing.T ) {
0 commit comments