Ver Fonte

Updated IsIssue to handle IO errors gracefully

arianagiroux há 3 semanas atrás
pai
commit
f34fc0e0f6
3 ficheiros alterados com 15 adições e 19 exclusões
  1. 1 2
      cmd/issues.go
  2. 5 4
      io.go
  3. 9 13
      io_test.go

+ 1 - 2
cmd/issues.go

@@ -27,8 +27,7 @@ func main() {
 		os.Exit(1)
 	}
 
-	isIssue, _ := issues.IsIssue(arg[0])
-	if isIssue {
+	if issues.IsIssue(arg[0]) {
 		issue, err := issues.Issue.NewFromPath(issues.Issue{}, arg[0])
 		if err != nil {
 			fmt.Println("could not load issue:", err)

+ 5 - 4
io.go

@@ -18,10 +18,11 @@ func readPath(path string) (output string, err error) {
 	return output, nil
 }
 
-func IsIssue(path string) (success bool, err error) {
+// Reports true when the specified path conforms to the minimum Poorman spec
+func IsIssue(path string) bool {
 	files, err := os.ReadDir(path)
 	if err != nil {
-		return false, err
+		return false
 	}
 
 	var specFiles []bool
@@ -32,10 +33,10 @@ func IsIssue(path string) (success bool, err error) {
 	}
 
 	if len(specFiles) >= 2 {
-		return true, nil
+		return true
 	}
 
-	return false, nil
+	return false
 }
 
 // Writes a issue to disk

+ 9 - 13
io_test.go

@@ -22,23 +22,19 @@ func Test_readPath_succeeds(t *testing.T) {
 	assert.Equal(t, data, "test description\n")
 }
 
-func Test_IsPath_success(t *testing.T) {
-	val, err := IsIssue("tests/bugs/test-1")
-	if err != nil {
-		assert.Fail(t, "should not throw error")
-	}
+func Test_IsIssue_success(t *testing.T) {
+	val := IsIssue("tests/bugs/test-1")
 	assert.True(t, val)
 }
 
-func Test_IsPath_fail(t *testing.T) {
-	val, err := IsIssue("tests/isnotabug")
-	if err != nil {
-		assert.Fail(t, "should not throw error")
-	}
+func Test_IsIssue_fail(t *testing.T) {
+	val := IsIssue("tests/isnotabug")
+	assert.False(t, val)
+}
+
+func Test_IsIssue_returns_false_on_error(t *testing.T) {
+	val := IsIssue("willneverexist")
 	assert.False(t, val)
 }
 
-func Test_IsPath_throws_error(t *testing.T) {
-	_, err := IsIssue("willneverexist")
-	assert.Error(t, err)
 }