-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- The framework resolver provides the necessary logic to determine which framework the currently application is. From there the framework is passed back to the consumer to be used in display and reading the file accordingly. - A constant file is used as reference for the supported versions.
- Loading branch information
Showing
6 changed files
with
106 additions
and
2 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
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 +1 @@ | ||
0.0.4 | ||
0.0.5 |
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,10 @@ | ||
package constants | ||
|
||
// Frameworks defines the supported frameworks within the application | ||
// Supported frameworks: | ||
// Generic | ||
// Node.js | ||
var Frameworks = map[string]string{ | ||
"VERSION": "generic", | ||
"package.json": "node", | ||
} |
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
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,23 @@ | ||
package services | ||
|
||
import ( | ||
"errors" | ||
"io/ioutil" | ||
) | ||
|
||
// DetermineFrameworks determines which files are in the root and returns the frameworks | ||
func DetermineFrameworks(directory string, frameworks map[string]string) (string, error) { | ||
|
||
files, _ := ioutil.ReadDir(directory) | ||
for _, file := range files { | ||
|
||
fileName := file.Name() | ||
framework, exists := frameworks[fileName] | ||
|
||
if exists { | ||
return framework, nil | ||
} | ||
} | ||
|
||
return "", errors.New("No frameworks matched") | ||
} |
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,53 @@ | ||
package services | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/franela/goblin" | ||
) | ||
|
||
func Test_Flags(t *testing.T) { | ||
g := Goblin(t) | ||
g.Describe("Framework Resolver", func() { | ||
|
||
g.It("should return 'generic' from DetermineFrameworks since its the first file in test-files", func() { | ||
frameworks := map[string]string{ | ||
"VERSION": "generic", | ||
"package.json": "node", | ||
} | ||
directory := "../test-files" | ||
|
||
expected := "generic" | ||
|
||
actual, _ := DetermineFrameworks(directory, frameworks) | ||
g.Assert(actual).Equal(expected) | ||
}) | ||
|
||
g.It("should return 'node' from DetermineFrameworks if its the only matching framework", func() { | ||
frameworks := map[string]string{ | ||
"package.json": "node", | ||
} | ||
directory := "../test-files" | ||
|
||
expected := "node" | ||
|
||
actual, _ := DetermineFrameworks(directory, frameworks) | ||
g.Assert(actual).Equal(expected) | ||
}) | ||
|
||
g.It("should return an error if no frameworks are matched", func() { | ||
frameworks := map[string]string{ | ||
"foobar.txt": "Foobar Framework", | ||
} | ||
directory := "../test-files" | ||
|
||
expected := "No frameworks matched" | ||
|
||
_, err := DetermineFrameworks(directory, frameworks) | ||
actual := err.Error() | ||
|
||
g.Assert(actual).Equal(expected) | ||
}) | ||
|
||
}) | ||
} |