Skip to content

Commit

Permalink
Add Version Service
Browse files Browse the repository at this point in the history
- This is a base implementation of the Version
  Service which provides implementation around
  reading the VERSION file, the generic framework.
  • Loading branch information
oshalygin committed Sep 24, 2017
1 parent 5e4a436 commit d5f19c2
Show file tree
Hide file tree
Showing 6 changed files with 101 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.9 (September 24, 2017)

- Addition of Version Service
- Base implementation against the generic `VERSION` file

## 0.0.8 (September 24, 2017)

- Cleaned up Limitations section in README.md to clearly explain the supported frameworks.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.8
0.0.9
2 changes: 1 addition & 1 deletion services/frameworkResolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
. "github.com/franela/goblin"
)

func Test_Flags(t *testing.T) {
func Test_FrameworkResolver(t *testing.T) {
g := Goblin(t)
g.Describe("Framework Resolver", func() {

Expand Down
49 changes: 49 additions & 0 deletions services/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package services

import (
"errors"
"io/ioutil"
)

var file string

// GetVersion will read the appropriate file based on the framework and return the version value
func GetVersion(framework string) (string, error) {
switch framework {
case "node":
return node(), nil
case "generic":

version, err := generic()
if err != nil {
return version, nil
}

return "", err
default:
return "", errors.New("No matching frameworks")
}
}

func node() string {
return ""
}

func generic() (string, error) {

if file == "file" {
file = "./VERSION"
}

result, err := ioutil.ReadFile(file)
if err != nil {
return "", errors.New("Error reading VERSION file, malformed")
}

content := string(result)
if len(content) <= 0 {
return "", errors.New("No data in VERSION file")
}

return content, nil
}
45 changes: 45 additions & 0 deletions services/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package services

import (
"testing"

. "github.com/franela/goblin"
)

func Test_VersionService(t *testing.T) {
g := Goblin(t)
g.Describe("Version Service", func() {

g.It("should read the VERSION file and return the version found inside", func() {
file = "../test-files/VERSION"

expected := "2.4.9"

actual, _ := generic()
g.Assert(actual).Equal(expected)
})

g.It("should throw an error if the VERSION file is empty", func() {
file = "../test-files/EMPTY_VERSION"

expected := "No data in VERSION file"

_, err := generic()

actual := err.Error()
g.Assert(actual).Equal(expected)
})

g.It("should throw an error if the VERSION file is malformed", func() {
file = "../test-files/NON_EXISTENT_VERSION_FILE"

expected := "Error reading VERSION file, malformed"

_, err := generic()

actual := err.Error()
g.Assert(actual).Equal(expected)
})

})
}
Empty file added test-files/EMPTY_VERSION
Empty file.

0 comments on commit d5f19c2

Please sign in to comment.