From 7f3e6527b08a09b05842e5b3405c023ba3a90df7 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Thu, 19 May 2022 13:00:10 +0300 Subject: [PATCH] add some more url tests and add testGetYaml --- conf/conf_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/conf/conf_test.go b/conf/conf_test.go index 6759ac6c..0ee892cc 100644 --- a/conf/conf_test.go +++ b/conf/conf_test.go @@ -18,6 +18,8 @@ package conf import ( + "io/ioutil" + "os" "testing" ) @@ -32,4 +34,36 @@ func TestPathAndURL(t *testing.T) { testisExternalURL("//tmp", false, t) testisExternalURL("file:///tmp", false, t) testisExternalURL("http://", false, t) + testisExternalURL("https://", false, t) + testisExternalURL("hTtP://", false, t) + testisExternalURL("http", false, t) + testisExternalURL("https", false, t) + testisExternalURL("ftp", false, t) + testisExternalURL("hTtP://127.0.0.1", true, t) + testisExternalURL("localhost", false, t) + testisExternalURL("ftp://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) + } }