瀏覽代碼

Fix tests

Shelikhoo 5 年之前
父節點
當前提交
00103d1f73
共有 3 個文件被更改,包括 8 次插入5 次删除
  1. 3 2
      app/stats/command/command_test.go
  2. 2 1
      infra/conf/common_test.go
  3. 3 2
      testing/scenarios/command_test.go

+ 3 - 2
app/stats/command/command_test.go

@@ -54,7 +54,7 @@ func TestGetStats(t *testing.T) {
 			}
 		} else {
 			common.Must(err)
-			if r := cmp.Diff(resp.Stat, &Stat{Name: tc.name, Value: tc.value}); r != "" {
+			if r := cmp.Diff(resp.Stat, &Stat{Name: tc.name, Value: tc.value}, cmpopts.IgnoreUnexported(Stat{})); r != "" {
 				t.Error(r)
 			}
 		}
@@ -85,7 +85,8 @@ func TestQueryStats(t *testing.T) {
 	if r := cmp.Diff(resp.Stat, []*Stat{
 		{Name: "test_counter_2", Value: 2},
 		{Name: "test_counter_3", Value: 3},
-	}, cmpopts.SortSlices(func(s1, s2 *Stat) bool { return s1.Name < s2.Name })); r != "" {
+	}, cmpopts.SortSlices(func(s1, s2 *Stat) bool { return s1.Name < s2.Name }),
+		cmpopts.IgnoreUnexported(Stat{})); r != "" {
 		t.Error(r)
 	}
 }

+ 2 - 1
infra/conf/common_test.go

@@ -2,6 +2,7 @@ package conf_test
 
 import (
 	"encoding/json"
+	"github.com/google/go-cmp/cmp/cmpopts"
 	"os"
 	"testing"
 
@@ -216,7 +217,7 @@ func TestUserParsing(t *testing.T) {
 	if r := cmp.Diff(nUser, &protocol.User{
 		Level: 1,
 		Email: "love@v2ray.com",
-	}); r != "" {
+	}, cmpopts.IgnoreUnexported(protocol.User{})); r != "" {
 		t.Error(r)
 	}
 }

+ 3 - 2
testing/scenarios/command_test.go

@@ -3,6 +3,7 @@ package scenarios
 import (
 	"context"
 	"fmt"
+	"github.com/google/go-cmp/cmp/cmpopts"
 	"io"
 	"strings"
 	"testing"
@@ -471,7 +472,7 @@ func TestCommanderStats(t *testing.T) {
 	if r := cmp.Diff(sresp.Stat, &statscmd.Stat{
 		Name:  name,
 		Value: 10240 * 1024,
-	}); r != "" {
+	}, cmpopts.IgnoreUnexported(statscmd.Stat{})); r != "" {
 		t.Error(r)
 	}
 
@@ -482,7 +483,7 @@ func TestCommanderStats(t *testing.T) {
 	if r := cmp.Diff(sresp.Stat, &statscmd.Stat{
 		Name:  name,
 		Value: 0,
-	}); r != "" {
+	}, cmpopts.IgnoreUnexported(statscmd.Stat{})); r != "" {
 		t.Error(r)
 	}