-
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.
- This is a base implementation of the Version Service which provides implementation around reading the VERSION file, the generic framework.
- Loading branch information
Showing
6 changed files
with
101 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.8 | ||
0.0.9 |
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,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 | ||
} |
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,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.