소스 검색

Update package to the same value, added error tests for the prom package

Matt Bolt 5 년 전
부모
커밋
bd4e8a2d03
4개의 변경된 파일88개의 추가작업 그리고 3개의 파일을 삭제
  1. 85 0
      pkg/prom/error_test.go
  2. 1 1
      test/cluster_test.go
  3. 1 1
      test/keytuple_test.go
  4. 1 1
      test/remote_cluster_test.go

+ 85 - 0
pkg/prom/error_test.go

@@ -0,0 +1,85 @@
+package prom
+
+import (
+	"errors"
+	"fmt"
+	"testing"
+)
+
+func newCommError() error {
+	return NewCommError("Test Communication Error")
+}
+
+func newErrorCollection() error {
+	qc := &QueryErrorCollector{}
+
+	qc.Report("test_query1", nil, NewCommError("Failed to connect"), nil)
+	qc.Report("test_query2", nil, NewCommError("Failed to connect"), errors.New("Parsing error"))
+	qc.Report("test_query3", nil, nil, errors.New("Failed to parse field 'foo'"))
+
+	return qc
+}
+
+func newNestedError() error {
+	comErr := NewCommError("Communication Error")
+	e1 := fmt.Errorf("Wrap Error #1: %w", comErr)
+	e2 := fmt.Errorf("Wrap Error #2: %w", e1)
+	return e2
+}
+
+func TestErrorCollectionCheck(t *testing.T) {
+	err := newErrorCollection()
+
+	if !IsErrorCollection(err) {
+		t.Fatalf("IsErrorCollection() returned false, expected true")
+		return
+	}
+}
+
+func TestNestedErrorAs(t *testing.T) {
+	err := newNestedError()
+
+	var commErr CommError
+	if !errors.As(err, &commErr) {
+		t.Fatalf("Expected there to exist a CommError, but failed.")
+		return
+	}
+}
+
+func TestErrorCollectionErrorAs(t *testing.T) {
+	err := newErrorCollection()
+
+	var commErr CommError
+	if !errors.As(err, &commErr) {
+		t.Fatalf("Expected there to exist a CommError, but failed.")
+		return
+	}
+}
+
+func TestCommErrorAs(t *testing.T) {
+	err := newCommError()
+
+	var commErr CommError
+	if !errors.As(err, &commErr) {
+		t.Fatalf("Expected there to exist a CommError, but failed.")
+		return
+	}
+}
+
+func TestAllErrorsFor(t *testing.T) {
+	err := newErrorCollection()
+	if !IsErrorCollection(err) {
+		t.Fatalf("Error is not ErrorCollection")
+		return
+	}
+	collection := err.(QueryErrorCollection)
+	allErrors := AllErrorsFor(collection)
+
+	// Expected Errors Length
+	const expected = 4
+
+	if len(allErrors) != expected {
+		t.Fatalf("All Errors Length was: %d, Expected %d", len(allErrors), expected)
+		return
+	}
+}

+ 1 - 1
test/cluster_test.go

@@ -1,4 +1,4 @@
-package costmodel_test
+package test
 
 import (
 	"context"

+ 1 - 1
test/keytuple_test.go

@@ -1,4 +1,4 @@
-package costmodel_test
+package test
 
 import (
 	"strings"

+ 1 - 1
test/remote_cluster_test.go

@@ -1,4 +1,4 @@
-package costmodel_test
+package test
 
 import (
 	_ "k8s.io/client-go/plugin/pkg/client/auth"