Skip to content

Commit

Permalink
Add framework resolver
Browse files Browse the repository at this point in the history
- 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
oshalygin committed Sep 24, 2017
1 parent d9b3fad commit af97d4b
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 0.0.5 (September 24, 2017)

- Addition of a Framework resolver which determines the framework based on the files present in the directory.
- Addition of a framework constants export, which provides the currently supported versions.

## 0.0.4 (September 23, 2017)

- Addition of a git service to handle tagging and pushing the tags
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.4
0.0.5
10 changes: 10 additions & 0 deletions constants/frameworks.go
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",
}
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package main

import (
"flag"

"github.com/fatih/color"
"github.com/oshalygin/go-tag/constants"
"github.com/oshalygin/go-tag/services"
)

var versionFlagPassed bool
var directory = "."

func init() {
flag.BoolVar(&versionFlagPassed, "version", false, "Print the version of the application")
Expand All @@ -16,5 +21,13 @@ func main() {
printVersion()
}

// services.Tag("0.0.3")
framework, err := services.DetermineFrameworks(directory, constants.Frameworks)

if err != nil {
color.Red("No framework files matched")
return
}

color.Green(framework)

}
23 changes: 23 additions & 0 deletions services/frameworkResolver.go
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")
}
53 changes: 53 additions & 0 deletions services/frameworkResolver_test.go
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)
})

})
}

0 comments on commit af97d4b

Please sign in to comment.