-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
513f3a7
commit d5494a7
Showing
4 changed files
with
91 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/paulscherrerinstitute/scicat/datasetUtils" | ||
) | ||
|
||
func TestArgs(t *testing.T) { | ||
// test cases | ||
tests := []struct { | ||
name string | ||
expectedArgs []interface{} | ||
args []string | ||
}{ | ||
// datasetIngestor | ||
{ | ||
name: "datasetIngestor test with 1 param", | ||
expectedArgs: []interface{}{ | ||
"some/place/metadata.json", | ||
"", | ||
"", | ||
}, | ||
args: []string{"datasetIngestor", "some/place/metadata.json"}, | ||
}, | ||
{ | ||
name: "datasetIngestor test with 2 params - folderlisting.txt", | ||
expectedArgs: []interface{}{ | ||
"some/place/metadata.json", | ||
"", | ||
"folderlisting.txt", | ||
}, | ||
args: []string{"datasetIngestor", "some/place/metadata.json", "folderlisting.txt"}, | ||
}, | ||
{ | ||
name: "datasetIngestor test with 2 params - filelisting", | ||
expectedArgs: []interface{}{ | ||
"some/place/metadata.json", | ||
"/some/path/", | ||
"", | ||
}, | ||
args: []string{"datasetIngestor", "some/place/metadata.json", "/some/path/"}, | ||
}, | ||
} | ||
|
||
// running test cases | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
//flag.CommandLine = flag.NewFlagSet(test.name, flag.ExitOnError) | ||
datasetUtils.TestArgs = func(args []interface{}) { | ||
passing := true | ||
for i, _ := range test.expectedArgs { | ||
if test.expectedArgs[i] != args[i] { | ||
t.Logf("'%v' is not correct, expected: '%s'", args[i], test.expectedArgs[i]) | ||
passing = false | ||
} | ||
} | ||
if !passing { | ||
t.Fail() | ||
} | ||
} | ||
|
||
rootCmd.SetArgs(test.args) | ||
Execute() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package datasetUtils | ||
|
||
var TestFlags func(flags map[string]interface{}) = nil | ||
var TestArgs func(args []interface{}) = nil |