Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #66 from davalb/config-test-2
Browse files Browse the repository at this point in the history
adds tests to three functions in the repo package
  • Loading branch information
cpacia committed Aug 7, 2016
2 parents fc385c6 + 214e55f commit d6c9498
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
58 changes: 57 additions & 1 deletion repo/config_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package repo

import (
"reflect"
"testing"
)

const testConfigPath = "testdata/config"
const nonexistentTestConfigPath = "testdata/nonexistent"

func TestGetAPIUsernameAndPw(t *testing.T) {
username, pw, err := GetAPIUsernameAndPw(testConfigPath)
Expand All @@ -18,7 +20,7 @@ func TestGetAPIUsernameAndPw(t *testing.T) {
t.Error("GetAPIUsernameAndPw threw an unexpected error")
}

username, pw, err = GetAPIUsernameAndPw("testdata/nonexistent")
username, pw, err = GetAPIUsernameAndPw(nonexistentTestConfigPath)
if username != "" {
t.Error("Expected empty string, got ", username)
}
Expand All @@ -29,3 +31,57 @@ func TestGetAPIUsernameAndPw(t *testing.T) {
t.Error("GetAPIUsernameAndPw didn`t throw an error")
}
}

func TestGetAPIHeaders(t *testing.T) {
headers, err := GetAPIHeaders(testConfigPath)
if reflect.ValueOf(headers).Kind() != reflect.Map {
t.Error("headers is not a map")
}
if err != nil {
t.Error("GetAPIHeaders threw an unexpected error")
}

headers, err = GetAPIHeaders(nonexistentTestConfigPath)
if reflect.ValueOf(headers).Kind() != reflect.Map {
t.Error("headers is not a map")
}
if err == nil {
t.Error("GetAPIHeaders didn`t throw an error")
}
}

func TestGetAPIEnabled(t *testing.T) {
enabled, err := GetAPIEnabled(testConfigPath)
if enabled != true {
t.Error("enabled is not true")
}
if err != nil {
t.Error("GetAPIEnabled threw an unexpected error")
}

enabled, err = GetAPIEnabled(nonexistentTestConfigPath)
if enabled != false {
t.Error("enabled is not false when path to config file is nonexistent")
}
if err == nil {
t.Error("GetAPIEnabled didn`t throw an error")
}
}

func TestGetAPICORS(t *testing.T) {
cors, err := GetAPICORS(testConfigPath)
if cors != true {
t.Error("cors is not true")
}
if err != nil {
t.Error("GetAPICORS threw an unexpected error")
}

cors, err = GetAPICORS(nonexistentTestConfigPath)
if cors != false {
t.Error("cors is not false when path to config file is nonexistent")
}
if err == nil {
t.Error("GetAPICORS didn`t throw an error")
}
}
2 changes: 1 addition & 1 deletion repo/testdata/config
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"IPNS": "/ipns"
},
"OB-API": {
"CORS": false,
"CORS": true,
"Enabled": true,
"HTTPHeaders": null,
"Password": "TestPassword",
Expand Down

0 comments on commit d6c9498

Please sign in to comment.