Explorar el Código

Implements IsIssue(), func to check if path follows spec

arianagiroux hace 3 semanas
padre
commit
952d626705
Se han modificado 4 ficheros con 40 adiciones y 0 borrados
  1. 20 0
      io.go
  2. 20 0
      io_test.go
  3. 0 0
      tests/bugs/test-3/tags/.gitignore
  4. 0 0
      tests/isnotabug/.gitignore

+ 20 - 0
io.go

@@ -18,6 +18,26 @@ func readPath(path string) (output string, err error) {
 	return output, nil
 }
 
+func IsIssue(path string) (success bool, err error) {
+	files, err := os.ReadDir(path)
+	if err != nil {
+		return false, err
+	}
+
+	var specFiles []bool
+	for _, file := range files {
+		if file.Name() == "description" || file.Name() == "status" {
+			specFiles = append(specFiles, true)
+		}
+	}
+
+	if len(specFiles) >= 2 {
+		return true, nil
+	}
+
+	return false, nil
+}
+
 // Writes a issue to disk
 func WriteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement
 

+ 20 - 0
io_test.go

@@ -22,3 +22,23 @@ 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")
+	}
+	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")
+	}
+	assert.False(t, val)
+}
+
+func Test_IsPath_throws_error(t *testing.T) {
+	_, err := IsIssue("willneverexist")
+	assert.Error(t, err)
+}

+ 0 - 0
tests/bugs/test-3/tags/.gitignore


+ 0 - 0
tests/isnotabug/.gitignore