diff --git a/cmd/clairctl/clair/clair_test.go b/cmd/clairctl/clair/clair_test.go deleted file mode 100644 index c3a4e617..00000000 --- a/cmd/clairctl/clair/clair_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package clair - -import ( - "encoding/json" - "io/ioutil" - "net/http" - "net/http/httptest" - "testing" - - "github.com/coreos/pkg/capnslog" -) - -func getSampleAnalysis() []byte { - file, err := ioutil.ReadFile("./samples/clair_report.json") - if err != nil { - log.Errorf("File error: %v\n", err) - } - - return file -} - -func newServer(httpStatus int) *httptest.Server { - return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(httpStatus) - })) -} - -func TestIsHealthy(t *testing.T) { - server := newServer(http.StatusOK) - defer server.Close() - healthURI = server.URL - if h := IsHealthy(); !h { - t.Errorf("IsHealthy() => %v, want %v", h, true) - } -} - -func TestIsNotHealthy(t *testing.T) { - server := newServer(http.StatusInternalServerError) - defer server.Close() - uri = server.URL - if h := IsHealthy(); h { - t.Errorf("IsHealthy() => %v, want %v", h, true) - } -} - -func TestRelativeCount(t *testing.T) { - var analysis ImageAnalysis - err := json.Unmarshal([]byte(getSampleAnalysis()), &analysis) - if err != nil { - t.Errorf("Failing with error: %v", err) - } - - vulnerabilitiesCount := allVulnerabilities(analysis) - if vulnerabilitiesCount.RelativeCount("High") != 1.3 { - t.Errorf("analysis.CountAllVulnerabilities().RelativeCount(\"High\") => %v, want 1.3", vulnerabilitiesCount.RelativeCount("High")) - } - - if vulnerabilitiesCount.RelativeCount("Medium") != 23.38 { - t.Errorf("analysis.CountAllVulnerabilities().RelativeCount(\"Medium\") => %v, want 23.38", vulnerabilitiesCount.RelativeCount("Medium")) - } - - if vulnerabilitiesCount.RelativeCount("Low") != 74.03 { - t.Errorf("analysis.CountAllVulnerabilities().RelativeCount(\"Low\") => %v, want 74.03", vulnerabilitiesCount.RelativeCount("Low")) - } -} diff --git a/cmd/clairctl/clair/push_test.go b/cmd/clairctl/clair/push_test.go deleted file mode 100644 index ab2bf914..00000000 --- a/cmd/clairctl/clair/push_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package clair - -import "testing" - -func TestInsertRegistryMapping(t *testing.T) { - layerID := "sha256:13be4a52fdee2f6c44948b99b5b65ec703b1ca76c1ab5d2d90ae9bf18347082e" - registryURI := "registry:5000" - insertRegistryMapping(layerID, registryURI) - - if r := registryMapping[layerID]; r != "http://registry:5000/v2" { - t.Errorf("insertRegistryMapping(%q,%q) => %q, want %q", layerID, registryURI, r, "http://registry:5000/v2") - } -} - -func TestGetRegistryMapping(t *testing.T) { - layerID := "sha256:13be4a52fdee2f6c44948b99b5b65ec703b1ca76c1ab5d2d90ae9bf18347082e" - registryURI := "registry:5000" - insertRegistryMapping(layerID, registryURI) - - if r, err := GetRegistryMapping(layerID); r != "http://registry:5000/v2" { - - if err != nil { - t.Errorf("GetRegistryMapping(%q) failed => %v", layerID, err) - } else { - t.Errorf("GetRegistryMapping(%q) => %q, want %q", layerID, registryURI, r) - } - } -} diff --git a/cmd/clairctl/clair/report_test.go b/cmd/clairctl/clair/report_test.go deleted file mode 100644 index 6e2db1c7..00000000 --- a/cmd/clairctl/clair/report_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package clair - -import ( - "encoding/json" - "io/ioutil" - "os" - "testing" - - "github.com/coreos/clair/database" -) - -func TestReportAsHtml(t *testing.T) { - var analysis ImageAnalysis - err := json.Unmarshal([]byte(getSampleAnalysis()), &analysis) - - if err != nil { - t.Errorf("Failing with error: %v", err) - } - - html, err := ReportAsHTML(analysis) - if err != nil { - log.Fatal(err) - } - - err = ioutil.WriteFile(os.TempDir()+"/clairctl-html-report.html", []byte(html), 0700) - if err != nil { - log.Fatal(err) - } -} - -func TestInvertedPriorities(t *testing.T) { - expected := []database.Severity{database.Defcon1Severity, database.CriticalSeverity, database.HighSeverity, database.MediumSeverity, database.LowSeverity, database.NegligibleSeverity, database.UnknownSeverity} - ip := invertedPriorities() - for i, v := range ip { - if v != expected[i] { - t.Errorf("Expecting %v, got %v", expected, ip) - } - } -} diff --git a/cmd/clairctl/config/config_test.go b/cmd/clairctl/config/config_test.go deleted file mode 100644 index 8fb02b8c..00000000 --- a/cmd/clairctl/config/config_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package config - -import ( - "fmt" - "os" - "testing" - - "github.com/coreos/clair/cmd/clairctl/test" - "github.com/spf13/viper" - - "gopkg.in/yaml.v2" -) - -const defaultValues = ` -clair: - uri: http://localhost - port: 6060 - healthport: 6061 - report: - path: reports - format: html -auth: - insecureskipverify: true -clairctl: - ip: "" - tempfolder: /tmp/clairctl - port: 0 -` - -const customValues = ` -clair: - uri: http://clair - port: 6061 - healthport: 6062 - report: - path: reports/test - format: json -auth: - insecureskipverify: false -clairctl: - ip: "localhost" - tempfolder: /tmp/clairctl/test - port: 64157 -` - -func TestInitDefault(t *testing.T) { - Init("", "INFO") - - cfg := values() - - var expected config - err := yaml.Unmarshal([]byte(defaultValues), &expected) - if err != nil { - t.Fatal(err) - } - - if cfg != expected { - t.Error("Default values are not correct") - } - viper.Reset() -} - -func TestInitCustomLocal(t *testing.T) { - tmpfile := test.CreateConfigFile(customValues, "clairctl.yml", ".") - defer os.Remove(tmpfile) // clean up - fmt.Println(tmpfile) - Init("", "INFO") - - cfg := values() - - var expected config - err := yaml.Unmarshal([]byte(customValues), &expected) - if err != nil { - t.Fatal(err) - } - - if cfg != expected { - t.Error("values are not correct") - } - viper.Reset() -} - -func TestInitCustomHome(t *testing.T) { - tmpfile := test.CreateConfigFile(customValues, "clairctl.yml", ClairctlHome()) - defer os.Remove(tmpfile) // clean up - fmt.Println(tmpfile) - Init("", "INFO") - - cfg := values() - - var expected config - err := yaml.Unmarshal([]byte(customValues), &expected) - if err != nil { - t.Fatal(err) - } - - if cfg != expected { - t.Error("values are not correct") - } - viper.Reset() -} - -func TestInitCustom(t *testing.T) { - tmpfile := test.CreateConfigFile(customValues, "clairctl.yml", "/tmp") - defer os.Remove(tmpfile) // clean up - fmt.Println(tmpfile) - Init(tmpfile, "INFO") - - cfg := values() - - var expected config - err := yaml.Unmarshal([]byte(customValues), &expected) - if err != nil { - t.Fatal(err) - } - - if cfg != expected { - t.Error("values are not correct") - } - viper.Reset() -}