Skip to content

Commit

Permalink
Merge pull request #76 from cagiti/add_missing_case_where_hosts_file_…
Browse files Browse the repository at this point in the history
…doesnt_exist

fix: add missing test case where hosts.yml doesn't exist
  • Loading branch information
garethjevans authored Nov 17, 2020
2 parents 54fe710 + 3616a2d commit 8d1424a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v1
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.27
version: v1.28
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,13 @@ k8s.io/apimachinery v0.19.0 h1:gjKnAda/HZp5k4xQYjL0K/Yb66IvNqjthCb03QlKpaQ=
k8s.io/apimachinery v0.19.0/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
k8s.io/apimachinery v0.19.3 h1:bpIQXlKjB4cB/oNpnNnV+BybGPR7iP5oYpsOTEJ4hgc=
k8s.io/apimachinery v0.19.3/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
k8s.io/apimachinery v0.19.4 h1:+ZoddM7nbzrDCp0T3SWnyxqf8cbWPT2fkZImoyvHUG0=
k8s.io/apimachinery v0.19.4/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
k8s.io/client-go v0.19.0 h1:1+0E0zfWFIWeyRhQYWzimJOyAk2UT7TiARaLNwJCf7k=
k8s.io/client-go v0.19.0/go.mod h1:H9E/VT95blcFQnlyShFgnFT9ZnJOAceiUHM3MlRC+mU=
k8s.io/client-go v0.19.3 h1:ctqR1nQ52NUs6LpI0w+a5U+xjYwflFwA13OJKcicMxg=
k8s.io/client-go v0.19.3/go.mod h1:+eEMktZM+MG0KO+PTkci8xnbCZHvj9TqR6Q1XDUIJOM=
k8s.io/client-go v0.19.4 h1:85D3mDNoLF+xqpyE9Dh/OtrJDyJrSRKkHmDXIbEzer8=
k8s.io/client-go v0.19.4/go.mod h1:ZrEy7+wj9PjH5VMBCuu/BDlvtUAku0oVFk4MmnW9mWA=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path"
"strings"

"github.com/ghodss/yaml"
"github.com/plumming/dx/pkg/util"
Expand All @@ -22,7 +23,7 @@ func ParseDefaultConfig(cf, hf string) (Config, error) {
// ~/.config/gh/hosts.yml lets try and load from
// there initially
config, err := parseHostsFile(hf)
if err != nil {
if err != nil && !strings.Contains(err.Error(), "no such file or directory") {
return nil, err
}
if config.HasHosts() {
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,23 @@ func TestParseDefaultConfigWithConfigFile(t *testing.T) {
token := config.GetToken("github.com")
assert.Equal(t, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", token)
}

func TestParseDefaultConfigWithNoHostsFile(t *testing.T) {
configFile, err := ioutil.TempFile(os.TempDir(), "TestParseDefaultConfigWithNoHostsFile2")
if err != nil {
panic(err)
}
defer os.Remove(configFile.Name())

err = ioutil.WriteFile(configFile.Name(), []byte(dummyConfigFile), 0600)
assert.NoError(t, err)

config, err := ParseDefaultConfig(configFile.Name(), "hosts-file-does-not-exist")
assert.NoError(t, err)

user := config.GetUser("github.com")
assert.Equal(t, "testuser", user)

token := config.GetToken("github.com")
assert.Equal(t, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", token)
}

0 comments on commit 8d1424a

Please sign in to comment.