Skip to content

Commit

Permalink
add some more url tests and add testGetYaml
Browse files Browse the repository at this point in the history
  • Loading branch information
proditis committed May 19, 2022
1 parent 7e75a3b commit 7f3e652
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package conf

import (
"io/ioutil"
"os"
"testing"
)

Expand All @@ -32,4 +34,36 @@ func TestPathAndURL(t *testing.T) {
testisExternalURL("//tmp", false, t)
testisExternalURL("file:https:///tmp", false, t)
testisExternalURL("http:https://", false, t)
testisExternalURL("https://", false, t)
testisExternalURL("hTtP:https://", false, t)
testisExternalURL("http", false, t)
testisExternalURL("https", false, t)
testisExternalURL("ftp", false, t)
testisExternalURL("hTtP:https://127.0.0.1", true, t)
testisExternalURL("localhost", false, t)
testisExternalURL("ftp:https://127.0.0.1", false, t)
}

func TestGetYamlFileFromFile(t *testing.T) {
//content := []byte("temporary file's content")

if _, err := getYamlFileFromFile("/tmp/nonexistent"); err == nil {
t.Errorf("getYamlFileFromFile(\"/tmp/nonexistent\") = nil, expected error")
}

tmpfile, err := ioutil.TempFile("", "invalid*.yaml")
if err != nil {
t.Errorf("TempFile(\"invalid*.yaml\") %v", err)
}

defer os.Remove(tmpfile.Name()) // clean up

// test empty file
data, err := getYamlFileFromFile(tmpfile.Name())
if err != nil {
t.Errorf("getYamlFileFromFile(\"%s\") = %v, expected nil", tmpfile.Name(), err)
}
if string(data) != "" {
t.Errorf("getYamlFileFromFile(\"%s\") got data %s, expected nil", tmpfile.Name(), data)
}
}

0 comments on commit 7f3e652

Please sign in to comment.